def main(): if not GUI_CPARSER: print "Wrong cparser imported:" exit() print "Starting generation..." parser = ArgumentParser() parser.add_argument("-d", "--dir", dest="directory", action="append", help="Source C-files to introspect", required=True) parser.add_argument("-o", "--outdir", dest="outdir", action="store", help="Output directory", required=True) parser.add_argument("-t", "--typedefs", dest="typedefs", action="store", help="Additional typedefs for parser") parser.add_argument("-X", "--xmldir", dest="xmldir", default = sys.path, action="append", help="Directory to search for parent classes's XMLs") parser.add_argument("-v", "--verbose", action="store_true", dest="verbose", default=False, help="Verbose output") args = parser.parse_args() verbose_print = None if args.verbose is True: verbose_print = verbose_true else: verbose_print = verbose_false directories = [] outdir = "" typedefs = "" xmldir = [] directories = abs_path_get(args.directory) outdir = abs_path_get([args.outdir])[0] if args.xmldir is not None: xmldir = abs_path_get(args.xmldir, False)# not abort if dir doesn't exist if args.typedefs != None: typedefs = abs_path_get([args.typedefs])[0] files = dir_files_get(directories) c_files = filter(isC, files) h_files = filter(isH, files) cp = Cparser(args.verbose) cp.outdir_set(outdir) #adding typedefs from extern file if typedefs: cp.typedefs_add(typedefs) #fetching data from c-file for f in c_files: # cp.c_file_data_get(f) cp.c_file_data_get2(f) #fetching data from h-file for f in h_files: cp.h_file_data_get(f) #remove records, which are not class, t.e. they don't have GET_FUNCTION key cl_data_tmp = dict(cp.cl_data) #deep copy of dictionary for k in cl_data_tmp: if const.GET_FUNCTION not in cp.cl_data[k]: print "Warning: no define for class: %s. Record will be excluded from tree"%k cp.cl_data.pop(k) del cl_data_tmp #mapping #defines, comments(@def) and op_ids together, to parse parameters for k in cp.cl_data: cp.parse_op_func_params(k) #cp.print_data() tup = cp.gui_parser_data_get() cp.typedef_file_create(tup) del cp
def main(): parser = ArgumentParser() parser.add_argument( "-d", "--dir", dest="directory", action="append", help="Source C-files to introspect", required=True ) parser.add_argument("-o", "--outdir", dest="outdir", action="store", help="Output directory", required=True) parser.add_argument("-t", "--typedefs", dest="typedefs", action="store", help="Additional typedefs for parser") parser.add_argument( "-X", "--xmldir", dest="xmldir", default=sys.path, action="append", help="Directory to search for parent classes's XMLs", ) parser.add_argument("-v", "--verbose", action="store_true", dest="verbose", default=False, help="Verbose output") args = parser.parse_args() verbose_print = None if args.verbose is True: verbose_print = verbose_true else: verbose_print = verbose_false directories = [] outdir = "" typedefs = "" xmldir = [] directories = abs_path_get(args.directory) outdir = abs_path_get([args.outdir])[0] if args.xmldir is not None: xmldir = abs_path_get(args.xmldir, False) # not abort if dir doesn't exist if args.typedefs != None: typedefs = abs_path_get([args.typedefs])[0] files = dir_files_get(directories) c_files = filter(isC, files) h_files = filter(isH, files) cp = Cparser(args.verbose) cp.outdir_set(outdir) # adding typedefs from extern file if typedefs: cp.typedefs_add(typedefs) # fetching data from c-file for f in c_files: # cp.c_file_data_get(f) cp.c_file_data_get2(f) # fetching data from h-file for f in h_files: cp.h_file_data_get(f) # remove records, which are not class, t.e. they don't have GET_FUNCTION key cl_data_tmp = dict(cp.cl_data) # deep copy of dictionary for k in cl_data_tmp: if const.GET_FUNCTION not in cp.cl_data[k]: print "Warning: no define for class: %s. Record will be excluded from tree" % k cp.cl_data.pop(k) del cl_data_tmp # mapping #defines, comments(@def) and op_ids together, to parse parameters for k in cp.cl_data: cp.parse_op_func_params(k) # creating list of all parents for classes which are in tree list_of_parents = [] for k in cp.cl_data: list_of_parents += cp.cl_data[k][const.PARENTS] list_of_parents = list(set(list_of_parents)) # checking, if we need to find any parent and filtering it's ids cl_data_tmp2 = dict(cp.cl_data) parents_to_find = filter(lambda ll: True if ll not in cl_data_tmp2 else False, list_of_parents) # if we have parents to find if len(parents_to_find) != 0: if len(xmldir) == 0: print "No XML directory was provided" verbose_print("xmldir: %s\n" % xmldir) xml_files = dir_files_get(xmldir) xml_files = filter(isXML, xml_files) if len(xml_files) == 0: print "ERROR: no include files found for %s classes... Aborting..." % ",".join(parents_to_find) exit(1) # parsing include XMLs xp = XMLparser() for f in xml_files: xp.parse(f) # saving data about parents we were looking for for n, o in xp.objects.items(): if o.macro in parents_to_find: cp.cl_incl[o.macro] = {const.MODULE: o.mod_name, const.C_NAME: o.c_name} i = parents_to_find.index(o.macro) parents_to_find.pop(i) del xp # if there are still parents, which we need to find - exit if len(parents_to_find) != 0: print "ERROR: XML files weren't found for %s classes... Aborting" % (",".join(parents_to_find)) exit(1) # building XMLs for k in cp.cl_data: cp.build_xml(k) del cp
def main(): parser = ArgumentParser() parser.add_argument( "-d", "--dir", dest="directory", action="append", help="Path to XML descriptions", required=True ) parser.add_argument("-o", "--outdir", dest="outdir", action="store", help="Output directory", required=True) parser.add_argument("-v", "--verbose", action="store_true", dest="verbose", default=False, help="Verbose output") parser.add_argument( "-X", "--xmldir", dest="xmldir", default=sys.path, action="append", help="Directory to search for parent classes's XMLs", ) parser.add_argument("--pkg", dest="pkg", default="eo", action="store", help='pkg-confing libraries. Default: "eo"') parser.add_argument("-m", "--module", dest="module", action="store", help="Name of module", required=True) parser.add_argument("-I", "--include", dest="include_paths", action="append", help="Pre-processor include path") parser.add_argument("-l", "--library", dest="libraries", action="append", help="Libraries of this unit") parser.add_argument( "-L", "--library-path", dest="library_paths", action="append", help="Directories to search for libraries" ) parser.add_argument("-D", "--define", dest="cpp_defines", action="append", help="Pre-processor define") args = parser.parse_args() verbose_print = verbose_true if args.verbose is True else verbose_false directories = [] outdir = "" sourcedir = "" incl_dirs = [] directories = abs_path_get(args.directory) outdir = abs_path_get([args.outdir])[0] if args.xmldir is not None: incl_dirs = abs_path_get(args.xmldir, False) xml_files = dir_files_get(directories, False) xml_files = filter(isXML, xml_files) xp = XMLparser() xp.module_parse(args.module, xml_files, incl_dirs) xp.js_code_generate(outdir) c_files = [] for n, o in xp.objects.items(): c_files.append(o.V.c_file.name) makefile_file_generate(args, c_files, outdir) del xp
def main(): parser = ArgumentParser() parser.add_argument( "-d", "--dir", dest="directory", action="append", help="Path to XML descriptions", required=True ) parser.add_argument("-o", "--outdir", dest="outdir", action="store", help="Output directory", required=True) parser.add_argument("-v", "--verbose", action="store_true", dest="verbose", default=False, help="Verbose output") parser.add_argument( "-X", "--xmldir", dest="xmldir", default=sys.path, action="append", help="Directory to search for parent classes's XMLs", ) parser.add_argument("--pkg", dest="pkg", default="eo", action="store", help='pkg-confing libraries. Default: "eo"') parser.add_argument("-m", "--module", dest="module", action="store", help="Name of module", required=True) parser.add_argument("-I", "--include", dest="include_paths", action="append", help="Pre-processor include path") parser.add_argument("-l", "--library", dest="libraries", action="append", help="Libraries of this unit") parser.add_argument( "-L", "--library-path", dest="library_paths", action="append", help="Directories to search for libraries" ) parser.add_argument("-D", "--define", dest="cpp_defines", action="append", help="Pre-processor define") args = parser.parse_args() verbose_print = verbose_true if args.verbose is True else verbose_false directories = [] outdir = "" sourcedir = "" incl_dirs = [] directories = abs_path_get(args.directory) outdir = abs_path_get([args.outdir])[0] if args.xmldir is not None: incl_dirs = abs_path_get(args.xmldir, False) xml_files = dir_files_get(directories, False) xml_files = filter(isXML, xml_files) xp = XMLparser() xp.module_parse(args.module, xml_files, incl_dirs) if args.module == "eobase": outdir_tmp = os.path.join(outdir, const.PREFIX) if not os.path.exists(outdir_tmp): os.mkdir(outdir_tmp) xp.py_code_generate(args.module, outdir_tmp) else: xp.py_code_generate(args.module, outdir) setup_file_generate(args, outdir) # Looking for "eodefault.pxd" module. Needed to include if args.module == "eobase": for d in incl_dirs: d_tmp = os.path.join(d, "eodefault.pxd") if os.path.exists(d_tmp): sourcedir = d break if sourcedir == "": print "ERROR: no include files were found... Aborting... (Use: -X(--xmldir=)XML_DIR)" exit(1) # copying eodefault module into source dir f_pyx = os.path.join(sourcedir, "eodefault.pyx") f_pxd = os.path.join(sourcedir, "eodefault.pxd") f_init = os.path.join(sourcedir, "__init__.py") try: # this file is needed only to build eodefault. outdir_tmp = os.path.join(outdir, const.PREFIX) shutil.copy(f_pyx, outdir_tmp) shutil.copy(f_pxd, outdir_tmp) shutil.copy(f_init, outdir_tmp) except IOError as ex: print "%s" % ex print "Aborting" exit(1) except shutil.Error as er: print "Warning: %s" % er del xp