pybootchartgui: Fix the filename and add a default format

* Fix teh output filename to make it easy to use
* Add a default output format (svg)
* Fix the usage message
* Fix the version to v1.0.0

Currently, the help messages are:

$ ./pybootchartgui.py --help
Usage: pybootchartgui.py [options] /path/to/tmp/buildstats/<recipe-machine>/<BUILDNAME>/

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -i, --interactive     start in active mode
  -f FORMAT, --format=FORMAT
                        image format: svg, pdf, png, [default: svg]
  -o PATH, --output=PATH
                        output path (file or directory) where charts are
                        stored
  -s NUM, --split=NUM   split the output chart into <NUM> charts, only works
                        with "-o PATH"
  -n, --no-prune        do not prune the process tree
  -q, --quiet           suppress informational messages
  --very-quiet          suppress all messages except errors
  --verbose             print all messages

[YOCTO #2403]

(From OE-Core rev: 138c2c31e41e3f1803b7efbedf78326d71821468)

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Robert Yang 2012-06-06 14:14:39 +08:00 committed by Richard Purdie
parent 0ad3f75432
commit 1b112fa9cf
1 changed files with 14 additions and 19 deletions

View File

@ -8,13 +8,13 @@ import batch
def _mk_options_parser(): def _mk_options_parser():
"""Make an options parser.""" """Make an options parser."""
usage = "%prog [options] PATH, ..., PATH" usage = "%prog [options] /path/to/tmp/buildstats/<recipe-machine>/<BUILDNAME>/"
version = "%prog v0.0.0" version = "%prog v1.0.0"
parser = optparse.OptionParser(usage, version=version) parser = optparse.OptionParser(usage, version=version)
parser.add_option("-i", "--interactive", action="store_true", dest="interactive", default=False, parser.add_option("-i", "--interactive", action="store_true", dest="interactive", default=False,
help="start in active mode") help="start in active mode")
parser.add_option("-f", "--format", dest="format", default = None, parser.add_option("-f", "--format", dest="format", default="svg", choices=["svg", "pdf", "png"],
help="image format (...); default format ...") help="image format: svg, pdf, png, [default: %default]")
parser.add_option("-o", "--output", dest="output", metavar="PATH", default=None, parser.add_option("-o", "--output", dest="output", metavar="PATH", default=None,
help="output path (file or directory) where charts are stored") help="output path (file or directory) where charts are stored")
parser.add_option("-s", "--split", dest="num", type=int, default=1, parser.add_option("-s", "--split", dest="num", type=int, default=1,
@ -29,20 +29,15 @@ def _mk_options_parser():
help="print all messages") help="print all messages")
return parser return parser
def _get_filename(paths, options): def _get_filename(path):
"""Construct a usable filename for outputs based on the paths and options given on the commandline.""" """Construct a usable filename for outputs"""
dir = "" dir = "."
file = "bootchart" file = "bootchart"
if options.output != None and not(os.path.isdir(options.output)): if os.path.isdir(path):
return options.output dir = path
if options.output != None: elif path != None:
dir = options.output file = path
if len(paths) == 1: return os.path.join(dir, file)
if os.path.isdir(paths[0]):
file = os.path.split(paths[0])[-1]
elif os.path.splitext(paths[0])[1] in [".tar", ".tgz", ".tar.gz"]:
file = os.path.splitext(paths[0])[0]
return os.path.join(dir, file + "." + options.format)
def main(argv=None): def main(argv=None):
try: try:
@ -57,10 +52,10 @@ def main(argv=None):
return 2 return 2
res = parsing.parse(args, options.prune) res = parsing.parse(args, options.prune)
if options.interactive or options.format == None: if options.interactive or options.output == None:
gui.show(res) gui.show(res)
else: else:
filename = _get_filename(args, options) filename = _get_filename(options.output)
res_list = parsing.split_res(res, options.num) res_list = parsing.split_res(res, options.num)
n = 1 n = 1
for r in res_list: for r in res_list: