def command_plot(args): import matplotlib matplotlib.use('Agg') from grond.environment import Environment def setup(parser): pass details = '' parser, options, args = cl_parse('plot', args, setup, details) if len(args) not in (2, 3): help_and_die(parser, 'two or three arguments required') env = Environment(args[1:]) from grond import plot if args[0] == 'list': plot_names, plot_doc = zip(*[(pc.name, pc.__doc__) for pc in env.get_plot_classes()]) plot_descs = [doc.split('\n')[0].strip() for doc in plot_doc] left_spaces = max([len(pn) for pn in plot_names]) for name, desc in zip(plot_names, plot_descs): print('{name:<{ls}} - {desc}'.format(ls=left_spaces, name=name, desc=desc)) elif args[0] == 'config': plot_config_collection = plot.get_plot_config_collection(env) print(plot_config_collection) elif args[0] == 'all': plot_names = plot.get_plot_names(env) plot.make_plots(env, plot_names=plot_names) elif op.exists(args[0]): plots = plot.PlotConfigCollection.load(args[0]) plot.make_plots(env, plots) else: plot_names = [name.strip() for name in args[0].split(',')] plot.make_plots(env, plot_names=plot_names)
def command_plot(args): def setup(parser): parser.add_option( '--show', dest='show', action='store_true', help='show plot for interactive inspection') details = '' parser, options, args = cl_parse('plot', args, setup, details) if not options.show: import matplotlib matplotlib.use('Agg') from grond.environment import Environment if len(args) not in (1, 2, 3): help_and_die(parser, '1, 2 or 3 arguments required') if len(args) > 1: env = Environment(args[1:]) else: env = None from grond import plot if args[0] == 'list': def get_doc_title(doc): for ln in doc.split('\n'): ln = ln.strip() if ln != '': ln = ln.strip('.') return ln return 'Undocumented.' if env: plot_classes = env.get_plot_classes() else: plot_classes = plot.get_all_plot_classes() plot_names, plot_doc = zip(*[(pc.name, pc.__doc__) for pc in plot_classes]) plot_descs = [get_doc_title(doc) for doc in plot_doc] left_spaces = max([len(pn) for pn in plot_names]) for name, desc in zip(plot_names, plot_descs): print('{name:<{ls}} - {desc}'.format( ls=left_spaces, name=name, desc=desc)) elif args[0] == 'config': plot_config_collection = plot.get_plot_config_collection(env) print(plot_config_collection) elif args[0] == 'all': if env is None: help_and_die(parser, 'two or three arguments required') plot_names = plot.get_plot_names(env) plot.make_plots(env, plot_names=plot_names, show=options.show) elif op.exists(args[0]): if env is None: help_and_die(parser, 'two or three arguments required') plots = plot.PlotConfigCollection.load(args[0]) plot.make_plots(env, plots, show=options.show) else: if env is None: help_and_die(parser, 'two or three arguments required') plot_names = [name.strip() for name in args[0].split(',')] plot.make_plots(env, plot_names=plot_names, show=options.show)