-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcreate_release.py
169 lines (134 loc) · 4.41 KB
/
create_release.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env python
import os
import zipfile
def zipdir(path, zip):
for root, dirs, files in os.walk(path):
for file in files:
zip.write(os.path.join(root, file))
import xml.dom.minidom as dom
class XML:
def __init__(self, path=None, string=None):
if string:
self.root = dom.parseString(string)
elif path:
self.root = dom.parse(path)
else:
self.root = dom.Document()
def add_element(self, elementname, parent=None):
element = self.root.createElement(elementname)
if parent:
parent.appendChild(element)
else:
self.root.appendChild(element)
return element
def add_data(self, text, parent):
data = self.root.createTextNode(text)
parent.appendChild(data)
def get_xmlstring(self):
return self.root.toprettyxml("\t", "\n").replace('\t',' ')
def get_root(self):
return self.root
def get_children(self, parent=None):
if parent:
return parent.childNodes
else:
return self.root.childNodes
def get_data(self,node):
if node.nodeValue:
return node.nodeValue
else:
return node.nodeName
def is_root(self, node):
try:
node.tagName
return False
except:
return True
def is_data(self, node):
if node.nodeValue:
return True
else:
return False
def write_xml(self, path):
xml_file = open(path, 'wb')
xml_file.write(self.get_xmlstring().encode(encoding))
xml_file.close()
def write_xml_with_dom(self, path):
xml_file = open(path, 'wb')
self.root.writexml(xml_file)
xml_file.close()
def count_version_up(verion):
versionint = int(version.replace('.',''))
versionint += 1
newversionstr = str(versionint)
if len(newversionstr) == 1:
return '0.0.%s'%newversionstr
if len(newversionstr) == 2:
return '0.%s.%s'%(newversionstr[0],newversionstr[1])
if len(newversionstr) == 3:
return '%s.%s.%s'%(newversionstr[0],newversionstr[1],newversionstr[2])
if __name__ == '__main__':
itemlist = os.listdir('./')
pluginlist = []
for item in itemlist:
if os.path.isdir(item):
if item.startswith('plugin.'):
pluginlist.append(item)
if item.startswith('skin.'):
pluginlist.append(item)
if item.startswith('script.'):
pluginlist.append(item)
if item.startswith('service.'):
pluginlist.append(item)
if item.startswith('repository.'):
pluginlist.append(item)
if item.startswith('metadata.'):
pluginlist.append(item)
pluginlist.sort()
print 'Please Choose Plugin to release\n'
counter = 0
pluginlib = {}
for plugin in pluginlist:
counter += 1
print "%s: %s"%(counter, plugin)
pluginlib[str(counter)] = plugin
num = raw_input("\nEnter Number: ")
if not num in pluginlib:
print '\nWrong entry: %s'%num
exit(0)
print 'Release: %s\n'%pluginlib[num]
plugin = pluginlib[num]
sourcefolder = './%s'%plugin
try:
os.makedirs(sourcefolder)
except:
pass
addon_xml_file = os.path.join(sourcefolder,'addon.xml')
print 'Updating: %s'%addon_xml_file
xml = XML(path=addon_xml_file)
node = xml.get_children()[0]
assert xml.get_data(node) == 'addon',xml.get_data(node)
version = node.getAttribute('version')
newversion = count_version_up(version)
print version,'-->',newversion
node.setAttribute('version',newversion)
xml.write_xml_with_dom(addon_xml_file)
list_xml_file = 'addons.xml'
print 'Updating: %s'%list_xml_file
xml = XML(path=list_xml_file)
node = xml.get_children()[0]
addon_list = xml.get_children(node)
for addon in addon_list:
if not isinstance(addon, dom.Text):
if addon.getAttribute('id') == plugin:
addon.setAttribute('version',newversion)
xml.write_xml_with_dom(list_xml_file)
try:
os.makedirs('./releases/%s'%plugin)
except:
pass
zippath = './releases/%s/%s-%s.zip'%(plugin,plugin,newversion)
print 'Creating: %s'%zippath
zipf = zipfile.ZipFile(zippath, 'w')
zipdir(sourcefolder, zipf)
zipf.close()