def perform(self, args): model_name, opts = self.parse_args(args) try: _schema = Schema('config/schema.yaml') _schema.fix_tables() except TypeError: print red('The schema is not defined.') sys.exit(-1) if not check_model(model_name): print red('\n{0} model does not exist at the project schema.\n' \ 'Use model -l or model --list to show a list of available models.'\ .format(model_name if len(model_name) else 'Noname')) sys.exit(0) print '\n' + bold('Generating {0} model...'.format(model_name)) gen = Generator(opts['verbose']) templates = gen.create_b(model_name, _schema.find_table(model_name)) if opts['dump']: print '\napplication/model/base/{0}Base.py'.format( templates['base'][0]) print templates['base'][1] if templates.get('rel') != None: for rel in templates['rel']: print '\n\napplication/model/relation/{0}.py'.format( rel[0]) print rel[1] else: gen.write_base_model(templates['base'][0], templates['base'][1]) if templates.get('rel') != None: for rel in templates['rel']: gen.write_relation(rel[0], rel[1]) print bold('Model created successfully.')
def perform(self, args): opts = self.parse_args(args) try: _schema = Schema('config/schema.yaml') _schema.fix_tables() except TypeError: print red('The schema is not defined.') sys.exit(-1) gen = Generator(opts['verbose']) for model_name in _schema.get_tables_list(): print '\n' + bold('Generating {0} model...'.format(model_name)) templates = gen.create_b(model_name, _schema.find_table(model_name)) if opts['dump']: print '\napplication/model/base/{0}Base.py'.format( templates['base'][0]) print templates['base'][1] if templates.get('rel') != None: for rel in templates['rel']: print '\n\napplication/model/relation/{0}.py'.format( rel[0]) print rel[1] else: gen.write_base_model(templates['base'][0], templates['base'][1]) if templates.get('rel') != None: for rel in templates['rel']: gen.write_relation(rel[0], rel[1]) print bold('Model {0} created successfully.'.format(model_name))
def __init__(self, verbose=False): self._verbose = verbose self._schema = Schema('config/schema.yaml') if self._verbose: print bold('Fixing null values on schema...') (success, msg) = self._schema.fix_tables() if not success: raise SchemaException(msg) if self._verbose: print green('Schema fixed!')
def model_list(): """Return a list of available models at current schema""" try: _schema = Schema('config/schema.yaml') for table in _schema.get_tables_list(): print brown(table) except TypeError: print red('Schema is not defined.')
def check_model(model_name): """Checks if a model given by model name exists at the current schema""" if not len(model_name): return False _schema = Schema('config/schema.yaml') if not model_name in _schema.get_tables_list(): return False return True
def __init__(self): super(Database, self).__init__() self._schema = Schema('config/schema.yaml') try: self._db = create_database(self._schema.get_properties()['uri']) self._initialized = True except: self._initialized = False raise DatabaseException("Database schema is not defined")