当前位置: 首页>>代码示例>>Python>>正文


Python commands.get_answer函数代码示例

本文整理汇总了Python中uliweb.core.commands.get_answer函数的典型用法代码示例。如果您正苦于以下问题:Python get_answer函数的具体用法?Python get_answer怎么用?Python get_answer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_answer函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle

    def handle(self, options, global_options, *args):
        from uliweb.orm import get_model
        from uliweb.core.SimpleFrame import get_app_dir
        
        if not options.test:
            if not options.skip_warning:
                message = """This command will delete all workflow specs, are you sure to do?"""
                get_answer(message)

        self.get_application(global_options)
        
        if not options.test:
            clear()
            print ""
        
        apps_list = self.get_apps(global_options)
        tasks, workflows = loadspec(apps_list, global_options)
        
        from uliweb.orm import get_model
        from uliweb.utils.common import Serial
        WorkflowSpec = get_model('workflow_spec')
        TaskSpec = get_model('task_spec')
        
        if not options.test:
            for name in tasks:
                task, file = tasks[name]
                spec = TaskSpec(name=name, content=Serial.dump(task), source=file)
                spec.save()
            
            for name in workflows:
                workflow, file = workflows[name]
                spec = WorkflowSpec(name=name, content=Serial.dump(workflow), source=file)
                spec.save()
开发者ID:panjunyong,项目名称:uliweb-redbreast,代码行数:33,代码来源:commands.py

示例2: handle

    def handle(self, options, global_options, *args):

        if not args:
            print "Failed! You should pass one or more tables name."
            sys.exit(1)

        message = """This command will drop all tables [%s], are you sure to reset""" % ','.join(args)
        get_answer(message)
        
        engine = get_engine(options, global_options)
        
        tables = get_sorted_tables(get_tables(global_options.apps_dir, 
            tables=args, engine_name=options.engine, 
            settings_file=global_options.settings, 
            local_settings_file=global_options.local_settings))
        _len = len(tables)
        for i, (name, t) in enumerate(tables):
            if t.__mapping_only__:
                msg = 'SKIPPED(Mapping Table)'
            else:
                t.drop(engine, checkfirst=True)
                t.create(engine)
                msg = 'SUCCESS'
            if global_options.verbose:
                print '[%s] Resetting %s...%s' % (options.engine, show_table(name, t, i, _len), msg)
开发者ID:08haozi,项目名称:uliweb,代码行数:25,代码来源:commands.py

示例3: handle

    def handle(self, options, global_options, *args):

        if not args:
            print "Failed! You should pass one or more tables name."
            sys.exit(1)

        message = """This command will drop all tables [%s], are you sure to drop""" % ",".join(args)
        get_answer(message)

        engine = get_engine(options, global_options)

        tables = get_sorted_tables(
            get_tables(
                global_options.apps_dir,
                tables=args,
                engine_name=options.engine,
                settings_file=global_options.settings,
                local_settings_file=global_options.local_settings,
            )
        )
        _len = len(tables)
        for i, (name, t) in enumerate(tables):
            if global_options.verbose:
                print "[%s] Dropping %s..." % (options.engine, show_table(name, t, i, _len))
            t.drop(engine, checkfirst=True)
开发者ID:xuxiandi,项目名称:uliweb,代码行数:25,代码来源:commands.py

示例4: handle

    def handle(self, options, global_options, *args):
        from uliweb import orm
        
        if args:
            message = """This command will delete all data of [%s] before loading, 
are you sure to load data""" % ','.join(args)
        else:
            message = """This command will delete whole database before loading, 
are you sure to load data"""

        get_answer(message)

        if not os.path.exists(options.dir):
            os.makedirs(options.dir)
        
        engine = get_engine(global_options.apps_dir)
        con = orm.get_connection(engine)

        for name, t in get_tables(global_options.apps_dir, args, engine=engine, settings_file=global_options.settings, local_settings_file=global_options.local_settings).items():
            if global_options.verbose:
                print 'Loading %s...' % name
            try:
                con.begin()
                filename = os.path.join(options.dir, name+'.txt')
                if options.text:
                    format = 'txt'
                else:
                    format = None
                load_table(t, filename, con, delimiter=options.delimiter, 
                    format=format, encoding=options.encoding)
                con.commit()
            except:
                log.exception("There are something wrong when loading table [%s]" % name)
                con.rollback()
开发者ID:zhangming0305,项目名称:uliweb,代码行数:34,代码来源:commands.py

示例5: handle

    def handle(self, options, global_options, *args):

        if args:
            message = """This command will drop all tables of app [%s], are you sure to reset""" % ','.join(args)
        else:
            message = """This command will drop whole database, are you sure to reset"""
        get_answer(message)
        
        engine = get_engine(options, global_options)
        
        for name, t in get_tables(global_options.apps_dir, args, engine=options.engine, settings_file=global_options.settings, local_settings_file=global_options.local_settings).items():
            if global_options.verbose:
                print '[%s] Resetting %s...' % (options.engine, name)
            t.drop(engine, checkfirst=True)
            t.create(engine)
开发者ID:tangjn,项目名称:uliweb,代码行数:15,代码来源:commands.py

示例6: handle

    def handle(self, options, global_options, *args):
        from uliweb import orm
        
        if args:
            message = """This command will delete all data of [%s]-[%s] before loading, 
are you sure to load data""" % (options.engine, ','.join(args))
        else:
            message = """This command will delete whole database [%s] before loading, 
are you sure to load data""" % options.engine

        get_answer(message)

        path = os.path.join(options.dir, options.engine)
        if not os.path.exists(path):
            os.makedirs(path)
        
        engine = get_engine(options, global_options)

        tables = get_sorted_tables(get_tables(global_options.apps_dir, args, 
            engine_name=options.engine, 
            settings_file=global_options.settings, 
            local_settings_file=global_options.local_settings))
        _len = len(tables)
        for i, (name, t) in enumerate(tables):
            if t.__mapping_only__:
                if global_options.verbose:
                    msg = 'SKIPPED(Mapping Table)'
                    print '[%s] Loading %s...%s' % (options.engine, show_table(name, t, i, _len), msg)
                continue
            if global_options.verbose:
                print '[%s] Loading %s...' % (options.engine, show_table(name, t, i, _len)),
            try:
                orm.Begin()
                filename = os.path.join(path, name+'.txt')
                if options.text:
                    format = 'txt'
                else:
                    format = None
                t = load_table(t, filename, engine, delimiter=options.delimiter, 
                    format=format, encoding=options.encoding, bulk=int(options.bulk),
                    engine_name=engine.engine_name)
                orm.Commit()
                if global_options.verbose:
                    print t
                
            except:
                log.exception("There are something wrong when loading table [%s]" % name)
                orm.Rollback()
开发者ID:chenke91,项目名称:uliweb,代码行数:48,代码来源:commands.py

示例7: handle

    def handle(self, options, global_options, *args):

        engine = get_engine(options, global_options)

        if args:
            message = """This command will drop all tables of app [%s], are you sure to reset""" % ','.join(args)
        else:
            message = """This command will drop whole database [%s], are you sure to reset""" % engine.engine_name

        ans = 'Y' if global_options.yes else get_answer(message)

        if ans!='Y':
            return

        tables = get_sorted_tables(get_tables(global_options.apps_dir, args,
            engine_name=options.engine, settings_file=global_options.settings,
            local_settings_file=global_options.local_settings))
        _len = len(tables)
        for i, (name, t) in enumerate(tables):
            if t.__mapping_only__:
                msg = 'SKIPPED(Mapping Table)'
            else:
                t.drop(engine, checkfirst=True)
                t.create(engine)
                msg = 'SUCCESS'
            if global_options.verbose:
                print '[%s] Resetting %s...%s' % (options.engine, show_table(name, t, i, _len), msg)
开发者ID:wangaicc,项目名称:uliweb,代码行数:27,代码来源:commands.py

示例8: handle

    def handle(self, options, global_options, *args):
        from uliweb.utils.common import pkg
        from uliweb import functions
        from uliweb.core.template import template_file
        from uliweb.orm import true
        import time

        self.get_application(global_options)

        Recorder = functions.get_model('uliwebrecorder')

        if args:
            if os.path.exists(args[0]):
                message = "Ths file %s is already exists, do you want to overwrite it?" % args[0]
                ans = 'Y' if global_options.yes else get_answer(message)
                if ans != 'Y':
                    return

            out = open(args[0], 'w')
            relpath = os.path.normpath(os.path.relpath(os.path.dirname(args[0]) or './', '.')).replace('\\', '/')
        else:
            out = sys.stdout
            relpath = '.'

        condition = true()
        if options.begin_time:
            condition = (Recorder.c.begin_datetime >= options.begin_time) & condition
        if options.id:
            condition = (Recorder.c.id >= int(options.id)) & condition

        path = pkg.resource_filename('uliweb.contrib.recorder', 'template_files')
        tplfile = os.path.join(path, options.template).replace('\\', '/')
        row_tplfile = os.path.join(path, options.template_row).replace('\\', '/')

        out.write('#coding=utf8\n')
        if global_options.verbose:
            print '#recorder template is "%s"' % tplfile
            print '#recorder row template is "%s"' % row_tplfile

        begin = time.time()
        rows = []
        for row in Recorder.filter(condition):
            rows.append(template_file(row_tplfile, {'row':row}).rstrip())

        out.write(template_file(tplfile, {'project_dir':relpath, 'rows':rows}))
        out.write('\n#total %d records output, time used %ds\n' % (len(rows), time.time()-begin))
开发者ID:limodou,项目名称:uliweb,代码行数:46,代码来源:subcommands.py

示例9: handle

 def handle(self, options, global_options, *args):
     from random import choice
     from uliweb.core.SimpleFrame import get_settings
     from uliweb.core.commands import get_answer
     
     settings = get_settings(global_options.project, settings_file=global_options.settings, 
         local_settings_file=global_options.local_settings)
     output = options.output or settings.SECRETKEY.SECRET_FILE
     keyfile = os.path.join(global_options.project, output)
     if os.path.exists(keyfile):
         message = 'The file %s is already existed, do you want to overwrite' % keyfile
         ans = 'Y' if global_options.yes else get_answer(message)
         if ans != 'Y':
             return
     print 'Creating secretkey file %s...' % keyfile,
     f = open(keyfile, 'wb')
     secret_key = ''.join([choice('[email protected]#$%^&*(-_=+)') for i in range(settings.SECRETKEY.KEY_LENGTH)])
     f.write(secret_key)
     print 'OK'
开发者ID:28sui,项目名称:uliweb,代码行数:19,代码来源:commands.py

示例10: handle

    def handle(self, options, global_options, *args):
        from uliweb import orm
        
        if args:
            message = """This command will delete all data of [%s]-[%s] before loading, 
are you sure to load data""" % (options.engine, ','.join(args))
        else:
            print "Failed! You should pass one or more tables name."
            sys.exit(1)

        ans = get_answer(message, answers='Yn', quit='q')

        path = os.path.join(options.dir, options.engine)
        if not os.path.exists(path):
            os.makedirs(path)
        
        engine = get_engine(options, global_options)

        tables = get_sorted_tables(get_tables(global_options.apps_dir, 
            engine_name=options.engine, 
            settings_file=global_options.settings, tables=args,
            local_settings_file=global_options.local_settings))
        _len = len(tables)
        
        for i, (name, t) in enumerate(tables):
            if global_options.verbose:
                print '[%s] Loading %s...' % (options.engine, show_table(name, t, i, _len))
            try:
                orm.Begin()
                filename = os.path.join(path, name+'.txt')
                if options.text:
                    format = 'txt'
                else:
                    format = None
                load_table(t, filename, engine, delimiter=options.delimiter, 
                    format=format, encoding=options.encoding, delete=ans=='Y')
                orm.Commit()
            except:
                log.exception("There are something wrong when loading table [%s]" % name)
                orm.Rollback()
开发者ID:chermong,项目名称:uliweb,代码行数:40,代码来源:commands.py

示例11: handle

    def handle(self, options, global_options, *args):
        from uliweb import orm
        from zipfile import ZipFile
        import shutil

        if args:
            message = """This command will delete all data of [%s]-[%s] before loading, 
are you sure to load data""" % (options.engine, ','.join(args))
        else:
            message = """This command will delete whole database [%s] before loading, 
are you sure to load data""" % options.engine

        ans = 'Y' if global_options.yes else get_answer(message)

        if ans != 'Y':
            return

        # extract zip file to path
        if options.zipfile:
            if options.dir and not os.path.exists(options.dir):
                os.makedirs(options.dir)
            path = get_temppath(prefix='dump', dir=options.dir)
            if global_options.verbose:
                print "Extract path is %s" % path
            zipfile = None
            try:
                zipfile = ZipFile(options.zipfile, 'r')
                zipfile.extractall(path)
            except:
                log.exception("There are something wrong when extract zip file [%s]" % options.zipfile)
                sys.exit(1)
            finally:
                if zipfile:
                    zipfile.close()
        else:
            path = os.path.join(options.dir, options.engine)
            if not os.path.exists(path):
                os.makedirs(path)

        engine = get_engine(options, global_options)

        tables = get_sorted_tables(get_tables(global_options.apps_dir, args, 
            engine_name=options.engine, 
            settings_file=global_options.settings, 
            local_settings_file=global_options.local_settings, all=options.all))
        _len = len(tables)
        for i, (name, t) in enumerate(tables):
            if hasattr(t, '__mapping_only__') and t.__mapping_only__:
                if global_options.verbose:
                    msg = 'SKIPPED(Mapping Table)'
                    print '[%s] Loading %s...%s' % (options.engine, show_table(name, t, i, _len), msg)
                continue
            if global_options.verbose:
                print '[%s] Loading %s...' % (options.engine, show_table(name, t, i, _len)),
            try:
                orm.Begin()
                filename = os.path.join(path, name+'.txt')
                if options.text:
                    format = 'txt'
                else:
                    format = None
                t = load_table(t, filename, engine, delimiter=options.delimiter, 
                    format=format, encoding=options.encoding,
                    bulk=int(options.bulk), engine_name=engine.engine_name)
                orm.Commit()
                if global_options.verbose:
                    print t
                
            except:
                log.exception("There are something wrong when loading table [%s]" % name)
                orm.Rollback()

        if options.zipfile:
            shutil.rmtree(path)
开发者ID:hb44,项目名称:uliweb,代码行数:74,代码来源:commands.py


注:本文中的uliweb.core.commands.get_answer函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。