-
Notifications
You must be signed in to change notification settings - Fork 1
/
AddonXMLUpdater.py
58 lines (42 loc) · 2.18 KB
/
AddonXMLUpdater.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import sys
import xml.etree.ElementTree as ET
class AddonXMLUpdater():
def __init__(self):
self.filesystem = sys.modules["__main__"].filesystem
def UpdateAddonVersion(self, update, xml):
xml.attrib["version"] = update["plugin"]["new_" + update["branch"] + "_version"]
def ParseXMLStructure(self, content):
xml = ET.fromstring(content)
return xml
def OutputXMLAsString(self, xml):
content = ET.tostring(xml, encoding="UTF-8")
content = content.replace("<?xml version='1.0' encoding='UTF-8'?>", "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>")
return content
def UpdateVersionNumberAndDependencyInformationInAddonXml(self, update):
file = "../tmp/" + update["branch"] + "/" + update["plugin"]["name"] + "/Addon.xml"
if update["branch"] == "master":
file = file.replace("/Addon.xml","/plugin/Addon.xml")
print "updating addon manifest xml: " + file
content = self.filesystem.readFileFromDisk(file)
if len(content) == 0:
return
xml = self.ParseXMLStructure(content)
self.UpdateAddonVersion(update, xml)
self.UpdatePluginDependencyInformation(update, xml)
content = self.OutputXMLAsString(xml)
self.filesystem.saveFileToDisk(file, content)
def UpdateDependencyVersion(self, branch, imports, update):
for dependency in imports:
if (dependency.attrib["addon"].replace(".beta","") == update["name"]):
if (update.has_key("new_version")):
dependency.attrib["version"] = update["new_version"]
elif (update.has_key("new_" + branch + "_version")):
dependency.attrib["version"] = update["new_" + branch + "_version"]
def UpdatePluginDependencyInformation(self, plugin_update, xml):
plugin = plugin_update["plugin"]
branch = plugin_update["branch"]
imports = xml.findall("*/import")
for update in plugin["dependencies"]:
if not (update.has_key("new_version") or update.has_key("new_" + branch + "_version")):
continue
self.UpdateDependencyVersion(branch, imports, update)