Начал реализовывать комманду патчинга андроид манифеста
This commit is contained in:
parent
0c7be54d43
commit
f46c5e0c78
|
|
@ -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
|
||||
|
|
@ -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()
|
||||
|
|
@ -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)
|
||||
|
|
@ -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")
|
||||
Loading…
Reference in New Issue