From f46c5e0c785c8051436a78130045b262d657b14c Mon Sep 17 00:00:00 2001 From: rzaitov Date: Thu, 14 Nov 2013 17:24:26 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE=D0=B2=D1=8B=D0=B2=D0=B0=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B0=D0=BD=D0=B4=D1=83=20?= =?UTF-8?q?=D0=BF=D0=B0=D1=82=D1=87=D0=B8=D0=BD=D0=B3=D0=B0=20=D0=B0=D0=BD?= =?UTF-8?q?=D0=B4=D1=80=D0=BE=D0=B8=D0=B4=20=D0=BC=D0=B0=D0=BD=D0=B8=D1=84?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PatchManifestCommandBuilder.py | 24 +++++++++++++++++++ .../Tests/ManualTests/manifest_test.py | 8 +++++++ .../commands/PatchManifestCommand.py | 20 ++++++++++++++++ scripts/TouchinBuild/utils/ManifestPatcher.py | 16 +++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 scripts/TouchinBuild/CommandBuilders/PatchManifestCommandBuilder.py create mode 100644 scripts/TouchinBuild/Tests/ManualTests/manifest_test.py create mode 100644 scripts/TouchinBuild/commands/PatchManifestCommand.py create mode 100644 scripts/TouchinBuild/utils/ManifestPatcher.py 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