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()
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)
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()
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)
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) 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 global_options.verbose: print "[%s] Resetting %s..." % (options.engine, show_table(name, t, i, _len)) t.drop(engine, checkfirst=True) t.create(engine)
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()
def handle(self, options, global_options, *args): d = {} d['appname'] = get_input("Appname:", option_value=options.appname) d['tablename'] = get_input("Table Name:", option_value=options.tablename) d['theme'] = get_input("Creation Theme([a]ngularjs, [h]tml), [e]sayui)[a]:", default="a", choices='ahe', option_value=options.theme) view_name = camel_to_cap(d['tablename'])+'View' view_file_name = 'views_%s.py' % d['tablename'] url_prefix = '/'+d['appname'] d['classname'] = get_input("View Class Name [%s]:" % view_name, default=view_name, option_value=options.classname) d['viewfile'] = get_input("Save views to [%s]:" % view_file_name, default=view_file_name, option_value=options.viewfile) d['url'] = get_input("Class View URL prefix [%s]:" % url_prefix, default=url_prefix, option_value=options.url) d['pagination'] = get_answer("Enable pagination", quit='q') == 'Y' d['query'] = get_answer("Enable query", quit='q') == 'Y' d['download'] = get_answer("Enable download", quit='q') == 'Y' if d['download']: d['downloadfile'] = get_input("Download filename [%s]:" % 'download.xls', default='download.xls', option_value=options.downloadfile) d['addview_popup'] = get_answer("Add View using popup", quit='q') == 'Y' d['addview_ajax'] = get_answer("Add View using ajax", quit='q') == 'Y' d['editview_popup'] = get_answer("Edit View using popup", quit='q') == 'Y' d['editview_ajax'] = get_answer("Edit View using ajax", quit='q') == 'Y' d['deleteview_ajax'] = get_answer("Delete View using ajax", quit='q') == 'Y' theme = {'a':'angularjs', 'h':'html', 'e':'easyui'} d['theme_name'] = theme_name = theme.get(d['theme']) self.process(theme_name, d, options, global_options, args)
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 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) orm.Commit() except: log.exception("There are something wrong when loading table [%s]" % name) orm.Rollback()
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)
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) for name, t in get_tables(global_options.apps_dir, tables=args, engine=options.engine, settings_file=global_options.settings, local_settings_file=global_options.local_settings).items(): if global_options.verbose: print '[%s] Dropping %s...' % (options.engine, name) t.drop(engine, checkfirst=True)
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()
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): ans = get_answer( 'The file %s is already existed, do you want to overwrite' % keyfile) if ans == 'n': return print 'Creating secretkey file %s...' % keyfile, f = open(keyfile, 'wb') secret_key = ''.join([ choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(settings.SECRETKEY.KEY_LENGTH) ]) f.write(secret_key) print 'OK'
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)
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)
def handle(self, options, global_options, *args): from sqlalchemy import create_engine 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(global_options.apps_dir) con = create_engine(engine) for name, t in get_tables(global_options.apps_dir, args, settings_file=global_options.settings, local_settings_file=global_options.local_settings).items(): if global_options.verbose: print 'Resetting %s...' % name t.drop(con) t.create(con)
def handle(self, options, global_options, *args): d = {} d['appname'] = get_input("Appname:", option_value=options.appname).lower() d['tablename'] = get_input("Table Name:", option_value=options.tablename).lower() d['theme'] = get_input( "Creation Theme([a]ngularjs, [h]tml), [e]sayui)[a], [m]mGrid, a[v]alon:", default="m", choices='ahemv', option_value=options.theme) view_name = camel_to_cap(d['tablename']) + 'View' view_file_name = 'views_%s.py' % d['tablename'] url_prefix = '/' + d['appname'] d['classname'] = get_input("View Class Name [%s]:" % view_name, default=view_name, option_value=options.classname) d['viewfile'] = get_input("Save views to [%s]:" % view_file_name, default=view_file_name, option_value=options.viewfile) layout_name = d['appname'].lower() + '_layout.html' d['layout'] = get_input("Layout template name [%s]:" % layout_name, default=layout_name, option_value=options.layout) d['url'] = get_input("Class View URL prefix [%s]:" % url_prefix, default=url_prefix, option_value=options.url) d['pagination'] = get_answer("Enable pagination", quit='q') == 'Y' d['query'] = get_answer("Enable query", quit='q') == 'Y' d['download'] = get_answer("Enable download", quit='q') == 'Y' if d['download']: d['downloadfile'] = get_input("Download filename [%s]:" % 'download.xls', default='download.xls', option_value=options.downloadfile) d['addview_popup'] = get_answer("Add View using popup", quit='q') == 'Y' d['addview_ajax'] = get_answer("Add View using ajax", quit='q') == 'Y' d['editview_popup'] = get_answer("Edit View using popup", quit='q') == 'Y' d['editview_ajax'] = get_answer("Edit View using ajax", quit='q') == 'Y' d['deleteview_ajax'] = get_answer("Delete View using ajax", quit='q') == 'Y' theme = { 'a': 'angularjs', 'h': 'html', 'e': 'easyui', 'm': 'mmgrid', 'v': 'avalon' } d['theme_name'] = theme_name = theme.get(d['theme']) self.process(theme_name, d, options, global_options, args)
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))
def handle(self, options, global_options, *args): from uliweb import orm if len(args) != 2: print self.print_help(self.prog_name, 'loadtablefile') sys.exit(1) if args: message = """Do you want to delete all data of [%s]-[%s] before loading, if you choose N, the data will not be deleted""" % ( options.engine, args[0]) else: print "Failed! You should pass one or more tables name." sys.exit(1) ans = 'Y' if global_options.yes else get_answer(message, quit='q') engine = get_engine(options, global_options) name = args[0] tables = get_tables(global_options.apps_dir, engine_name=options.engine, settings_file=global_options.settings, tables=[name], local_settings_file=global_options.local_settings) t = tables[name] 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) return if global_options.verbose: print '[%s] Loading %s...' % (options.engine, show_table(name, t, 0, 1)), try: orm.Begin() if options.text: format = 'txt' else: format = None t = load_table(t, args[1], engine, delimiter=options.delimiter, format=format, encoding=options.encoding, delete=ans == 'Y', 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()
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_tables(global_options.apps_dir, args, engine=options.engine, settings_file=global_options.settings, local_settings_file=global_options.local_settings) for name, t in tables.items(): if global_options.verbose: print '[%s] Loading %s...' % (options.engine, name) 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) orm.Commit() except: log.exception( "There are something wrong when loading table [%s]" % name) orm.Rollback()
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) 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 global_options.verbose: print '[%s] Resetting %s...' % (options.engine, show_table(name, t, i, _len)) t.drop(engine, checkfirst=True) t.create(engine)
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)
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)
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: print "Failed! You should pass one or more tables name." sys.exit(1) 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 in args: m = orm.get_model(name) if not m: print "Error! Can't find the table %s...Skipped!" % name continue t = m.table 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()
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) for name, t in get_tables( global_options.apps_dir, tables=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)
def handle(self, options, global_options, *args): from uliweb import orm if len(args) != 2: print self.print_help(self.prog_name, "loadtablefile") sys.exit(1) if args: message = ( """Do you want to delete all data of [%s]-[%s] before loading, if you choose N, the data will not be deleted""" % (options.engine, args[0]) ) else: print "Failed! You should pass one or more tables name." sys.exit(1) ans = get_answer(message, answers="Yn", quit="q") engine = get_engine(options, global_options) name = args[0] tables = get_tables( global_options.apps_dir, engine_name=options.engine, settings_file=global_options.settings, tables=[name], local_settings_file=global_options.local_settings, ) t = tables[name] if global_options.verbose: print "[%s] Loading %s..." % (options.engine, show_table(name, t, 0, 1)) try: orm.Begin() if options.text: format = "txt" else: format = None load_table( t, args[1], 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()
def handle(self, options, global_options, *args): from sqlalchemy import create_engine from uliweb import orm 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(global_options.apps_dir) con = create_engine(engine) for name in args: m = orm.get_model(name) if not m: print "Error! Can't find the table %s...Skipped!" % name continue t = m.table if global_options.verbose: print 'Dropping %s...' % name t.drop(con)
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_tables(global_options.apps_dir, args, engine=options.engine, settings_file=global_options.settings, local_settings_file=global_options.local_settings) for name, t in tables.items(): if global_options.verbose: print '[%s] Loading %s...' % (options.engine, name) 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) orm.Commit() except: log.exception("There are something wrong when loading table [%s]" % name) orm.Rollback()
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))
def handle(self, options, global_options, *args): from uliweb import orm if len(args) != 2: print self.print_help(self.prog_name, 'loadtablefile') sys.exit(1) if args: message = """Do you want to delete all data of [%s]-[%s] before loading, if you choose N, the data will not be deleted""" % (options.engine, args[0]) else: print "Failed! You should pass one or more tables name." sys.exit(1) ans = 'Y' if global_options.yes else get_answer(message, quit='q') engine = get_engine(options, global_options) name = args[0] tables = get_tables(global_options.apps_dir, engine_name=options.engine, settings_file=global_options.settings, tables=[name], local_settings_file=global_options.local_settings) t = tables[name] 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) return if global_options.verbose: print '[%s] Loading %s...' % (options.engine, show_table(name, t, 0, 1)), try: orm.Begin() if options.text: format = 'txt' else: format = None t = load_table(t, args[1], engine, delimiter=options.delimiter, format=format, encoding=options.encoding, delete=ans=='Y', 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()
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('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(settings.SECRETKEY.KEY_LENGTH)]) f.write(secret_key) print 'OK'
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()
def handle(self, options, global_options, *args): from uliweb import orm if len(args) != 2: print self.print_help(self.prog_name, 'loadtablefile') sys.exit(1) if args: message = """Do you want to delete all data of [%s] before loading, if you choose N, the data will not be deleted""" % args[0] else: print "Failed! You should pass one or more tables name." sys.exit(1) ans = get_answer(message, answers='Yn', quit='q') engine = get_engine(global_options.apps_dir) con = orm.get_connection(engine) name = args[0] m = orm.get_model(name) if not m: print "Error! Can't find the table %s...Skipped!" % name t = m.table if global_options.verbose: print 'Loading %s...' % name try: con.begin() if options.text: format = 'txt' else: format = None load_table(t, args[1], con, delimiter=options.delimiter, format=format, encoding=options.encoding, delete=ans=='Y') con.commit() except: log.exception("There are something wrong when loading table [%s]" % name) con.rollback()
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): ans = get_answer("The file %s is already existed, do you want to overwrite" % keyfile) if ans == "n": return print "Creating secretkey file %s..." % keyfile, f = open(keyfile, "wb") secret_key = "".join( [choice("abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)") for i in range(settings.SECRETKEY.KEY_LENGTH)] ) f.write(secret_key) print "OK"
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) def _f(table, filename, msg): session = orm.get_session() if session: session.close() orm.Begin() try: result = load_table(table, filename, engine, delimiter=options.delimiter, format=format, encoding=options.encoding, delete=ans=='Y', bulk=int(options.bulk), engine_name=engine.engine_name) if global_options.verbose: print(msg, result) orm.Commit() except: import traceback traceback.print_exc() orm.Rollback() 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 msg = '' if global_options.verbose: msg = '[%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 #fork process to run if sys.platform != 'win32' and options.multi>1: load_table_file(t, filename, options.multi, bulk=options.bulk) else: _f(t, filename, msg) except: log.exception("There are something wrong when loading table [%s]" % name) orm.Rollback() if options.zipfile: shutil.rmtree(path)
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)
def handle(self, options, global_options, *args): message = """This command will delete all workflow specs, are you sure to do?""" get_answer(message) self.get_application(global_options) clear()
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: print "Failed! You should pass one or more tables name." sys.exit(1) ans = 'Y' if global_options.yes else get_answer(message, quit='q') # 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, engine_name=options.engine, settings_file=global_options.settings, tables=args, local_settings_file=global_options.local_settings)) _len = len(tables) def _f(table, filename, msg): session = orm.get_session() if session: session.close() orm.Begin() try: result = load_table(table, filename, engine, delimiter=options.delimiter, format=format, encoding=options.encoding, delete=ans=='Y', bulk=int(options.bulk), engine_name=engine.engine_name) if global_options.verbose: print msg, result orm.Commit() except: orm.Rollback() manager = ProcessManager(options.multi) 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: msg = '[%s] Loading %s...' % (options.engine, show_table(name, t, i, _len)) try: filename = os.path.join(path, name+'.txt') if options.text: format = 'txt' else: format = None #fork process to run if sys.platform != 'win32' and options.multi>1: manager(_f, t, filename, msg) else: _f(t, filename, msg) except: log.exception("There are something wrong when loading table [%s]" % name) manager.join() if options.zipfile: shutil.rmtree(path)
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: print "Failed! You should pass one or more tables name." sys.exit(1) ans = 'Y' if global_options.yes else get_answer(message, quit='q') # 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, 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 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, delete=ans == 'Y', 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)