Beispiel #1
0
    def get_apps(self, global_options, include_apps=None):
        from uliweb.core.SimpleFrame import get_apps

        return get_apps(global_options.apps_dir,
                        include_apps=include_apps,
                        settings_file=global_options.settings,
                        local_settings_file=global_options.local_settings)
Beispiel #2
0
    def execute(self, args, options, global_options):
        from uliweb.utils.common import check_apps_dir
        from uliweb.core.SimpleFrame import get_apps

        #add apps_dir to global_options and insert it to sys.path
        global_options.project = '.'
        global_options.apps_dir = apps_dir = os.path.normpath(os.path.join(global_options.project, 'apps'))
        if apps_dir not in sys.path:
            sys.path.insert(0, apps_dir)
        
        if self.check_apps_dirs:
            check_apps_dir(global_options.apps_dir)
        if self.check_apps and args: #then args should be apps
            all_apps = get_apps(global_options.apps_dir)
            apps = args
            args = []
            for p in apps:
                if p not in all_apps:
                    print 'Error: Appname %s is not a valid app' % p
                    sys.exit(1)
                else:
                    args.append(p)
        try:
            self.handle(options, global_options, *args)
        except CommandError, e:
            log.exception(e)
            sys.exit(1)
Beispiel #3
0
    def handle(self, options, global_options, *args):
        from uliweb.core.SimpleFrame import get_apps, get_app_dir, Dispatcher
        from uliweb import orm

        app = Dispatcher(project_dir=global_options.project, start=False)

        if not args:
            apps_list = get_apps(global_options.apps_dir, settings_file=global_options.settings, local_settings_file=global_options.local_settings)
        else:
            apps_list = args
        
        con = orm.get_connection()
        
        for p in apps_list:
            if not is_pyfile_exist(get_app_dir(p), 'dbinit'):
                continue
            m = '%s.dbinit' % p
            try:
                if global_options.verbose:
                    print "Processing %s..." % m
                con.begin()
                mod = __import__(m, {}, {}, [''])
                con.commit()
            except ImportError:
                con.rollback()
                log.exception("There are something wrong when importing module [%s]" % m)
Beispiel #4
0
    def get_apps(self, global_options, include_apps=None):
        from uliweb.core.SimpleFrame import get_apps

        return get_apps(
            global_options.apps_dir,
            include_apps=include_apps,
            settings_file=global_options.settings,
            local_settings_file=global_options.local_settings,
        )
Beispiel #5
0
def get_tables(apps_dir, apps=None, engine=None, import_models=False, tables=None,
    settings_file='settings.ini', local_settings_file='local_settings.ini'):
    from uliweb.core.SimpleFrame import get_apps, get_app_dir
    from uliweb import orm
    from StringIO import StringIO
    
    engine = orm.engine_manager[engine]
    e = engine.options['connection_string']
    engine_name = e[:e.find('://')+3]
    
    buf = StringIO()
    
    if import_models:
        apps = get_apps(apps_dir, settings_file=settings_file, local_settings_file=local_settings_file)
        if apps:
            apps_list = apps
        else:
            apps_list = apps[:]
        models = []
        for p in apps_list:
            if p not in apps:
                log.error('Error: Appname %s is not a valid app' % p)
                continue
            if not is_pyfile_exist(get_app_dir(p), 'models'):
                continue
            m = '%s.models' % p
            try:
                mod = __import__(m, {}, {}, [''])
                models.append(mod)
            except ImportError:
                log.exception("There are something wrong when importing module [%s]" % m)
        
    else:
        old_models = orm.__models__.keys()
        try:
            for tablename, m in orm.__models__.items():
                orm.get_model(tablename)
        except:
            print "Problems to models like:", list(set(old_models) ^ set(orm.__models__.keys()))
            raise
            
    if apps:
        t = {}
        for tablename, m in engine.metadata.tables.items():
            if hasattr(m, '__appname__') and m.__appname__ in apps:
                t[tablename] = engine.metadata.tables[tablename]
    elif tables:
        t = {}
        for tablename, m in engine.metadata.tables.items():
            if tablename in tables:
                t[tablename] = engine.metadata.tables[tablename]
    else:
        t = engine.metadata.tables
                
    return t
Beispiel #6
0
def get_tables(apps_dir, apps=None, engine=None, import_models=False, settings_file='settings.ini', local_settings_file='local_settings.ini'):
    from uliweb.core.SimpleFrame import get_apps, get_app_dir
    from uliweb import orm
    from sqlalchemy import create_engine
    from StringIO import StringIO
    
    if not engine:
        engine = get_engine(apps_dir)
    
    _engine = engine[:engine.find('://')+3]
    
    buf = StringIO()
    
    con = create_engine(_engine, strategy='mock', executor=lambda s, p='': buf.write(str(s) + p))
    db = orm.get_connection(con)
    
    if import_models:
        apps = get_apps(apps_dir, settings_file=settings_file, local_settings_file=local_settings_file)
        if apps:
            apps_list = apps
        else:
            apps_list = apps[:]
        models = []
        for p in apps_list:
            if p not in apps:
                log.error('Error: Appname %s is not a valid app' % p)
                continue
            if not is_pyfile_exist(get_app_dir(p), 'models'):
                continue
            m = '%s.models' % p
            try:
                mod = __import__(m, {}, {}, [''])
                models.append(mod)
            except ImportError:
                log.exception("There are something wrong when importing module [%s]" % m)
        
    else:
        old_models = orm.__models__.keys()
        try:
            for tablename, m in orm.__models__.items():
                orm.get_model(tablename)
        except:
            print "Problems to models like:", list(set(old_models) ^ set(orm.__models__.keys()))
            raise
            
    if apps:
        tables = {}
        for tablename, m in db.metadata.tables.iteritems():
            if hasattr(m, '__appname__') and m.__appname__ in apps:
                tables[tablename] = db.metadata.tables[tablename]
    else:
        tables = db.metadata.tables
                
    return tables
Beispiel #7
0
    def handle(self, options, global_options, *args):
        from uliweb.core.SimpleFrame import get_apps, Dispatcher
        from graph import generate_dot

        app = Dispatcher(project_dir=global_options.project, start=False)
        if args:
            apps = args
        else:
            apps = get_apps(global_options.apps_dir, settings_file=global_options.settings, local_settings_file=global_options.local_settings)
        
        engine = get_engine(global_options.apps_dir)
        
        tables = get_tables(global_options.apps_dir, None, engine=engine, settings_file=global_options.settings, local_settings_file=global_options.local_settings)
        print generate_dot(tables, apps)
Beispiel #8
0
def get_tables(apps_dir,
               apps=None,
               engine=None,
               import_models=False,
               tables=None,
               settings_file='settings.ini',
               local_settings_file='local_settings.ini'):
    from uliweb.core.SimpleFrame import get_apps, get_app_dir
    from uliweb import orm
    from StringIO import StringIO

    engine = orm.engine_manager[engine]
    e = engine.options['connection_string']
    engine_name = e[:e.find('://') + 3]

    buf = StringIO()

    if import_models:
        apps = get_apps(apps_dir,
                        settings_file=settings_file,
                        local_settings_file=local_settings_file)
        if apps:
            apps_list = apps
        else:
            apps_list = apps[:]
        models = []
        for p in apps_list:
            if p not in apps:
                log.error('Error: Appname %s is not a valid app' % p)
                continue
            if not is_pyfile_exist(get_app_dir(p), 'models'):
                continue
            m = '%s.models' % p
            try:
                mod = __import__(m, {}, {}, [''])
                models.append(mod)
            except ImportError:
                log.exception(
                    "There are something wrong when importing module [%s]" % m)

    else:
        old_models = orm.__models__.keys()
        try:
            for tablename, m in orm.__models__.items():
                orm.get_model(tablename)
        except:
            print "Problems to models like:", list(
                set(old_models) ^ set(orm.__models__.keys()))
            raise

    if apps:
        t = {}
        for tablename, m in engine.metadata.tables.items():
            if hasattr(m, '__appname__') and m.__appname__ in apps:
                t[tablename] = engine.metadata.tables[tablename]
    elif tables:
        t = {}
        for tablename, m in engine.metadata.tables.items():
            if tablename in tables:
                t[tablename] = engine.metadata.tables[tablename]
    else:
        t = engine.metadata.tables

    return t