Esempio n. 1
0
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)
Esempio n. 2
0
 def parse_xml(self):
     """!
     Parse arsdk-xml files into self.ctx: ArParserCtx
     """
     self.ctx = arsdkparser.ArParserCtx()
     # first load generic.xml
     arsdkparser.parse_xml(self.ctx, os.path.join(self.path, "generic.xml"))
     for f in sorted(os.listdir(self.path)):
         if not f.endswith(".xml") or f == "generic.xml":
             continue
         arsdkparser.parse_xml(self.ctx, os.path.join(self.path, f))
Esempio n. 3
0
 def parse_xml(self):
     """!
     Parse arsdk-xml files into self.ctx: ArParserCtx
     """
     self.ctx = arsdkparser.ArParserCtx()
     # first load generic.xml
     arsdkparser.parse_xml(self.ctx,
                           str(self.arsdk_xml_path / "generic.xml"))
     for f in self.arsdk_xml_path.glob("*.xml"):
         if f.name == "generic.xml":
             continue
         arsdkparser.parse_xml(self.ctx, str(f))
Esempio n. 4
0
 def __init__(self, root):
     if root == "olympe":
         # Default arsdk-xml location
         od_path = Path(od.__file__)
         if od_path.stem == "__init__":
             od_path = od_path.parent
         site_path = od_path.parent
         self.arsdk_xml_path = site_path / "arsdk" / "xml"
         self.ctx = None
         self.parse_xml()
     else:
         # TODO: we might want to support multiple version of arsdk-xml here
         self.ctx = arsdkparser.ArParserCtx()
Esempio n. 5
0
import os
import sys
import struct

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',