default='${event_name}/${problem_name}') default=u'Grond Report', help='Title shown on report overview page.') default=u'This interactive document aggregates earthquake source ' u'inversion results from optimisations performed with Grond.', help='Description shown on report overview page.') help='Configurations for plots to be included in the report.') default=True, help='Set to `false` to prevent creation of compressed archive.')
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
try: basepath = config.get_basepath() dirname = op.dirname(path) or '.' config.change_basepath(dirname) guts.dump( config, filename=path, header='Grond report configuration file, version %s' % __version__)
config.change_basepath(basepath)
except OSError: raise GrondError( 'Cannot write Grond report configuration file: %s' % path)
else:
make_index=True, make_archive=True, nthreads=0):
report_config = ReportConfig() report_config.set_basepath('.')
op.join( fp(report_config.report_base_path), report_config.entries_sub_path), dict( event_name=event_name, problem_name=problem.name))
shutil.rmtree(entry_path)
filename=op.join(entry_path, 'config.yaml'), header=True)
'stats', [rundir_path], filename=op.join(entry_path, 'stats.yaml'))
'best', [rundir_path], filename=op.join(entry_path, 'event.solution.best.yaml'), type='event-yaml')
'mean', [rundir_path], filename=op.join(entry_path, 'event.solution.mean.yaml'), type='event-yaml')
'ensemble', [rundir_path], filename=op.join(entry_path, 'event.solution.ensemble.yaml'), type='event-yaml')
except (environment.NoRundirAvailable, ProblemInfoNotAvailable, ProblemDataNotAvailable):
pass
env, plots_path=op.join(entry_path, 'plots'), plot_config_collection=pcc)
except environment.NoRundirAvailable: run_info = None
path='.', problem_name=problem.name, grond_version=problem.grond_version, run_info=run_info)
except Exception as e: logger.warn( 'Failed to create report entry, removing incomplete subdirectory: ' '%s' % entry_path) raise e
if op.exists(entry_path): shutil.rmtree(entry_path)
report_index(report_config)
report_archive(report_config)
report_config = ReportConfig()
logger.warn('Skipping indexing of incomplete report entry: %s' % entry_path)
continue
entries, filename=op.join(report_base_path, 'report_list.yaml'))
ReportInfo( title=report_config.title, description=report_config.description, version_info=info.version_info(), have_archive=report_config.make_archive), filename=op.join(report_base_path, 'info.yaml'))
report_config = ReportConfig()
return
mode='w:gz') as tar:
if host == 'localhost': ip = '127.0.0.1' elif host == 'default': import socket ip = [ (s.connect(('4.4.4.4', 80)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1] elif host == '*': ip = '' else: ip = host
return ip
logger.error(fmt % args)
logger.debug(fmt % args)
self.send_header('Cache-Control', 'no-cache') SimpleHTTPRequestHandler.end_headers(self)
'.yaml': 'application/x-yaml', '.yml': 'application/x-yaml'})
addr=('127.0.0.1', 8383), report_config=None, fixed_port=False, open=False):
if report_config is None: report_config = ReportConfig()
path = report_config.expand_path(report_config.report_base_path) os.chdir(path)
host, port = addr if fixed_port: ports = [port] else: ports = range(port, port+20)
httpd = None for port in ports: try: httpd = HTTPServer((host, port), ReportHandler) break except OSError as e: logger.warn(str(e))
if httpd: logger.info( 'Starting report web service at http://%s:%d' % (host, port))
thread = threading.Thread(None, httpd.serve_forever) thread.start()
if open: import webbrowser if open: webbrowser.open('http://%s:%d' % (host, port))
def handler(signum, frame): global g_terminate g_terminate = True
signal.signal(signal.SIGINT, handler) signal.signal(signal.SIGTERM, handler)
while not g_terminate: time.sleep(0.1)
signal.signal(signal.SIGINT, signal.SIG_DFL) signal.signal(signal.SIGTERM, signal.SIG_DFL)
logger.info('Stopping report web service...')
httpd.shutdown() thread.join()
logger.info('... done')
else: logger.error('Failed to start web service.')
report report_index report_archive ReportConfig ReportIndexEntry ReportInfo serve_ip serve_report read_config write_config '''.split() |