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
|
#!/usr/bin/python
import os
import os.path
def makeMaintainerXML(leads):
maintainer_template = """
<maintainer>
<user>%(user)s</user>
<name>%(name)s</name>
<email>%(email)s</email>
<role>lead</role>
</maintainer>
"""
return "<maintainers>" + \
"".join([maintainer_template % l for l in leads]) + \
"</maintainers>"
def makeLeadXML(leads):
lead_template = """
<lead>
<name>%(name)s</name>
<user>%(user)s</user>
<email>%(email)s</email>
<active>%(active)s</active>
</lead>
"""
return "".join([lead_template % l for l in leads])
INDENT_STRING = " "
def buildContentsXMLFordir(dir_or_file, roles, depth=0, dir_role=None,
all_files=False):
"""
Returns a list of strings, each of which is either a <file> XML
element for the given file or a <dir> element which contains other
<file> elements.
"""
try:
entries = os.listdir(dir_or_file)
dir_role_s = ''
if dir_role:
dir_role_s = ' role="%s"' % (dir_role)
lines = ['%s<dir name="%s"%s>' % (INDENT_STRING * depth,
os.path.basename(dir_or_file),
dir_role_s)]
for entry in entries:
lines += buildContentsXMLFordir(dir_or_file + os.sep + entry, roles,
depth + 1, dir_role, all_files)
lines.append('%s</dir>' % (INDENT_STRING * depth))
return lines
except OSError:
try:
extension = dir_or_file.split(".")[-1]
except:
if not all_files:
return []
if all_files and dir_role:
return ['%s<file name="%s" role="%s" />' %
(INDENT_STRING * depth, os.path.basename(dir_or_file), dir_role)]
elif extension in roles: # Ends in an extension we care about
return ['%s<file name="%s" role="%s" />' %
(INDENT_STRING * depth, os.path.basename(dir_or_file),
roles[extension])]
else:
return []
def buildContentsXML(roles, *dirs):
lines = []
for directory in dirs:
lines.append("\n".join(buildContentsXMLFordir(directory, roles, 1)))
return "\n".join(lines)
def buildDocsXML(*dirs):
lines = []
for directory in dirs:
lines.append("\n".join(buildContentsXMLFordir(directory, {}, 1, 'doc',
all_files=True)))
return "\n".join(lines)
if __name__ == "__main__":
def usage(progname):
print "Usage: %s <package version> <xml template file> <release notes file>" % (progname)
import sys
import time
try:
import xmlconfig
except:
print "Could not import XML configuration module xmlconfig"
sys.exit(1)
# Expect sys.argv[2] to be the name of the XML file template to
# use for processing.
try:
template_f = open(sys.argv[2], 'r')
except Exception, e:
usage(sys.argv[0])
print "Could not open template file:", str(e)
sys.exit(1)
# Expect sys.argv[1] to be the version number to include in the
# package.xml file.
try:
version = sys.argv[1]
except:
usage(sys.argv[0])
sys.exit(2)
# Expect sys.argv[3] to be the name of the release notes file.
try:
release_file = sys.argv[3]
release_file_h = open(release_file, 'r')
release_notes = release_file_h.read().strip()
release_file_h.close()
except Exception, e:
usage(sys.argv[0])
print str(e)
sys.exit(3)
data = xmlconfig.__dict__.copy()
contentsXml = buildContentsXML({'php': 'php'}, *xmlconfig.contents_dirs)
docsXml = buildDocsXML(*xmlconfig.docs_dirs)
contents = '<dir name="/">\n' + contentsXml + \
"\n" + docsXml + '\n </dir>'
contents_v1 = '<filelist><dir name="/" baseinstalldir="Auth">\n' + contentsXml + \
"\n" + docsXml + '\n </dir></filelist>'
data['contents'] = contents
data['contents_version_1'] = contents_v1
data['leads'] = makeLeadXML(xmlconfig.leads)
data['maintainers'] = makeMaintainerXML(xmlconfig.leads)
data['date'] = time.strftime("%Y-%m-%d")
data['version'] = version
data['uri'] = "%s%s-%s.tgz" % (data['package_base_uri'], data['package_name'],
version)
data['release_notes'] = release_notes
template_data = template_f.read()
print template_data % data
|