Use optparse to parse gtester-report commandline options

See bug #611778.
This commit is contained in:
Robert Collins 2010-06-15 01:37:14 -04:00 committed by Matthias Clasen
parent ddb9a2f264
commit 8de6d03c44

View File

@ -17,6 +17,7 @@
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
import optparse
import sys, re, xml.dom.minidom
pkginstall_configvars = {
#@PKGINSTALL_CONFIGVARS_IN24LINES@ # configvars are substituted upon script installation
@ -331,40 +332,31 @@ class ReportWriter (TreeProcess):
self.oprint ('</html>\n')
# main program handling
def parse_files_and_args ():
from sys import argv, stdin
files = []
arg_iter = sys.argv[1:].__iter__()
rest = len (sys.argv) - 1
for arg in arg_iter:
rest -= 1
if arg == '--help' or arg == '-h':
print_help ()
sys.exit (0)
elif arg == '--version' or arg == '-v':
print_help (False)
sys.exit (0)
else:
files = files + [ arg ]
return files
def parse_opts():
"""Parse program options.
:return: An options object and the program arguments.
"""
parser = optparse.OptionParser()
parser.version = pkginstall_configvars.get ('glib-version', '0.0-uninstalled')
parser.usage = "%prog [OPTIONS] <gtester-log.xml>"
parser.description = "Generate HTML reports from the XML log files generated by gtester."
parser.epilog = "gtester-report (GLib utils) version %s."% (parser.version,)
parser.add_option("-v", "--version", action="store_true", dest="version", default=False,
help="Show program version.")
options, files = parser.parse_args()
if options.version:
print parser.epilog
return None, None
if len(files) != 1:
parser.error("Must supply a log file to parse.")
return options, files
def print_help (with_help = True):
import os
print "gtester-report (GLib utils) version", pkginstall_configvars.get ('glib-version', '0.0-uninstalled')
if not with_help:
return
print "Usage: %s [OPTIONS] <gtester-log.xml>" % os.path.basename (sys.argv[0])
print "Generate HTML reports from the XML log files generated by gtester."
print "Options:"
print " --help, -h print this help message"
print " --version, -v print version info"
def main():
from sys import argv, stdin
files = parse_files_and_args()
if len (files) != 1:
print_help (True)
sys.exit (1)
options, files = parse_opts()
if options is None:
return 0
xd = xml.dom.minidom.parse (files[0])
rr = ReportReader()
rr.trampoline (xd)