summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Cakebread <pythonhead@gentoo.org>2010-03-22 20:43:36 +0100
committerSebastian Pipping <sebastian@pipping.org>2010-03-22 20:51:52 +0100
commit9a8b04a0438f14c67d4b92bfc5870c0748626d6d (patch)
tree05a509782688bca37d70bc7a23ea5572afb4d0fd
parentUpdate with content from metagen-0.3.tar.bz2 (diff)
downloadmetagen-9a8b04a0438f14c67d4b92bfc5870c0748626d6d.tar.gz
metagen-9a8b04a0438f14c67d4b92bfc5870c0748626d6d.tar.bz2
metagen-9a8b04a0438f14c67d4b92bfc5870c0748626d6d.zip
Update with content from metagen-0.4.tbz2v0.4
-rw-r--r--__init__.py0
-rw-r--r--docs/ChangeLog6
-rw-r--r--docs/README118
-rw-r--r--meta_unittest.py52
-rw-r--r--metadata.xml9
-rwxr-xr-xmetagen159
-rwxr-xr-xmetagen.py185
-rw-r--r--metagenerator.py63
-rwxr-xr-xtest_cli28
9 files changed, 461 insertions, 159 deletions
diff --git a/__init__.py b/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/__init__.py
diff --git a/docs/ChangeLog b/docs/ChangeLog
new file mode 100644
index 0000000..87e02b2
--- /dev/null
+++ b/docs/ChangeLog
@@ -0,0 +1,6 @@
+* metagen-0.4 (04 Jan 2005)
+
+ 04 Jan 04 2005; Rob Cakebread <pythonhead@gentoo.org>:
+ Major refactoring. Created separate class metagenerator.py
+ Created rudimentary testing framework.
+
diff --git a/docs/README b/docs/README
new file mode 100644
index 0000000..76d75e3
--- /dev/null
+++ b/docs/README
@@ -0,0 +1,118 @@
+
+metagen is copyright 2004,2005 Rob Cakebread, released under
+the terms of the GNU Public License v2
+
+
+metagen is a command line tool that writes a Gentoo metadata.xml file
+in the current working directory.
+
+The metagen package also has a metagenerator class that can be used
+from Python to create metadata.xml files easily:
+
+ from metagenerator import MyMetadata
+
+ metadata = MyMetadata()
+ metadata.set_herd(["python"])
+ print metadata
+
+ metadata = MyMetadata()
+ metadata.set_herd(["gnome", "python"])
+ metadata.set_maintainer(["<pythonhead@gentoo.org>"],
+ ["Rob Cakebread"],
+ ["Maintainer description."]
+ )
+ print metadata
+
+ * All methods use lists of strings as arguments except
+ set_longdescription, which is a string
+
+ * See meta_unittest.py for more detailed examples
+
+ * There isn't much in the way of error checking in metagenerator.py
+ Most of the sanity checking is done in metagen.py
+
+
+
+Command line tool examples:
+
+metagen -H python
+
+ * One herd
+
+ <?xml version="1.0" encoding="UTF-8"?>
+ <!DOCTYPE pkgmetadata SYSTEMhttp://www.gentoo.org/dtd/metadata.dtd">
+ <pkgmetadata>
+ <herd>python</herd>
+ </pkgmetadata>
+
+metagen -m
+
+ * This takes the maintainer info from your ECHANGELOG_USER variable
+ and assigns "no-herd" as the herd.
+
+ <?xml version="1.0" encoding="UTF-8"?>
+ <!DOCTYPE pkgmetadata SYSTEMhttp://www.gentoo.org/dtd/metadata.dtd">
+ <pkgmetadata>
+ <herd>no-herd</herd>
+ <maintainer>
+ <email>pythonhead@gentoo.org</email>
+ <name>Rob Cakebread</name>
+ </maintainer>
+ </pkgmetadata>
+
+
+metagen -m -d "I maintain this because I'm crazy."
+
+ * Maintainer with description of maintenance
+
+ <?xml version="1.0" encoding="UTF-8"?>
+ <!DOCTYPE pkgmetadata SYSTEMhttp://www.gentoo.org/dtd/metadata.dtd">
+ <pkgmetadata>
+ <herd>no-herd</herd>
+ <maintainer>
+ <email>pythonhead@gentoo.org</email>
+ <name>Rob Cakebread</name>
+ <description>I maintain this because I'm crazy.</description>
+ </maintainer>
+ </pkgmetadata>
+
+
+metagen -m -H python -l "This package does X, Y, and Z."
+
+ * Maintainer, herd, long description
+
+ <?xml version="1.0" encoding="UTF-8"?>
+ <!DOCTYPE pkgmetadata SYSTEMhttp://www.gentoo.org/dtd/metadata.dtd">
+ <pkgmetadata>
+ <herd>python</herd>
+ <maintainer>
+ <email>pythonhead@gentoo.org</email>
+ <name>Rob Cakebread</name>
+ </maintainer>
+ <longdescription>This package does X, Y, and Z.</longdescription>
+ </pkgmetadata>
+
+metagen -m -e "jdoe@gentoo.org","tsmith@gentoo.org" -n "Jane Doe","Tom Smith" -H python,gnome -l "This package does X, Y, and Z."
+
+ * Two herds, 3 maintainers, long description
+
+ <?xml version="1.0" encoding="UTF-8"?>
+ <!DOCTYPE pkgmetadata SYSTEMhttp://www.gentoo.org/dtd/metadata.dtd">
+ <pkgmetadata>
+ <herd>python</herd>
+ <herd>gnome</herd>
+ <maintainer>
+ <email>pythonhead@gentoo.org</email>
+ <name>Rob Cakebread</name>
+ </maintainer>
+ <maintainer>
+ <email>jdoe@gentoo.org</email>
+ <name>Jane Doe</name>
+ </maintainer>
+ <maintainer>
+ <email>tsmith@gentoo.org</email>
+ <name>Tom Smith</name>
+ </maintainer>
+ <longdescription>This package does X, Y, and Z.</longdescription>
+ </pkgmetadata>
+
diff --git a/meta_unittest.py b/meta_unittest.py
new file mode 100644
index 0000000..06208a6
--- /dev/null
+++ b/meta_unittest.py
@@ -0,0 +1,52 @@
+#!/usr/bin/python
+
+from metagenerator import MyMetadata
+
+
+def test1():
+ """1 herd specified"""
+ metadata = MyMetadata()
+ metadata.set_herd(("python"))
+ return metadata
+
+def test2():
+ """No herd specified, 1 maintainer"""
+ metadata = MyMetadata()
+ metadata.set_herd([""])
+ metadata.set_maintainer(["<pythonhead@gentoo.org>"],
+ ["Rob Cakebread"],
+ ["Maintainer description."]
+ )
+ return metadata
+
+def test3():
+ """1 herd, 1 maintainer"""
+ metadata = MyMetadata()
+ metadata.set_herd(["python"])
+ metadata.set_maintainer(["<pythonhead@gentoo.org>"],
+ ["Rob Cakebread"],
+ ["Maintainer description."]
+ )
+ return metadata
+
+def test4():
+ """2 herds, 1 maintainer"""
+ metadata = MyMetadata()
+ metadata.set_herd(["python", "gnome"])
+ metadata.set_maintainer(["pythonhead@gentoo.org"],
+ ["Rob Cakebread"],
+ ["Maintainer description."]
+ )
+ return metadata
+
+def test5():
+ """2 herds, 2 maintainers, longdesc"""
+ metadata = MyMetadata()
+ metadata.set_herd(["python", "gnome"])
+ metadata.set_maintainer(["goofy@gentoo.org", "pythonhead@gentoo.org"],
+ ["Goo Fi", "Rob Cakebread"],
+ ["Maintainer one.", "Maintainer two"]
+ )
+ metadata.set_longdescription("This packages does X Y and Z.")
+ return metadata
+
diff --git a/metadata.xml b/metadata.xml
new file mode 100644
index 0000000..178bf7a
--- /dev/null
+++ b/metadata.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEMhttp://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+ <herd>no-herd</herd>
+ <maintainer>
+ <email>pythonhead@gentoo.org</email>
+ <name>Rob Cakebread</name>
+ </maintainer>
+</pkgmetadata>
diff --git a/metagen b/metagen
deleted file mode 100755
index 97769ec..0000000
--- a/metagen
+++ /dev/null
@@ -1,159 +0,0 @@
-#!/usr/bin/python
-
-
-"""
-
-NAME - metagen
-
-SYNOPSIS - Adds metadata.xml to current directory
-
-AUTHOR - Rob Cakebread <pythonhead@gentoo.org>
-
-USE - metagen --help
-
-"""
-
-import string, sys, re, os
-from optparse import *
-from commands import getstatusoutput
-
-from output import *
-import jaxml
-
-
-def generate_xml(options):
- """Returns metadata.xml"""
- #TODO: Make a separate class so it can be used by external apps?
- 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 not options.herd:
- options.herd = "no-herd"
- for o in options.herd.split(","):
- doc.herd(o)
- i = 0
- if options.echangelog:
- if not os.environ.has_key("ECHANGELOG_USER"):
- print red("!!! Environmental variable ECHANGELOG_USER not set.")
- sys.exit(1)
- e = os.environ["ECHANGELOG_USER"]
- my_email = e[e.find("<") +1:e.find(">")]
- my_name = e[0:e.find("<")-1]
- if options.email:
- options.email = "%s,%s" % (my_email, options.email)
- else:
- options.email = my_email
- if options.name:
- options.name = "%s,%s" % (my_name, options.name)
- else:
- options.name = my_name
- if options.email:
- emails = options.email.split(",")
- for o in emails:
- doc._push("maintainer_level")
- doc.maintainer().email(o)
- if options.name:
- names = options.name.split(",")
- if len(names) > len(emails):
- print red("!!! Number of names is greater than number of emails")
- sys.exit(1)
- if i <= len(names) -1:
- doc.name(names[i])
- if options.desc:
- descs = options.desc.split(",")
- if len(descs) > len(emails):
- print red("!!! Number of descriptions is greater than number of emails")
- sys.exit(1)
- if i <= len(descs) -1:
- doc.description(descs[i])
- doc._pop("maintainer_level")
- i += 1
- if options.long:
- doc.longdescription(options.long)
-
- return "%s" % doc
-
-def ValidateXML(file):
- """Test for valid XML"""
- #TODO validate against DTD
- re_escape_quotes=re.compile('"')
- s=re_escape_quotes.sub('\\"', f)
- return getstatusoutput("echo \"%s\" | xmllint --valid - 2>&1 > /dev/null" % s)[0]
-
-
-if __name__ == '__main__':
- optParser = OptionParser()
- optParser.add_option( "-H", action="store", dest="herd", type="string",
- help="Name of herd. If not specified, 'no-herd' will be inserted. \
- This would require the -e option.")
-
- 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( "-m", action="store_true", dest="echangelog", default=False,
- help="Use name and email address from ECHANGELOG_USER environmental variable. \
- This is a shortcut for -e <email> -n <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.")
-
- optParser.add_option( "-o", action="store", dest="output", type="string",
- help="Specify location of output file.")
-
- optParser.add_option( "-f", action="store_true", dest="force", default=False,
- help="Force overwrite of existing metadata.")
-
- optParser.add_option( "-v", action="store_true", dest="verbose", default=True,
- help="Verbose. Output of file to stdout. (default)")
-
- optParser.add_option( "-q", action="store_false", dest="verbose",
- help="Squelch output of file to stdout.")
-
- optParser.add_option( "-Q", action="store_true", dest="no_write", default=False,
- help="Do not write file to disk.")
-
- (options, remainingArgs) = optParser.parse_args()
-
- if len(sys.argv) == 1:
- optParser.print_help()
- sys.exit(1)
-
- if options.desc or options.name:
- if not options.email:
- print red("!!! You haven't specified a maintainer's email address (-e)")
- print red("!!! Options -d and -n are only valid when used with -e")
- sys.exit(1)
-
- if not options.herd and not options.email:
- print red("!!! You must specify at least a herd (-H) or maintainer's email address (-e)\n")
- sys.exit(1)
-
- f = generate_xml(options)
-
- if ValidateXML(f):
- print red("!!! Error - Invalid XML")
- print red("!!! Please report this bug with the options you used and the output:")
- print f
- sys.exit(1)
-
- if options.verbose:
- print "\n%s" % f
-
- oloc = "./metadata.xml"
- if options.output:
- oloc = options.output
- if not options.no_write and os.path.exists(oloc):
- if not options.force:
- print red("!!! File %s exists." % oloc)
- print red("!!! Use -f to force overwrite.")
- sys.exit(1)
- if not options.no_write:
- open("%s" % oloc, "w").writelines(f)
-
diff --git a/metagen.py b/metagen.py
new file mode 100755
index 0000000..31fe91d
--- /dev/null
+++ b/metagen.py
@@ -0,0 +1,185 @@
+#!/usr/bin/python
+
+
+"""
+
+NAME - metagen
+
+SYNOPSIS - Adds metadata.xml to current directory
+
+AUTHOR - Rob Cakebread <pythonhead@gentoo.org>
+
+USE - metagen --help
+
+EXAMPLES - man metagen
+
+"""
+
+import sys
+import re
+import os
+from optparse import OptionParser
+from commands import getstatusoutput
+
+from output import red, blue
+
+import metagenerator
+
+
+def parse_echangelog_variable(name, email):
+ """Extract developer name and email from ECHANGELOG_USER variable"""
+ try:
+ e = os.environ["ECHANGELOG_USER"]
+ except KeyError:
+ print red("!!! Environmental variable ECHANGELOG_USER not set.")
+ print red("!!! Set ECHANGELOG_USER or use -e and -n")
+ sys.exit(1)
+ try:
+ my_email = e[e.find("<") +1:e.find(">")]
+ except:
+ print red("!!! ECHANGELOG_USER not set properly")
+ sys.exit(1)
+ try:
+ my_name = e[0:e.find("<")-1]
+ except:
+ print red("!!! ECHANGELOG_USER not set properly")
+ sys.exit(1)
+ if email:
+ email = "%s,%s" % (my_email, email)
+ else:
+ email = my_email
+ if name:
+ name = "%s,%s" % (my_name, name)
+ else:
+ name = my_name
+ return name, email
+
+def generate_xml(options):
+ """Returns metadata.xml text"""
+
+ metadata = metagenerator.MyMetadata()
+
+ if options.herd:
+ herds = options.herd.split(",")
+ else:
+ herds = ["no-herd"]
+ metadata.set_herd(herds)
+
+ if options.echangelog:
+ (options.name, options.email) = \
+ parse_echangelog_variable(options.name, options.email)
+
+ if options.email:
+ names, descs = [], []
+ if options.name:
+ names = options.name.split(",")
+ if options.desc:
+ descs = options.desc.split(",")
+ metadata.set_maintainer(options.email.split(","),
+ names,
+ descs
+ )
+
+ if options.long:
+ metadata.set_longdescription(options.long)
+
+ return "%s" % metadata
+
+def validate_xml(my_xml):
+ """Test for valid XML"""
+ #TODO validate against DTD
+ #This just makes sure its valid XML of some sort.
+ #Probably not necessary since repoma validates against DTD?
+ re_escape_quotes = re.compile('"')
+ s = re_escape_quotes.sub('\\"', my_xml)
+ cmd = "echo \"%s\" | xmllint --valid - 2>&1 > /dev/null" % s
+ return getstatusoutput(cmd)[0]
+
+
+if __name__ == '__main__':
+ optParser = OptionParser()
+ optParser.add_option("-H", action="store", dest="herd", type="string",
+ help="Name of herd. If not specified, " +
+ "'no-herd' will be inserted. " +
+ "This requires either the -e or -m option.")
+
+ 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("-m", action="store_true", dest="echangelog",
+ default=False,
+ help="Use name and email address from ECHANGELOG_USER "+
+ "environmental variable. "+
+ "This is a shortcut for -e <email> -n <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.")
+
+ optParser.add_option("-o", action="store", dest="output", type="string",
+ help="Specify location of output file.")
+
+ optParser.add_option("-f", action="store_true", dest="force", default=False,
+ help="Force overwrite of existing metadata.")
+
+ optParser.add_option("-v", action="store_true", dest="verbose", default=True,
+ help="Verbose. Output of file to stdout. (default)")
+
+ optParser.add_option("-q", action="store_false", dest="verbose",
+ help="Squelch output of file to stdout.")
+
+ optParser.add_option("-Q", action="store_true", dest="no_write",
+ default=False,
+ help="Do not write file to disk.")
+
+ (options, remainingArgs) = optParser.parse_args()
+
+ if len(sys.argv) == 1:
+ optParser.print_help()
+ sys.exit(1)
+
+ if options.desc or options.name:
+ if not options.email and not options.echangelog:
+ print red("!!! No maintainer's email address specified.")
+ print red("!!! Options -d and -n are only valid with -e or -m")
+ sys.exit(1)
+
+ if options.herd == "no-herd" and not options.email and not options.echangelog:
+ print red("!!! You must specify a maintainer if you have no-herd.")
+ sys.exit(1)
+
+ if not options.herd and not options.email and not options.echangelog:
+ print red("!!! You must specify at least a herd (-H) " +
+ "or maintainer's email address (-e)\n")
+ sys.exit(1)
+
+ txt = generate_xml(options)
+
+ error_status = validate_xml(txt)
+ if error_status < 0:
+ print red("!!! Error - Invalid XML")
+ print red("!!! Please report this bug with the options you used and the output:")
+ print error_status
+ print txt
+ sys.exit(1)
+
+ if options.verbose:
+ print "\n%s" % txt
+
+ out_file = "./metadata.xml"
+ if options.output:
+ out_file = options.output
+ if not options.no_write and os.path.exists(out_file):
+ if not options.force:
+ print red("!!! File %s exists." % out_file)
+ print red("!!! Use -f to force overwrite.")
+ sys.exit(1)
+ if not options.no_write:
+ open("%s" % out_file, "w").writelines(txt)
+ print blue("%s written") % out_file
+
diff --git a/metagenerator.py b/metagenerator.py
new file mode 100644
index 0000000..842388f
--- /dev/null
+++ b/metagenerator.py
@@ -0,0 +1,63 @@
+#!/usr/bin/python
+
+import sys
+
+import jaxml
+from output import red
+
+
+class MyMetadata(jaxml.XML_document):
+
+ """Create Gentoo Linux metadata.xml"""
+
+ def __init__(self):
+ jaxml.XML_document.__init__(self, "1.0", "UTF-8")
+ self._indentstring("\t")
+ self._text('<!DOCTYPE pkgmetadata SYSTEM' +
+ 'http://www.gentoo.org/dtd/metadata.dtd">')
+ self.pkgmetadata()
+
+ def set_herd(self, opt_herds=["no-herd"]):
+ """Set herd(s)"""
+ for my_herd in opt_herds:
+ self.herd(my_herd)
+
+ def set_maintainer(self, emails, names, descs):
+ """Set maintainer(s)'s email, name, desc"""
+ i = 0
+ for e in emails:
+ self._push("maintainer_level")
+ self.maintainer().email(e)
+ if names:
+ if len(names) > len(emails):
+ print red("!!! Nbr names > nbr emails")
+ sys.exit(1)
+ if i <= len(names) -1:
+ self.name(names[i])
+ if descs:
+ if len(descs) > len(emails):
+ print red("!!! Nbr descs > nbr emails")
+ sys.exit(1)
+ if i <= len(descs) -1:
+ self.description(descs[i])
+ self._pop("maintainer_level")
+ i += 1
+
+ def set_longdescription(self, longdesc):
+ """Set package's long description."""
+ self.longdescription(longdesc)
+
+if __name__ == "__main__":
+ import meta_unittest
+ fails = 0
+ for func in dir(meta_unittest):
+ if func[0:4] == "test":
+ try:
+ exec "print meta_unittest.%s.__name__ + ':'," % func
+ exec "print meta_unittest.%s.__doc__" % func
+ exec "print meta_unittest.%s()" % func
+ except:
+ fails += 1
+ print "Test %s failed:" % func
+ print sys.exc_type, sys.exc_value
+ print "%s tests failed." % fails
diff --git a/test_cli b/test_cli
new file mode 100755
index 0000000..8995050
--- /dev/null
+++ b/test_cli
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+#Should fail if ECHANGELOG_USER not set:
+echo 'metagen -m -Q'
+./metagen.py -m -Q
+
+echo 'metagen -e "someguy@gentoo.org" -d "Maint desc" -Q'
+./metagen.py -e "someguy@gentoo.org" -d "Maint desc" -Q
+
+echo 'metagen -e "someguy@gentoo.org" -n "Jon Doe" -d "Maint desc" -Q'
+./metagen.py -e "someguy@gentoo.org" -n "Jon Doe" -d "Maint desc" -Q
+
+#Should fail if ECHANGELOG_USER not set:
+echo 'metagen -m -H python -e "foo@bar.com" -d "Foo bar.","Chow fun" -Q'
+./metagen.py -m -H python -e "foo@bar.com" -d "Foo bar.","Chow fun" -Q
+
+#Should fail:
+echo 'metagen -H no-herd -Q'
+./metagen.py -H no-herd -Q
+
+#Should fail:
+echo 'metagen -l "Long desc" -Q'
+./metagen.py -l "Long desc" -Q
+
+#Should fail:
+echo 'metagen -d "Maintainer desc" -Q'
+./metagen.py -d "Maintainer desc" -Q
+