def do_generate(args): # Make sure the requested configuration file exists for conf in args.config: if not conf.exists(): exit(msg="No such configuration file: %s" % conf, status=1) # Build but DON'T PROCESS the Config object # This is fast, and gives us enough information to check whether or not try: config = Configuration(configfile=args.config, stdin_data=args.stdin, prior=args.prior, force_glottolog_load=args.report) except wrap_errors as e: # PRAGMA: NO COVER exit(msg="Error encountered while parsing configuration file:", status=2, exception=True) # Make sure we can write to the appropriate output filename output_filename = pathlib.Path( args.output) if args.output else config.admin.path(".xml") if output_filename.exists() and not args.overwrite: exit( msg= "File %s already exists! Run beastling with the --overwrite option if you wish " "to overwrite it." % output_filename, status=4) # Now that we know we will be able to save the resulting XML, we can take # the time to process the config object try: config.process() except wrap_errors as e: # pragma: no cover exit(msg="Error encountered while parsing configuration file:", status=2, exception=True) # Build XML file try: xml = BeastXml(config) except wrap_errors as e: # pragma: no cover exit(msg="Error encountered while building BeastXML object:", status=3, exception=True) # Write XML file xml.write_file(output_filename) # Build and write report if args.report: report = BeastlingReport(config) report.write_file(output_filename.parent / config.admin.path(".md")) geojson = BeastlingGeoJSON(config) geojson.write_file(output_filename.parent / config.admin.path(".geojson")) # Build and write language list if args.language_list: write_language_list(config)
def do_generate(args): # Build config object for conf in args.config: if not os.path.exists(conf): errmsg("No such configuration file: %s\n" % conf) sys.exit(1) try: config = beastling.configuration.Configuration( configfile=args.config, stdin_data=args.stdin, prior=args.prior) config.process() except Exception as e: errmsg("Error encountered while parsing configuration file:\n") traceback.print_exc() sys.exit(2) # If verbose mode is on, print any messages which were generated while # processing the configuration if args.verbose: for msg in config.messages: errmsg(msg + "\n") # Build XML file try: xml = BeastXml(config) except Exception as e: errmsg("Error encountered while building BeastXML object:\n") traceback.print_exc() sys.exit(3) # Write XML file filename = args.output if args.output else config.basename+".xml" if os.path.exists(filename) and not args.overwrite: errmsg("File %s already exists! Run beastling with the --overwrite option if you wish to overwrite it.\n" % filename) sys.exit(4) xml.write_file(filename) # Build and write report if args.report: report = BeastlingReport(config) report.write_file(config.basename+".md") geojson = BeastlingGeoJSON(config) geojson.write_file(config.basename+".geojson")
def test_report(self): config = self._make_cfg('admin', 'basic', 'calibration') report = BeastlingReport(config) report.tostring()
def test_report(config_factory): config = config_factory('admin', 'basic', 'calibration') report = BeastlingReport(config) report.tostring()