diff --git a/scripts/TouchinBuild/CommandBuilders/PatchManifestCommandBuilder.py b/scripts/TouchinBuild/CommandBuilders/PatchManifestCommandBuilder.py new file mode 100644 index 0000000..97f0e79 --- /dev/null +++ b/scripts/TouchinBuild/CommandBuilders/PatchManifestCommandBuilder.py @@ -0,0 +1,24 @@ +from commands.PatchManifestCommand import PatchManifestCommand +from parsers.InsideParser.InsideSetParser import InsideSetParser + + +class PatchManifestCommandBuilder: + def __init__(self): + pass + + def isManifestCommand(self, line): + assert line is not None + + parser = InsideSetParser('xml') + isValid = parser.isValidLine(line) + + return isValid + + def getCommandFor(self, line): + assert line is not None + + parser = InsideSetParser('xml') + result = parser.parseLine(line) + + command = PatchManifestCommand(result[0], result[1], result[2]) + return command diff --git a/scripts/TouchinBuild/Tests/ManualTests/manifest_test.py b/scripts/TouchinBuild/Tests/ManualTests/manifest_test.py new file mode 100644 index 0000000..493a174 --- /dev/null +++ b/scripts/TouchinBuild/Tests/ManualTests/manifest_test.py @@ -0,0 +1,8 @@ +from CommandBuilders.PatchManifestCommandBuilder import PatchManifestCommandBuilder + +line = "inside 'BuildSample/DroidApp/Properties/AndroidManifest.xml' set android:versionCode to '777'" + +builder = PatchManifestCommandBuilder() + +command = builder.getCommandFor(line) +command.execute() diff --git a/scripts/TouchinBuild/commands/PatchManifestCommand.py b/scripts/TouchinBuild/commands/PatchManifestCommand.py new file mode 100644 index 0000000..5b1dbab --- /dev/null +++ b/scripts/TouchinBuild/commands/PatchManifestCommand.py @@ -0,0 +1,20 @@ +from commands.CommandBase import CommandBase +from utils.ManifestPatcher import ManifestPatcher + + +class PatchManifestCommand(CommandBase): + def __init__(self, pathToManifest, key, value): + CommandBase.__init__(self) + + assert pathToManifest is not None + assert key is not None + assert value is not None + + self.pathToManifest = pathToManifest + self.key = key + self.value = value + + def execute(self): + patcher = ManifestPatcher(self.pathToManifest) + + patcher.AddOrReplaceManifestAtr(self.key, self.value) diff --git a/scripts/TouchinBuild/utils/ManifestPatcher.py b/scripts/TouchinBuild/utils/ManifestPatcher.py new file mode 100644 index 0000000..83a052d --- /dev/null +++ b/scripts/TouchinBuild/utils/ManifestPatcher.py @@ -0,0 +1,16 @@ +import xml.etree.ElementTree as eT + + +class ManifestPatcher: + def __init__(self, manifestPath): + assert manifestPath is not None + + self.manifestPath = manifestPath + + def AddOrReplaceManifestAtr(self, atrName, atrValue): + tree = eT.parse(self.manifestPath) + manifestElement = tree.getroot().find('manifest') + + manifestElement.attrib[atrName] = atrValue + + tree.write(self.manifestPath, xml_declaration=True, encoding='UTF-8', method="xml") \ No newline at end of file