def load(cls, path): from grond.plot import get_all_plot_classes get_all_plot_classes() # make sure all plot classes are loaded collection = load(filename=path) if not isinstance(collection, PlotConfigCollection): raise GrondError( 'invalid plot collection configuration in file "%s"' % path) return collection
def read_config(path): get_all_plot_classes() # make sure all plot modules are imported try: config = guts.load(filename=path) except OSError: raise GrondError('Cannot read Grond report configuration file: %s' % path) if not isinstance(config, ReportConfig): raise GrondError('Invalid Grond report configuration in file "%s".' % path) config.set_basepath(op.dirname(path) or '.') return config
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)