コード例 #1
0
ファイル: arsdkgen.py プロジェクト: Music802/bebop_codes
def main():
    (options, args) = parseArgs()
    setupLog(options)
    generator_filepath = args[0]
    extra = ' '.join(args[1:]) if len(args) > 1 else None

    # Setup full path of output directories
    options.outdir = os.path.abspath(options.outdir)

    logging.info("arsdkgen: cmd=%s generator=%s, outdir=%s extra=%s",
                 "list" if options.listFiles else "generate",
                 generator_filepath, options.outdir, extra)
    if not options.listFiles and not os.path.exists(options.outdir):
        os.makedirs(options.outdir, 0755)

    # Import package of ge generation
    (generator_path, generator_filename) = os.path.split(generator_filepath)
    sys.path.append(generator_path)
    try:
        generator = __import__(os.path.splitext(generator_filename)[0])
    except ImportError:
        logging.error("Unable to import generator %s", generator_filepath)
        sys.exit(1)

    ctx = arsdkparser.ArParserCtx()
    path, filename = os.path.split(os.path.realpath(__file__))
    path = os.path.join(path, "xml")
    # first load generic.xml
    arsdkparser.parse_xml(ctx, os.path.join(path, "generic.xml"))
    for f in sorted(os.listdir(path)):
        if not f.endswith(".xml") or f == "generic.xml":
            continue
        arsdkparser.parse_xml(ctx, os.path.join(path, f))

    # Finalize features after parsing
    arsdkparser.finalize_ftrs(ctx)

    # Call generator
    if options.listFiles:
        generator.list_files(ctx, options.outdir, extra)
    else:
        # Generate in tmp folder.
        tmp_dir = tempfile.mkdtemp()
        generator.generate_files(ctx, tmp_dir, extra)
        # Copy in outdir all files different in tmp_dir and in outdir.
        for path, subdirs, files in os.walk(tmp_dir):
            for name in files:
                f_tmp = os.path.join(path, name)
                f_cp = f_tmp.replace(tmp_dir, options.outdir)
                if not os.path.isfile(f_cp) or \
                  filecmp.cmp(f_tmp, f_cp) == False:
                    if not os.path.exists(os.path.dirname(f_cp)):
                        os.makedirs(os.path.dirname(f_cp))
                    logging.info('Copy: ' + f_tmp + " => " + f_cp)
                    shutil.copy(f_tmp, f_cp)
        # Remove tmp_dir
        shutil.rmtree(tmp_dir)
コード例 #2
0
ファイル: Bybop_Commands.py プロジェクト: sumsted/hermes
MY_PATH, _ = os.path.split(os.path.realpath(__file__))
ARSDK_PATH = os.path.join(MY_PATH, '..', 'arsdk-xml')
ARCOMMANDS_PATH = os.path.join(ARSDK_PATH, 'xml')

sys.path.append(ARSDK_PATH)

import arsdkparser

_ctx = arsdkparser.ArParserCtx()
arsdkparser.parse_xml(_ctx, os.path.join(ARCOMMANDS_PATH, 'generic.xml'))
for f in sorted(os.listdir(ARCOMMANDS_PATH)):
    if not f.endswith('.xml') or f == 'generic.xml':
        continue
    arsdkparser.parse_xml(_ctx, os.path.join(ARCOMMANDS_PATH, f))
arsdkparser.finalize_ftrs(_ctx)


class CommandError(Exception):
    def __init__(self, msg):
        self.value = msg

    def __str__(self):
        return repr(self.value)


_struct_fmt_for_type = {
    'u8': 'B',
    'i8': 'b',
    'u16': 'H',
    'i16': 'h',