Esempio n. 1
0
    def run(cls, args):
        cls._setup_logging(args)
        cls._check_args(args)

        with open(args.schema, 'r') as input_file:
            schema = input_file.read()
            try:
                engine = Engine(schema)
                logging.debug("Tree: %s" % engine.tree)
            except FlatdataSyntaxError as e:
                logging.fatal("Error reading schema: %s " % e)
                sys.exit(1)

        for gen in args.gen:
            try:
                logging.info("Generating %s..." % gen)
                output_content = engine.render(gen)
            except Engine.GeneratorNotDefined:
                logging.fatal(
                    "Generator %s not implemented. Available options: %s" %
                    (gen, ', '.join(Engine.available_generators())))
                sys.exit(1)

        dirname = os.path.dirname(os.path.abspath(args.output_file))
        if not os.path.exists(dirname):
            os.makedirs(dirname)
        with open(args.output_file, "w") as output:
            output.write(output_content)
            logging.info("Code for %s is written to %s" %
                         (gen, args.output_file))
Esempio n. 2
0
def _run(args):
    _setup_logging(args)
    _check_args(args)

    with open(args.schema, 'r') as input_file:
        schema = input_file.read()
        try:
            engine = Engine(schema)
            logging.debug("Tree: %s", engine.tree)
        except FlatdataSyntaxError as ex:
            logging.fatal("Error reading schema: %s ", ex)
            sys.exit(1)

    try:
        logging.info("Generating %s...", args.gen)
        output_content = engine.render(args.gen)
    except ValueError as ex:
        logging.fatal("%s", ex)
        sys.exit(1)

    dirname = os.path.dirname(os.path.abspath(args.output_file))
    if not os.path.exists(dirname):
        os.makedirs(dirname)
    with open(args.output_file, "w") as output:
        output.write(output_content)
        logging.info("Code for %s is written to %s", args.gen,
                     args.output_file)