<commit_before>#!/usr/bin/env python
#-*-coding:utf-8-*-
import os, sys
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))

from flask import Flask
from flaskext.script import Manager
from scriptfan import config_app, dispatch_handlers, dispatch_apps
from scriptfan.extensions import *

manager = Manager(app)

@manager.option('-c', '--config', dest='config', help='Configuration file name', default='scriptfan.cfg')
def test(config):
    config_app(app, config)
    dispatch_handlers(app)
    dispatch_apps(app)
    app.run(host='0.0.0.0')

@manager.option('-c', '--config', dest='config', help='Configuration file name', default='scriptfan.cfg')
def initdb(config='scriptfan.cfg'):
    config_app(app, config)
    from scriptfan.models import *

    try:
        db.drop_all()
        db.create_all()
        print 'Create tables success'
    except Exception as e:
        print 'Create tables fail:', e
        sys.exit(0)

if __name__ == '__main__':
    manager.run()

<commit_msg>在initdb命令中，仅import db python不推荐在方法内部 import *<commit_after>#!/usr/bin/env python
#-*-coding:utf-8-*-
import os, sys
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))

from flask import Flask
from flaskext.script import Manager
from scriptfan import config_app, dispatch_handlers, dispatch_apps
from scriptfan.extensions import *

manager = Manager(app)

@manager.option('-c', '--config', dest='config', help='Configuration file name', default='scriptfan.cfg')
def test(config):
    config_app(app, config)
    dispatch_handlers(app)
    dispatch_apps(app)
    app.run(host='0.0.0.0')

@manager.option('-c', '--config', dest='config', help='Configuration file name', default='scriptfan.cfg')
def initdb(config='scriptfan.cfg'):
    config_app(app, config)
    from scriptfan.models import db

    try:
        db.drop_all()
        db.create_all()
        print 'Create tables success'
    except Exception as e:
        print 'Create tables fail:', e
        sys.exit(0)

if __name__ == '__main__':
    manager.run()


{'fraction_non_alphanumeric': 0.14342040413997043, 'fraction_numerical': 0.006899950714637753, 'mean_word_length': 4.037220843672457, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4580485', 'n_tokens_mistral': 671, 'n_tokens_neox': 666, 'n_words': 157}