def make_report(env_args, event_name, conf, update_without_plotting): from grond.environment import Environment from grond.report import report try: env = Environment(env_args) if event_name: env.set_current_event_name(event_name) report(env, conf, update_without_plotting=update_without_plotting, make_index=False, make_archive=False) return True except grond.GrondError as e: logger.error(str(e)) return False
def command_report(args): import matplotlib matplotlib.use('Agg') from grond.environment import Environment from grond.report import \ report, report_index, serve_ip, serve_report, read_config, \ write_config, ReportConfig def setup(parser): parser.add_option('--index-only', dest='index_only', action='store_true', help='create index only') parser.add_option('--serve', '-s', dest='serve', action='store_true', help='start http service') parser.add_option( '--serve-external', '-S', dest='serve_external', action='store_true', help='shortcut for --serve --host=default --fixed-port') parser.add_option( '--host', dest='host', default='localhost', help='<ip> to start the http server on. Special values for ' '<ip>: "*" binds to all available interfaces, "default" ' 'to default external interface, "localhost" to "127.0.0.1".') parser.add_option( '--port', dest='port', type=int, default=8383, help='set default http server port. Will count up if port is ' 'already in use unless --fixed-port is given.') parser.add_option('--fixed-port', dest='fixed_port', action='store_true', help='fail if port is already in use') parser.add_option('--open', '-o', dest='open', action='store_true', help='open report in browser') parser.add_option('--config', dest='config', help='report configuration file to use') parser.add_option( '--write-config', dest='write_config', metavar='FILE', help='write configuration (or default configuration) to FILE') parser.add_option( '--update-without-plotting', dest='update_without_plotting', action='store_true', help='quick-and-dirty update parameter files without plotting') parser, options, args = cl_parse('report', args, setup) s_conf = '' if options.config: try: conf = read_config(options.config) except grond.GrondError as e: die(str(e)) s_conf = ' --config="%s"' % options.config else: conf = ReportConfig() conf.set_basepath('.') if options.write_config: try: write_config(conf, options.write_config) sys.exit(0) except grond.GrondError as e: die(str(e)) if len(args) == 1 and op.exists(op.join(args[0], 'index.html')): conf.reports_base_path = conf.rel_path(args[0]) s_conf = ' %s' % args[0] args = [] reports_base_path = conf.expand_path(conf.reports_base_path) if options.index_only: report_index(conf) args = [] reports_generated = False if args and all(op.isdir(rundir) for rundir in args): rundirs = args all_failed = True for rundir in rundirs: try: env = Environment([rundir]) report(env, conf, update_without_plotting=options.update_without_plotting) all_failed = False reports_generated = True except grond.GrondError as e: logger.error(str(e)) if all_failed: die('no reports generated') elif args: try: env = Environment(args) for event_name in env.get_selected_event_names(): env.set_current_event_name(event_name) report(env, conf, update_without_plotting=options.update_without_plotting) reports_generated = True except grond.GrondError as e: die(str(e)) if options.serve or options.serve_external: if options.serve_external: host = 'default' else: host = options.host addr = serve_ip(host), options.port serve_report(addr, report_config=conf, fixed_port=options.fixed_port or options.serve_external, open=options.open) elif options.open: import webbrowser url = 'file://%s/index.html' % op.abspath(reports_base_path) webbrowser.open(url) else: if not reports_generated and not options.index_only: logger.info('nothing to do, see: grond report --help') if reports_generated and not (options.serve or options.serve_external): logger.info(CLIHints('report', config=s_conf))