def main(argv): schemaPath = '' filesPath = '' try: opts, args = getopt.getopt(argv, "hs:d:", ["schema=","directory="]) except getopt.GetoptError: print('orm.py --schema <schemapath> --directory <dirpath>') sys.exit(2) if len(opts) == 0: print('orm.py --schema <schemapath> --directory <dirpath>') else: for opt, arg in opts: if opt == '-h': print ('orm.py --schema <schemapath> --directory <dirpath>') sys.exit() elif opt in ["--schema", "-s"]: schemaPath = arg elif opt in ["--directory", "-d"]: filesPath = arg currDir = os.path.dirname(__file__) classesFromPath = os.path.join(currDir, 'classes') classesToPath = os.path.join(filesPath , 'classes') distutils.dir_util.copy_tree(classesFromPath, classesToPath) entities, models = schema_parser.parse(schemaPath) generate_data_manager.create_data_manager(entities, filesPath) schema_parser.createDTOEntities(entities, os.path.join(filesPath , 'DTO')) schema_parser.createEntities(entities, os.path.join(filesPath , 'entities')) for model in models: generate_model.createModel(os.path.join(filesPath , 'models'), model)
def test_type_mapping(self): forest = schema_parser.parse('TypeMapping.h') trees = forest.get_trees() self.assertEqual(len(trees), 1) tree = trees[0] fields = tree.get_fields() self.assertEqual(len(fields), 14)
def test_cast_functions(self): forest = schema_parser.parse('CastFunctions.h') trees = forest.get_trees() self.assertEqual(len(trees), 1) tree = trees[0] fields = tree.get_fields() self.assertEqual(len(fields), 1) field = fields[0] self.assertEqual(field.args[0], "std::array<int8_t,10>")
def test_equality(self): forest = schema_parser.parse('Equality.h') trees = forest.get_trees() self.assertEqual(len(trees), 1) tree = trees[0] fields = tree.get_fields() self.assertEqual(len(fields), 3) for i, field in enumerate(fields): self.assertEqual(field.args[0], 'int') self.assertEqual(field.args[1], 'f%i' % (i + 1))
def test_multiple_assignment(self): forest = schema_parser.parse('MultipleAssignment.h') trees = forest.get_trees() self.assertEqual(len(trees), 1) tree = trees[0] fields = tree.get_fields() self.assertEqual(len(fields), 4) for i, field in enumerate(fields): self.assertEqual(field.args[0], 'int') self.assertEqual(field.args[1], 'f%i' % (i + 1))
def test_type_mapping(self): forest = schema_parser.parse('TypeMapping.h') trees = forest.get_trees() self.assertEqual(len(trees), 1) tree = trees[0] fields = tree.get_fields() self.assertEqual(len(fields), 14) schema_types = [generator.Type(f.args[0]) for f in fields] for st in schema_types: self.assertTrue(st.is_primitive()) self.assertTrue(st.is_numeric())
def write_swig(self, outdir): for path in self.paths: forest = schema_parser.parse(path) if forest and forest.get_trees(): forest.remove_directives() swig = forest.getValue() outpath = os.path.join(outdir, os.path.basename(path)) self.write_content(swig, outpath) else: with open(path, 'r') as f: header = f.read() header = re.sub(r'NO_SCHEMA\([A-Za-z]+\);', '', header) with open(os.path.join(outdir, os.path.basename(path)), 'w') as f: f.write(header)
def test_constructor_initializers(self): forest = schema_parser.parse('ConstructorInitializers.h') trees = forest.get_trees() self.assertEqual(len(trees), 1) tree = trees[0] fields = tree.get_fields() self.assertEqual(len(fields), 2) self.assertEqual(fields[0].args[0], 'int') self.assertEqual(fields[0].args[1], 'f1') self.assertEqual(fields[1].args[0], 'int') self.assertEqual(fields[1].args[1], 'f2')
def test_access_modifiers(self): forest = schema_parser.parse('AccessModifiers.h') trees = forest.get_trees() self.assertEqual(len(trees), 1) tree = trees[0] fields = tree.get_fields() self.assertEqual(len(fields), 2) self.assertEqual(fields[0].args[0], 'int') self.assertEqual(fields[0].args[1], 'f1') self.assertEqual(fields[1].args[0], 'int') self.assertEqual(fields[1].args[1], 'f2') self.assertEqual(fields[1].args[2], '3')
def test_externals(self): forest = schema_parser.parse('Externals.h') trees = forest.get_trees() self.assertEqual(len(trees), 1) tree = trees[0] fields = tree.get_fields() self.assertEqual(len(fields), 3) self.assertEqual(fields[0].args[0], 'float') self.assertEqual(fields[0].args[1], 'x') self.assertEqual(fields[1].args[0], 'float') self.assertEqual(fields[1].args[1], 'y') self.assertEqual(fields[2].args[0], 'float') self.assertEqual(fields[2].args[1], 't')
def _parse(self): found = False schema = None for path in self.paths: self.forest = schema_parser.parse(path) trees = self.forest.get_trees() if self.forest else None # If we're not just checking for validity then go to the next path if not trees: if self.verify: raise Exception("No valid schemas found in header: '%s'" % path) else: continue console("%i trees identified" % len(trees)) for t in trees: if t.is_external(): schema = ExternalSchema(t) else: schema = InternalSchema(t) self.schemas.append(schema) for f in t.get_fields(): f = Field(*f.args) schema.fields.append(f) for s in t.get_custom_serialization(): schema.write_field_values = s.args[0][1:-1] # Remove brackets to avoid scoping break for d in t.get_custom_deserialization(): schema.read_field_values = d.args[0] for d in t.get_pre_serialization(): schema.pre_serialization = d.args[0] for d in t.get_post_serialization(): schema.post_serialization = d.args[0] for d in t.get_pre_deserialization(): schema.pre_deserialization = d.args[0] for d in t.get_post_deserialization(): schema.post_deserialization = d.args[0] return True
def test_compound_containers(self): forest = schema_parser.parse('CompoundContainers.h') trees = forest.get_trees() self.assertEqual(len(trees), 1)