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
|
#!/usr/bin/python
"""
NAME - metagen
SYNOPSIS - Adds metadata.xml to current directory
AUTHOR - Rob Cakebread <pythonhead@gentoo.org>
USE - metagen --help
NOTE - Any tags that can have multiples can be separated by a comma
EXAMPLES -
metagen -H python
(creates barebones metadata.xml with python as the herd)
metagen -H python,wxwidgets \
-l "This package does yada yada yada."
(Two herds and long description)
metagen -e pythonhead@gentoo.org \
-n "Joe Blow" \
-d "The voices in my head told me to maintain this package"
(No herd, maintainer email, maintainer name, description of maintainership)
"""
import jaxml
import sys
from optparse import *
import os
def cleanup_indent():
"""Strip tabs to match Gentoo's metadata.xml file"""
#TODO This may be doable with _push() and _pop()
lines = open("metadata.xml", "r").readlines()
newfile = []
for l in lines:
if l[0] == "\t":
l = l[1:]
newfile.append(l)
f = open("metadata.xml", "w")
f.writelines(newfile)
def generate_xml(options):
"""Write XML file"""
doc = jaxml.XML_document("1.0", "UTF-8")
doc._indentstring("\t")
doc._text('<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">')
doc.pkgmetadata()
if options.herd:
for o in options.herd.split(","):
doc.herd(o)
i = 0
if options.email:
for o in options.email.split(","):
doc._push("maintainer_level")
doc.maintainer().email(o)
if options.name:
names = options.name.split(",")
if i <= len(names)-1:
doc.name(names[i])
if options.desc:
descs = options.desc.split(",")
if i <= len(descs)-1:
doc.description(descs[i])
doc._pop("maintainer_level")
i += 1
if options.long:
doc.longdescription(options.long)
doc._output("metadata.xml")
cleanup_indent()
if __name__ == '__main__':
optParser = OptionParser()
optParser.add_option( "-H", action="store", dest="herd", type="string",
help="Name of herd")
optParser.add_option( "-e", action="store", dest="email", type="string",
help="Maintainer's email address")
optParser.add_option( "-n", action="store", dest="name", type="string",
help="Maintainer's name")
optParser.add_option( "-d", action="store", dest="desc", type="string",
help="Description of maintainership")
optParser.add_option( "-l", action="store", dest="long", type="string",
help="Long description of package.")
(options, remainingArgs) = optParser.parse_args()
if len(sys.argv) == 1:
print "usage: %s [options]\n" % os.path.basename(sys.argv[0])
print "For help:"
print "%s --help" % os.path.basename(sys.argv[0])
sys.exit(1)
if not options.herd and not options.email:
print "You must specify at least a herd (-H) or maintainer's email address (-e)"
sys.exit(1)
generate_xml(options)
|