in tools/plisttool/plisttool.py [0:0]
def run(self):
"""Performs the operations requested by the control struct.
Raises:
PlistToolError: For any bad input (unknown control structure entries,
missing required information, etc.) or for processing/validation
errors.
"""
target = self._control.get('target')
if not target:
raise PlistToolError('No target name in control.')
output = self._control.get('output')
if not output:
raise PlistToolError('No output file specified.')
def validate_keys(keys, expected, options_name=None):
"""Helper to validate the support keys in control structures."""
unknown_keys = set(keys) - expected
if unknown_keys:
if options_name:
raise PlistToolError(UNKNOWN_TASK_OPTIONS_KEYS_MSG % (
target, options_name, ', '.join(sorted(unknown_keys))))
else:
raise PlistToolError(UNKNOWN_CONTROL_KEYS_MSG % (
target, ', '.join(sorted(unknown_keys))))
# Check for unknown keys in the control structure.
validate_keys(list(self._control.keys()), _CONTROL_KEYS)
tasks = []
var_subs = self._control.get('variable_substitutions', {})
raw_subs = self._control.get('raw_substitutions', {})
unknown_var_msg_additions = {}
task_types = (
EntitlementsTask,
InfoPlistTask,
)
for task_type in task_types:
options_name = task_type.control_structure_options_name()
options = self._control.get(options_name)
if options is not None:
validate_keys(list(options.keys()), task_type.options_keys(),
options_name=options_name)
task = task_type(target, options)
var_subs.update(task.extra_variable_substitutions())
raw_subs.update(task.extra_raw_substitutions())
unknown_var_msg_additions.update(
task.unknown_variable_message_additions())
tasks.append(task)
subs_engine = SubstitutionEngine(target, var_subs, raw_subs)
out_plist = {}
for p in self._control.get('plists', []):
plist = PlistIO.get_dict(p, target)
self._merge_dictionaries(plist, out_plist, target, subs_engine)
forced_plists = self._control.get('forced_plists', [])
for p in forced_plists:
plist = PlistIO.get_dict(p, target)
self._merge_dictionaries(plist, out_plist, target, subs_engine,
override_collisions=True)
for t in tasks:
t.update_plist(out_plist, subs_engine)
SubstitutionEngine.validate_no_variable_references(
target, '', out_plist, msg_additions=unknown_var_msg_additions)
if tasks:
saved_copy = copy.deepcopy(out_plist)
for t in tasks:
t.validate_plist(out_plist)
# Sanity check it wasn't mutated during a validate.
assert saved_copy == out_plist
PlistIO.write(out_plist, output, binary=self._control.get('binary'))