示例#1
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.
    
    """
    from uliweb.manage import make_simple_application
    from uliweb import orm, settings

    #    engine = engine_from_config(
    #                config.get_section(config.config_ini_section),
    #                prefix='sqlalchemy.',
    #                poolclass=pool.NullPool)

    name = config.get_main_option("engine_name")
    make_simple_application(project_dir='.')
    target_metadata = orm.get_metadata(name)
    connection = orm.get_connection(name).connect()
    #    connection = engine.connect()

    context.configure(
        connection=connection,
        target_metadata=target_metadata,
        compare_server_default=True,
        include_object=uliweb_include_object,
        #                compare_server_default=uliweb_compare_server_default,
    )

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
示例#2
0
 def handle(self, options, global_options, *args):
     from uliweb.utils.common import extract_dirs
     from uliweb.core.template import template_file
     from uliweb.manage import make_simple_application
     from uliweb import settings
     from sqlalchemy import create_engine, MetaData, Table
     from shutil import rmtree
     from uliweb.orm import get_connection, engine_manager
     
     alembic_path = os.path.join(global_options.project, 'alembic', options.engine).replace('\\', '/')
     #delete alembic path
     if os.path.exists(alembic_path):
         rmtree(alembic_path, True)
     extract_dirs('uliweb.contrib.orm', 'templates/alembic', alembic_path, 
         verbose=global_options.verbose, replace=True)
     make_simple_application(project_dir=global_options.project,
         settings_file=global_options.settings,
         local_settings_file=global_options.local_settings)
     ini_file = os.path.join(alembic_path, 'alembic.ini')
     text = template_file(ini_file, 
         {'connection':engine_manager[options.engine].options.connection_string, 
         'engine_name':options.engine,
         'script_location':alembic_path})
     
     with open(ini_file, 'w') as f:
         f.write(text)
         
     #drop old alembic_version table
     db = get_connection(options.engine)
     metadata = MetaData(db)
     if db.dialect.has_table(db.connect(), 'alembic_version'):
         version = Table('alembic_version', metadata, autoload=True) 
         version.drop()
示例#3
0
文件: env.py 项目: 08haozi/uliweb
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.
    
    """
    from uliweb.manage import make_simple_application
    from uliweb import orm, settings

#    engine = engine_from_config(
#                config.get_section(config.config_ini_section), 
#                prefix='sqlalchemy.', 
#                poolclass=pool.NullPool)

    name = config.get_main_option("engine_name")
    make_simple_application(project_dir='.')
    target_metadata = orm.get_metadata(name)
    connection = orm.get_connection(engine_name=name).connect()
#    connection = engine.connect()
    
    context.configure(
                connection=connection, 
                target_metadata=target_metadata,
                compare_server_default=True,
                include_object=uliweb_include_object,
#                compare_server_default=uliweb_compare_server_default,
                )

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
示例#4
0
 def handle(self, options, global_options, *args):
     from uliweb.utils.common import extract_dirs
     from uliweb.core.template import template_file
     from uliweb.manage import make_simple_application
     from uliweb import settings
     from sqlalchemy import create_engine, MetaData, Table
     from shutil import rmtree
     from uliweb.orm import get_connection, engine_manager
     
     alembic_path = os.path.join(global_options.project, 'alembic', options.engine).replace('\\', '/')
     #delete alembic path
     if os.path.exists(alembic_path):
         rmtree(alembic_path, True)
     extract_dirs('uliweb.contrib.orm', 'templates/alembic', alembic_path, 
         verbose=global_options.verbose, replace=True)
     make_simple_application(project_dir=global_options.project,
         settings_file=global_options.settings,
         local_settings_file=global_options.local_settings)
     ini_file = os.path.join(alembic_path, 'alembic.ini')
     text = template_file(ini_file, 
         {'connection':engine_manager[options.engine].options.connection_string, 
         'engine_name':options.engine,
         'script_location':alembic_path})
     
     with open(ini_file, 'w') as f:
         f.write(text)
         
     #drop old alembic_version table
     db = get_connection(engine_name=options.engine)
     metadata = MetaData(db)
     if db.dialect.has_table(db.connect(), 'alembic_version'):
         version = Table('alembic_version', metadata, autoload=True) 
         version.drop()
示例#5
0
    def get_application(self, global_options):
        from uliweb.manage import make_simple_application

        return make_simple_application(
            project_dir=global_options.project,
            settings_file=global_options.settings,
            local_settings_file=global_options.local_settings)
示例#6
0
文件: commands.py 项目: tangjn/uliweb
 def get_application(self, global_options):
     from uliweb.manage import make_simple_application
     
     return make_simple_application(project_dir=global_options.project, 
         settings_file=global_options.settings, 
         local_settings_file=global_options.local_settings
         )
示例#7
0
文件: commands.py 项目: 28sui/uliweb
 def handle(self, options, global_options, *args):
     from uliweb.manage import make_simple_application
     from uliweb import orm
     from getpass import getpass
     
     app = make_simple_application(apps_dir=global_options.apps_dir, 
         settings_file=global_options.settings, local_settings_file=global_options.local_settings)
     db = orm.get_connection()
     
     username = ''
     while not username:
         username = raw_input("Please enter the super user's name: ")
     email = ''
     while not email:
         email = raw_input("Please enter the email of [%s]: " % username)
         
     password = ''
     while not password:
         password = getpass("Please enter the password for [%s(%s)]: " % (username, email))
     repassword = ''
     while not repassword:
         repassword = getpass("Please enter the password again: ")
     
     if password != repassword:
         print "The password is not matched, can't create super user!"
         return
     
     orm.set_dispatch_send(False)
     
     User = orm.get_model('user', options.engine)
     user = User(username=username, email=email)
     user.set_password(password)
     user.is_superuser = True
     user.save()
示例#8
0
文件: test.py 项目: RiverLiu/uliweb
def get_app(project_path=".", settings_file="settings.ini", local_settings_file="local_settings.ini"):
    from uliweb.manage import make_simple_application

    app = make_simple_application(
        project_dir=project_path, settings_file=settings_file, local_settings_file=local_settings_file
    )
    return app
示例#9
0
def get_app(project_path='.',
            settings_file='settings.ini',
            local_settings_file='local_settings.ini'):
    from uliweb.manage import make_simple_application

    app = make_simple_application(project_dir=project_path,
                                  settings_file=settings_file,
                                  local_settings_file=local_settings_file)
    return app
示例#10
0
 def get_application(self, global_options, default_settings=None):
     from uliweb.manage import make_simple_application
     
     app = make_simple_application(project_dir=global_options.project,
         settings_file=global_options.settings, 
         local_settings_file=global_options.local_settings,
         default_settings=default_settings
                                    )
     from uliweb import application
     return application
示例#11
0
def setup():
    import os
    global _path
    _path = os.getcwd()
    locate_dir = os.path.dirname(__file__)
    os.chdir(os.path.abspath(locate_dir))
    os.chdir('test_project')

    from uliweb.manage import make_simple_application
    app = make_simple_application(apps_dir='./apps')         
示例#12
0
文件: commands.py 项目: 28sui/uliweb
    def get_application(self, global_options, default_settings=None):
        from uliweb.manage import make_simple_application

        app = make_simple_application(project_dir=global_options.project,
            settings_file=global_options.settings, 
            local_settings_file=global_options.local_settings,
            default_settings=default_settings
            )
        from uliweb import application
        return application
    def setup(self):
        import os
        self._path = os.getcwd()

        locate_dir = os.path.dirname(__file__)
        os.chdir(os.path.abspath(locate_dir))
        os.chdir('test_project')
        self.create_database()

        from uliweb.manage import make_simple_application
        app = make_simple_application(apps_dir='./apps')        
示例#14
0
def init():
    setup()
    manage.call('uliweb makeproject --yes TestProject')
    os.chdir('TestProject')
    path = os.getcwd()
    manage.call('uliweb makeapp Test')
    f = open('apps/Test/models.py', 'w')
    f.write('''
from uliweb.orm import *

class User(Model):
    username = Field(str)
    birth = Field(datetime.date)
    email =Field(str)
    
class Group(Model):
    name = Field(str)
    members = ManyToMany('user')
    manager = Reference('user')
    
class Blog(Model):
    sid = Field(str)
    subject = Field(str)
''')
    f.close()
    f = open('apps/settings.ini', 'w')
    f.write('''
[GLOBAL]
INSTALLED_APPS = [
'uliweb.contrib.redis_cli', 
'uliweb.contrib.orm', 
'uliweb.contrib.objcache', 
'Test'
]

[LOG]
level = 'info'

[LOG.Loggers]
uliweb.contrib.objcache = {'level':'info'}

[MODELS]
user = '******'
group = 'Test.models.Group'
blog = 'Test.models.Blog'

[OBJCACHE_TABLES]
user = '******', 'email'
group = 'name'
blog = {'key':'sid'}
''')
    f.close()
    manage.call('uliweb syncdb')
    app = manage.make_simple_application(project_dir=path)
    def setup(self):
        import os
        self._path = os.getcwd()

        locate_dir = os.path.dirname(__file__)
        os.chdir(os.path.abspath(locate_dir))
        os.chdir('test_project')
        self.create_database()

        from uliweb.manage import make_simple_application
        app = make_simple_application(apps_dir='./apps')
示例#16
0
def init():
    setup()
    manage.call('uliweb makeproject --yes TestProject')
    os.chdir('TestProject')
    path = os.getcwd()
    manage.call('uliweb makeapp Test')
    f = open('apps/Test/models.py', 'w')
    f.write('''
from uliweb.orm import *

class User(Model):
    username = Field(str)
    birth = Field(datetime.date)
    email =Field(str)
    
class Group(Model):
    name = Field(str)
    members = ManyToMany('user')
    manager = Reference('user')
    
class Blog(Model):
    sid = Field(str)
    subject = Field(str)
''')
    f.close()
    f = open('apps/settings.ini', 'w')
    f.write('''
[GLOBAL]
INSTALLED_APPS = [
'uliweb.contrib.redis_cli', 
'uliweb.contrib.orm', 
'uliweb.contrib.objcache', 
'Test'
]

[LOG]
level = 'info'

[LOG.Loggers]
uliweb.contrib.objcache = {'level':'info'}

[MODELS]
user = '******'
group = 'Test.models.Group'
blog = 'Test.models.Blog'

[OBJCACHE_TABLES]
user = '******', 'email'
group = 'name'
blog = {'key':'sid'}
''')
    f.close()
    manage.call('uliweb syncdb')
    app = manage.make_simple_application(project_dir=path)
def call(args, options, global_options):
    app = make_simple_application(apps_dir=global_options.apps_dir)

    Begin()
    try:
        process()
        Commit()
    except:
        Rollback()
        import traceback

        traceback.print_exc()
示例#18
0
文件: commands.py 项目: tangjn/uliweb
def get_engine(options, global_options):
    from uliweb.manage import make_simple_application
    settings = {'ORM/DEBUG_LOG':False, 'ORM/AUTO_CREATE':False, 'ORM/AUTO_DOTRANSACTION':False}
    app = make_simple_application(apps_dir=global_options.apps_dir, 
        settings_file=global_options.settings, 
        local_settings_file=global_options.local_settings,
        default_settings=settings)
    #because set_auto_set_model will be invoked in orm initicalization, so
    #below setting will be executed after Dispatcher started
    set_auto_set_model(True)
    engine_name = options.engine
    engine = get_connection(engine_name=engine_name)
    return engine
示例#19
0
def get_engine(options, global_options):
    from uliweb.manage import make_simple_application
    settings = {'ORM/DEBUG_LOG':False, 'ORM/AUTO_CREATE':False, 'ORM/AUTO_DOTRANSACTION':False}
    app = make_simple_application(apps_dir=global_options.apps_dir, 
        settings_file=global_options.settings, 
        local_settings_file=global_options.local_settings,
        default_settings=settings)
    #because set_auto_set_model will be invoked in orm initicalization, so
    #below setting will be executed after Dispatcher started
    set_auto_set_model(True)
    engine_name = options.engine
    engine = get_connection(engine_name=engine_name)
    return engine
    def setup(self):
        locate_dir = os.path.dirname(__file__)
        os.chdir(locate_dir)
        os.chdir('test_project')

        import shutil
        shutil.rmtree('database.db', ignore_errors=True)

        manage.call('uliweb syncdb')
        manage.call('uliweb syncspec')

        from uliweb.manage import make_simple_application
        app = make_simple_application(apps_dir='./apps')
示例#21
0
    def handle(self, options, global_options, *args):
        from alembic.config import Config
        from uliweb.orm import engine_manager
        from uliweb.manage import make_simple_application
        
        app = make_simple_application(apps_dir=global_options.apps_dir, 
            settings_file=global_options.settings, local_settings_file=global_options.local_settings)

        alembic_path = os.path.join(global_options.project, 'alembic', options.engine).replace('\\', '/')
        configfile = os.path.join(alembic_path, 'alembic.ini')
        alembic_cfg = Config(configfile)
        alembic_cfg.set_main_option("sqlalchemy.url", engine_manager[options.engine].options.connection_string)
        alembic_cfg.set_main_option("engine_name", options.engine)
        alembic_cfg.set_main_option("script_location", alembic_path)
        self.do(alembic_cfg, args, options, global_options)
    def setup(self):
        
        import os
        locate_dir = os.path.dirname(__file__)
        os.chdir(locate_dir)
        os.chdir('test_project')
        from uliweb.manage import make_simple_application
        app = make_simple_application(apps_dir='./apps')

        spec_dir = "test_project/apps/specapp/workflow_specs/"
        
        CoreWFManager.reset()
        storage = WFConfigStorage()
        config_file = join(dirname(__file__), spec_dir + "TestWorkflow.spec")
        storage.load_config_file(config_file)
        CoreWFManager.set_storage(storage)
    def setup(self):

        import os
        locate_dir = os.path.dirname(__file__)
        os.chdir(locate_dir)
        os.chdir('test_project')
        from uliweb.manage import make_simple_application
        app = make_simple_application(apps_dir='./apps')

        spec_dir = "test_project/apps/specapp/workflow_specs/"

        CoreWFManager.reset()
        storage = WFConfigStorage()
        config_file = join(dirname(__file__), spec_dir + "TestWorkflow.spec")
        storage.load_config_file(config_file)
        CoreWFManager.set_storage(storage)
示例#24
0
    def handle(self, options, global_options, *args):
        from alembic.config import Config
        from uliweb.orm import engine_manager
        from uliweb.manage import make_simple_application
        
        app = make_simple_application(apps_dir=global_options.apps_dir, 
            settings_file=global_options.settings, local_settings_file=global_options.local_settings)

        alembic_path = os.path.join(global_options.project, 'alembic', options.engine).replace('\\', '/')
        configfile = os.path.join(alembic_path, 'alembic.ini')
        alembic_cfg = Config(configfile)
        alembic_cfg.set_main_option("sqlalchemy.url", engine_manager[options.engine].options.connection_string)
        alembic_cfg.set_main_option("engine_name", options.engine)
        alembic_cfg.set_main_option("script_location", alembic_path)
        alembic_cfg.set_main_option("remove_tables", '1' if options.remove else '0')
        self.do(alembic_cfg, args, options, global_options)
    def setup(self):
        
        locate_dir = os.path.dirname(__file__)
        os.chdir(locate_dir)
        os.chdir('test_project')
        self.reset_database()
        manage.call('uliweb syncspec')
        self.path = os.getcwd()

        from uliweb.manage import make_simple_application
        app = make_simple_application(apps_dir='./apps')
        
        print app
        from uliweb import settings
        print settings.SPECS
        from redbreast.core.spec import WFDatabaseStorage
        
        CoreWFManager.reset()
示例#26
0
    def setup(self):

        locate_dir = os.path.dirname(__file__)
        os.chdir(locate_dir)
        os.chdir('test_project')
        self.reset_database()
        manage.call('uliweb syncspec')
        self.path = os.getcwd()

        from uliweb.manage import make_simple_application
        app = make_simple_application(apps_dir='./apps')

        print app
        from uliweb import settings
        print settings.SPECS
        from redbreast.core.spec import WFDatabaseStorage

        CoreWFManager.reset()
示例#27
0
def make_shell_env(**kwargs):
    import os
    import sys
    from uliweb import functions, settings
    from uliweb.core.SimpleFrame import Dispatcher
    from uliweb.manage import make_simple_application

    project_dir = '.'
    application = make_simple_application(project_dir=project_dir)

    if project_dir not in sys.path:
        sys.path.insert(0, project_dir)

    app = application
    while app:
        if isinstance(app, Dispatcher):
            break
        else:
            app = app.app

    env = {'application': app, 'settings': settings, 'functions': functions}
    return env
示例#28
0
def make_shell_env(**kwargs):
    import os
    import sys
    from uliweb import functions, settings
    from uliweb.core.SimpleFrame import Dispatcher
    from uliweb.manage import make_simple_application

    project_dir = '.'
    application = make_simple_application(project_dir=project_dir)

    if project_dir not in sys.path:
        sys.path.insert(0, project_dir)

    app = application
    while app:
        if isinstance(app, Dispatcher):
            break
        else:
            app = app.app

    env = {'application':app, 'settings':settings, 'functions':functions}
    return env
示例#29
0
    def handle(self, options, global_options, *args):
        from uliweb.manage import make_simple_application
        from uliweb import orm
        from getpass import getpass

        app = make_simple_application(
            apps_dir=global_options.apps_dir,
            settings_file=global_options.settings,
            local_settings_file=global_options.local_settings)
        db = orm.get_connection()

        username = ''
        while not username:
            username = raw_input("Please enter the super user's name: ")
        email = ''
        while not email:
            email = raw_input("Please enter the email of [%s]: " % username)

        password = ''
        while not password:
            password = getpass("Please enter the password for [%s(%s)]: " %
                               (username, email))
        repassword = ''
        while not repassword:
            repassword = getpass("Please enter the password again: ")

        if password != repassword:
            print "The password is not matched, can't create super user!"
            return

        orm.set_dispatch_send(False)

        User = orm.get_model('user', options.engine)
        user = User(username=username, email=email)
        user.set_password(password)
        user.is_superuser = True
        user.save()
示例#30
0
from uliweb.manage import make_simple_application
from uliweb import functions
from uliweb.utils.common import log


def process():
    from uliweb.utils.common import Serial
    from uliweb.mail import Mail

    redis = functions.get_redis()
    while 1:
        data = redis.brpop("sendmail", 5)
        if data:
            message = Serial.load(data[1])
            log.info(message)
            Mail().send_mail(**message)
        else:
            log.info("no data")


if __name__ == "__main__":
    app = make_simple_application(project_dir="..")

    log.info("staring...")
    process()
示例#31
0
from redbreast.core.spec import CoreWFManager
from redbreast.core.spec import *
from redbreast.serializable import Workflow, Task
import os
from os.path import dirname, join


def event_log(event):
    print " --> spec %s, %s" % (event.task.get_name(), event.type)


locate_dir = os.path.dirname(__file__)
os.chdir(locate_dir)
os.chdir('test_project')
from uliweb.manage import make_simple_application
app = make_simple_application(apps_dir='./apps')

CoreWFManager.reset()
storage = WFDatabaseStorage()
CoreWFManager.set_storage(storage)

workflow_spec = CoreWFManager.get_workflow_spec('TestWorkflow')
workflow_spec.on("enter", event_log)
workflow_spec.on("ready", event_log)
workflow_spec.on("executed", event_log)
workflow_spec.on("completed", event_log)

print "--------Workflow Spec Dump ----------------------"
workflow_spec.dump()

workflow = Workflow(workflow_spec)
示例#32
0
import sys, os
import getopt
import tornado.wsgi
import tornado.httpserver
import tornado.ioloop

hostname = '0.0.0.0'
port = 80

opts, args = getopt.getopt(sys.argv[1:], "h:p:", [])
for o, a in opts:
    if o == '-h':
        hostname = a
    elif o == '-p':
        port = int(a)

path = os.path.dirname(os.path.abspath(__file__))
if path not in sys.path:
    sys.path.insert(0, path)

from uliweb.manage import make_simple_application
application = make_simple_application(project_dir=path)

container = tornado.wsgi.WSGIContainer(application)
http_server = tornado.httpserver.HTTPServer(container, xheaders=True)
http_server.listen(port, address=hostname)
tornado.ioloop.IOLoop.instance().start()

示例#33
0
import sys, os
import getopt
from gevent import monkey
from socketio.server import SocketIOServer

monkey.patch_all()

hostname = '127.0.0.1'
port = 80

opts, args = getopt.getopt(sys.argv[1:], "h:p:", [])
for o, a in opts:
    if o == '-h':
        hostname = a
    elif o == '-p':
        port = int(a)

path = os.path.dirname(os.path.abspath(__file__))
if path not in sys.path:
    sys.path.insert(0, path)

from uliweb.manage import make_simple_application
application = make_simple_application(project_dir=path)

SocketIOServer((hostname, port), application,
               resource="socket.io").serve_forever()
from redbreast.core.spec import CoreWFManager
from redbreast.core.spec import *
from redbreast.serializable import Workflow, Task
import os
from os.path import dirname, join

def event_log(event):
    print " --> spec %s, %s" % (event.task.get_name(), event.type)

locate_dir = os.path.dirname(__file__)
os.chdir(locate_dir)
os.chdir('test_project')
from uliweb.manage import make_simple_application
app = make_simple_application(apps_dir='./apps')

CoreWFManager.reset()
storage = WFDatabaseStorage()
CoreWFManager.set_storage(storage)

workflow_spec = CoreWFManager.get_workflow_spec('TestWorkflow')
workflow_spec.on("enter", event_log)
workflow_spec.on("ready", event_log)
workflow_spec.on("executed", event_log)
workflow_spec.on("completed", event_log)


print "--------Workflow Spec Dump ----------------------"
workflow_spec.dump()


print "---------RUN-------------------"
示例#35
0
#coding=utf8
import os
from uliweb.manage import make_simple_application
from uliweb import functions

os.chdir('../../..')
app = make_simple_application(project_dir='.')

from async_tasks import AsyncCommand

c = AsyncCommand('async_tasks.tasks.echo', {'message': 'hello'},
                 queue=['async_workers_localhost'])
functions.call_async(c)
示例#36
0
文件: test.py 项目: 28sui/uliweb
def get_app(project_path='.', settings_file='settings.ini', local_settings_file='local_settings.ini'):
    from uliweb.manage import make_simple_application
    
    app = make_simple_application(project_dir=project_path, settings_file=settings_file,
        local_settings_file=local_settings_file)
    return app
示例#37
0
        import traceback
        traceback.print_exc()
    
def process():
    from datetime import timedelta, datetime
    from uliweb.utils.common import Serial
    
    Request = functions.get_model('eventrequest')
    Event = functions.get_model('event')
    User = functions.get_model('user')

    #day = date.today() - timedelta(days=2)
    day = datetime(year=2013, month=3, day=24)
    
    redis = functions.get_redis()
    
    for obj in Request.filter((Request.c.event==Event.c.id) & (Event.c.begin_date==day) & (Request.c.user==User.c.id)).values(User.c.username, User.c.email, Event.c.title) :
        email = {}
        email['from_'] = 'codepark'
        email['to_'] = obj.email
        email['subject'] = u'活动通知'
        email['message'] = u'用户:%s 活动"%s"将于%s开始' % (obj.username, obj.title, date.today())
        message = Serial.dump(email)
        print 'xxxxxxxxxxxxx', message
        redis.lpush('sendmail', message)
        
if __name__ == '__main__':
    app = make_simple_application(project_dir='..')
    
    main()
示例#38
0
from redbreast.core.spec import *
from redbreast.middleware import Workflow, Task
import os
from os.path import dirname, join


def event_log(event):
    print " --> spec %s, %s" % (event.task.get_name(), event.type)


locate_dir = os.path.dirname(__file__)
os.chdir(locate_dir)
os.chdir("test_project")
from uliweb.manage import make_simple_application

app = make_simple_application(apps_dir="./apps")

CoreWFManager.reset()
storage = WFDatabaseStorage()
CoreWFManager.set_storage(storage)

workflow_spec = CoreWFManager.get_workflow_spec("TestWorkflow")
workflow_spec.on("enter", event_log)
workflow_spec.on("ready", event_log)
workflow_spec.on("executed", event_log)
workflow_spec.on("completed", event_log)


print "--------Workflow Spec Dump ----------------------"
workflow_spec.dump()