diff options
author | Rob Cakebread <pythonhead@gentoo.org> | 2010-03-22 20:41:02 +0100 |
---|---|---|
committer | Sebastian Pipping <sebastian@pipping.org> | 2010-03-22 20:51:36 +0100 |
commit | 723f5b045cba07498970cd6185607502e2ae5e01 (patch) | |
tree | 63dcc27dc589820b2274e288661fdcc6a2d6f379 | |
parent | Add content from metagen-0.1.tar.bz2 (diff) | |
download | metagen-723f5b045cba07498970cd6185607502e2ae5e01.tar.gz metagen-723f5b045cba07498970cd6185607502e2ae5e01.tar.bz2 metagen-723f5b045cba07498970cd6185607502e2ae5e01.zip |
Update with content from metagen-0.3.tar.bz2v0.3
-rwxr-xr-x | metagen | 149 | ||||
-rw-r--r-- | metagen.1 | 64 |
2 files changed, 146 insertions, 67 deletions
@@ -1,84 +1,92 @@ #!/usr/bin/python + """ -NAME - metagen +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) +AUTHOR - Rob Cakebread <pythonhead@gentoo.org> - 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) +USE - metagen --help """ +import string, sys, re, os +from optparse import * +from commands import getstatusoutput +from output import * 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""" + """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 options.herd: - for o in options.herd.split(","): - doc.herd(o) + 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: - for o in options.email.split(","): + emails = options.email.split(",") + for o in emails: doc._push("maintainer_level") doc.maintainer().email(o) if options.name: names = options.name.split(",") - if i <= len(names)-1: + 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 i <= len(descs)-1: + 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) - doc._output("metadata.xml") - cleanup_indent() + + 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") + 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") @@ -86,23 +94,66 @@ if __name__ == '__main__': 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: - print "usage: %s [options]\n" % os.path.basename(sys.argv[0]) - print "For help:" - print "%s --help" % os.path.basename(sys.argv[0]) + 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 "You must specify at least a herd (-H) or maintainer's email address (-e)" + 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) - generate_xml(options) + 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) @@ -1,13 +1,18 @@ .\" Contact pythonhead@gentoo.org to correct errors or omissions. .TH man 1 "22 August 2004" "1.0" "metagen man page" .SH NAME -metagen \- generate metadata.xml for ebuilds +.B metagen +\- generate metadata.xml for ebuilds .SH SYNOPSIS -metagen [-H herd] [-e email] [-d desc] [-l long desc] ... +.B metagen +[options] .SH DESCRIPTION -metagen will create a valid metadata.xml file in the current directory. -At a miminumum you must speficy either a herd (-H) or a package -maintainer's email address (-e). +.B metagen +will create a valid metadata.xml file in the current directory. metadata.xml requires a herd tag (-H). If you only specify a package maintainer's email address (-e) "no-herd" will be inserted in the herd tag automatically. + +If you need multiple elements, such as two herds, use a comma to +separate them. See EXAMPLES. + .SH OPTIONS .\" metagen [OPTIONS] -H herd @@ -19,38 +24,61 @@ maintainer's email address (-e). -n maintainer-name Package maintainer's name (used with -e option) + -m + Uses ECHANGELOG_USER variable. Can be used instead of -e and -n + -d description Description of maintainership (used with -e option) -l long-description Long description of package. + -o output-file + Write to <output-file> instead of ./metadata.xml + + -f + Force overwrite of existing metadata + + -v + Write to stdout as well as disk (default) + + -q + Don't write to stdout + + -Q + Don't write file to disk + -h, --help show this help message and exit -.SH NOTES -If you need multiple elements, such as two herds, use a comma to -separate them. See EXAMPLES + .SH EXAMPLES .B metagen -H python -Creates barebones metadata.xml with python as the herd +Creates metadata.xml in current directory with python as the herd -.B metagen -H python,wxwidgets -l "This package does yada yada yada." +.B metagen -H python,wxwidgets \ + -l 'This package does a little of this and some o dat.' -Two herds and long description +Creates metadata in current directory with two herds and long description -.B metagen -e pythonhead@gentoo.org -n "Joe Blow" -d "The voices in my head told me to maintain this package" +.B metagen -e pythonhead@gentoo.org \ + -n 'Joe Blow' \ + -d 'The voices in my head told me to maintain this package' \ + -Q -No herd, maintainer email, maintainer name, description of maintainership +herd='no-herd', maintainer email, maintainer name, description of maintainership, to stdout only .B metagen -H net-p2p,python -e jo@gentoo.org,flo@gentoo.org \ - -n "Jo Blo","Flo Blo" \ - -d "I'm maintaining this because foo","I'm maintaining this because bar" \ - -l "This package is yadda yadda yadda, spam and eggs" + -n 'Jo Blo','Flo Blo' \ + -d 'I am maintaining this because foo','I am maintaining this because bar' \ + -l 'This package is yadda yadda yadda, spam and eggs' \ + -Q + +2 herds, 2 maintainers with names and maintainer descriptions for each maintainer, +only write to stdout -2 herds, 2 maintainers with names and maintainer descriptions for each maintainer .SH FILES .P @@ -60,7 +88,7 @@ No herd, maintainer email, maintainer name, description of maintainership No known bugs at this time. .SH AUTHOR .nf -Rob "pythonhead" Cakebread (pythonhead@gentoo.org) +Rob 'pythonhead' Cakebread (pythonhead@gentoo.org) .fi .SH HISTORY 2004 \- Initial revision |