BuildScript/scripts/commands/patch_infoplist_command.py

54 lines
1.4 KiB
Python

import commands.build_command as bcmd
import utils.PathConverter.path_converter as pc
import utils.infoplist.patcher as plist
class PatchInfoPlist(bcmd.BuildCommand):
def __init__(self, config):
bcmd.BuildCommand.__init__(self, config, 'plist-')
self._info_plist_rel_path = None
self._plist_dict = {}
self.ParseConfig()
def ParseConfig(self):
self.FetchInfoPlistPath()
self.FetchAllParams()
def FetchInfoPlistPath(self):
self._info_plist_rel_path = self._config['info_plist_rel_path']
def FetchAllParams(self):
all_conf_keys = self.FetchAllConfigKeys()
for k in all_conf_keys:
self.AddValueFor(k)
def FetchAllConfigKeys(self):
all_keys = []
for k in self._config.keys():
if k.startswith(PatchInfoPlist._command_prefix) and not k.endswith('rel_path'):
all_keys.append(k)
return all_keys
def AddValueFor(self, conf_key):
value_token = self._config[conf_key]
value = self.ParseValueFromToken(value_token)
k = self.ParsePlistKeyFrom(conf_key)
self._plist_dict[k] = value
def ParsePlistKeyFrom(self, config_key):
return config_key[PatchInfoPlist._cmd_prefix_len:]
def Execute(self):
sln_path = self._config['sln_path']
pConverter = pc.PathConverter(sln_path)
info_plist_abs_path = pConverter.Convert(self._info_plist_rel_path)
patcher = plist.Patcher(info_plist_abs_path)
patcher.AddOrReplace(self._plist_dict)