예제 #1
0
    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))
예제 #2
0
    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))