Exemplo n.º 1
0
def make_app():
    app.json_encoder = utils.APIJSONEncoder
    app.config["CASE_INSENSITIVE"] = config.CASE_INSENSITIVE
    app.config["SQLALCHEMY_DATABASE_URI"] = config.SQLA_URI
    app.config["BASIC_AUTH_USERNAME"] = os.environ.get("AUTOAPI_ADMIN_USERNAME", "")
    app.config["BASIC_AUTH_PASSWORD"] = os.environ.get("AUTOAPI_ADMIN_PASSWORD", "")

    CORS(app)
    basic_auth = BasicAuth(app)

    @app.before_request
    def refresh():
        tables = utils.get_tables()
        if tables != app.config["SQLALCHEMY_TABLES"]:
            utils.refresh_tables()
            app.config["SQLALCHEMY_TABLES"] = tables

    app.config["SQLALCHEMY_TABLES"] = utils.get_tables()

    @app.before_request
    def protect_admin():
        if request.path.startswith("/admin/"):
            if not basic_auth.authenticate():
                return basic_auth.challenge()

    blueprint = aws.make_blueprint()
    app.register_blueprint(blueprint)

    utils.activate(admin=True)

    route = os.path.join("/api-program", config.API_NAME)
    container = DispatcherMiddleware(app.wsgi_app, {route: app})

    return container
Exemplo n.º 2
0
def main():
    print("Docker Test")
    env = sys.argv[1]
    db_details = load_db_details(env)
    tables = get_tables('tables_list')
    for table_name in tables['table_name']:
        data, column_names = read_table(db_details, table_name)
        load_table(db_details, data, column_names, table_name)
Exemplo n.º 3
0
def main():
    env = sys.argv[1]
    db_details = get_credentials(env)
    tables = get_tables("tables_to_be_loaded.txt")
    for table in tables:
        print("Discovering data...")
        data, cols = read_table(db_details, table)
        print(f"Table: {table} | {len(data)} rows")
        print("Writing data...")
        write_table(db_details, table, data, cols)
        print("Process completed")
Exemplo n.º 4
0
def main():
    """Program takes atleast one argument"""
    env = sys.argv[1]
    db_details = DB_DETAILS[env]
    tables = get_tables('table_list')

    for table_name in tables['table_name']:
        print(table_name)

        data,column_names = read_table(db_details,table_name,10)

        query = build_insert_query('film_actor_target', column_names)

        insert_data(db_details, query, data, batchsize=100)
Exemplo n.º 5
0
def make_app():
    app = sandman2.get_app(config.SQLA_URI, Base=utils.AutomapModel)
    app.json_encoder = utils.APIJSONEncoder
    app.config['CASE_INSENSITIVE'] = config.CASE_INSENSITIVE
    app.config['BASIC_AUTH_USERNAME'] = os.environ.get('AUTOAPI_ADMIN_USERNAME', '')
    app.config['BASIC_AUTH_PASSWORD'] = os.environ.get('AUTOAPI_ADMIN_PASSWORD', '')

    CORS(app)
    basic_auth = BasicAuth(app)

    @app.before_request
    def refresh():
        tables = utils.get_tables()
        if tables != app.config['SQLALCHEMY_TABLES']:
            utils.refresh_tables()
            app.config['SQLALCHEMY_TABLES'] = tables

    @app.before_request
    def protect_admin():
        if request.path.startswith('/admin/'):
            if not basic_auth.authenticate():
                return basic_auth.challenge()

    aws_blueprint = aws.make_blueprint()
    app.register_blueprint(aws_blueprint)

    docs_blueprint = swagger.make_blueprint(app)
    app.register_blueprint(docs_blueprint)

    route = os.path.join('/api-program', config.API_NAME)
    container = DispatcherMiddleware(app.wsgi_app, {route: app})

    with app.app_context():
        app.config['SQLALCHEMY_TABLES'] = utils.get_tables()
        utils.activate()

    return app, container
Exemplo n.º 6
0
Arquivo: app.py Projeto: 18F/autoapi
 def refresh():
     tables = utils.get_tables()
     if tables != app.config['SQLALCHEMY_TABLES']:
         utils.refresh_tables()
         app.config['SQLALCHEMY_TABLES'] = tables
Exemplo n.º 7
0
Arquivo: app.py Projeto: 18F/autoapi
def make_app():
    app = sandman2.get_app(config.SQLA_URI, Base=utils.AutomapModel)

    app.json_encoder = utils.APIJSONEncoder
    app.config['CASE_INSENSITIVE'] = config.CASE_INSENSITIVE
    app.config['BASIC_AUTH_USERNAME'] = os.environ.get(
        'AUTOAPI_ADMIN_USERNAME', '')
    app.config['BASIC_AUTH_PASSWORD'] = os.environ.get(
        'AUTOAPI_ADMIN_PASSWORD', '')

    CORS(app)
    basic_auth = BasicAuth(app)

    @app.before_request
    def refresh():
        tables = utils.get_tables()
        if tables != app.config['SQLALCHEMY_TABLES']:
            utils.refresh_tables()
            app.config['SQLALCHEMY_TABLES'] = tables

    @app.before_request
    def protect_admin():
        if request.path.startswith('/admin/'):
            if not basic_auth.authenticate():
                return basic_auth.challenge()

    class RefreshTables(View):

        task_name = 'refresh'

        def dispatch_request(self):
            underway = RefreshLog.refresh_underway()
            if underway:
                return '''Refresh begun at {} still underway.

                Now: {}; timeout set for {} seconds'''.format(
                    underway.begun_at, datetime.now(),
                    config.REFRESH_TIMEOUT_SECONDS)
            try:
                subprocess.Popen(['invoke', self.task_name, ])
            except Exception as e:
                print('Problem with table refresh:')
                print(e)
            return 'Table refresh requested.'

    class QuickRefreshTables(RefreshTables):

        task_name = 'quick_refresh'

    app.add_url_rule('/refresh/', view_func=RefreshTables.as_view('refresh'))
    app.add_url_rule('/quick_refresh/',
                     view_func=QuickRefreshTables.as_view('quick_refresh'))

    aws_blueprint = aws.make_blueprint()
    app.register_blueprint(aws_blueprint)

    docs_blueprint = swagger.make_blueprint(app)
    app.register_blueprint(docs_blueprint)

    with app.app_context():
        app.config['SQLALCHEMY_TABLES'] = utils.get_tables()
        utils.activate()

    refresh_log_db.init_app(app)
    refresh_log_db.create_all(app=app)

    return app
Exemplo n.º 8
0
 def refresh():
     tables = utils.get_tables()
     if tables != app.config['SQLALCHEMY_TABLES']:
         utils.refresh_tables()
         app.config['SQLALCHEMY_TABLES'] = tables
Exemplo n.º 9
0
def make_app():
    app = sandman2.get_app(config.SQLA_URI, Base=utils.AutomapModel)

    app.json_encoder = utils.APIJSONEncoder
    app.config['CASE_INSENSITIVE'] = config.CASE_INSENSITIVE
    app.config['BASIC_AUTH_USERNAME'] = os.environ.get(
        'AUTOAPI_ADMIN_USERNAME', '')
    app.config['BASIC_AUTH_PASSWORD'] = os.environ.get(
        'AUTOAPI_ADMIN_PASSWORD', '')

    CORS(app)
    basic_auth = BasicAuth(app)

    @app.before_request
    def refresh():
        tables = utils.get_tables()
        if tables != app.config['SQLALCHEMY_TABLES']:
            utils.refresh_tables()
            app.config['SQLALCHEMY_TABLES'] = tables

    @app.before_request
    def protect_admin():
        if request.path.startswith('/admin/'):
            if not basic_auth.authenticate():
                return basic_auth.challenge()

    class RefreshTables(View):

        task_name = 'refresh'

        def dispatch_request(self):
            underway = RefreshLog.refresh_underway()
            if underway:
                return '''Refresh begun at {} still underway.

                Now: {}; timeout set for {} seconds'''.format(
                    underway.begun_at, datetime.now(),
                    config.REFRESH_TIMEOUT_SECONDS)
            try:
                subprocess.Popen([
                    'invoke',
                    self.task_name,
                ])
            except Exception as e:
                print('Problem with table refresh:')
                print(e)
            return 'Table refresh requested.'

    class QuickRefreshTables(RefreshTables):

        task_name = 'quick_refresh'

    app.add_url_rule('/refresh/', view_func=RefreshTables.as_view('refresh'))
    app.add_url_rule('/quick_refresh/',
                     view_func=QuickRefreshTables.as_view('quick_refresh'))

    aws_blueprint = aws.make_blueprint()
    app.register_blueprint(aws_blueprint)

    docs_blueprint = swagger.make_blueprint(app)
    app.register_blueprint(docs_blueprint)

    with app.app_context():
        app.config['SQLALCHEMY_TABLES'] = utils.get_tables()
        utils.activate()

    refresh_log_db.init_app(app)
    refresh_log_db.create_all(app=app)

    return app
Exemplo n.º 10
0
    if not os.path.isdir('unlock'):
        os.mkdir('unlock')

    if args.model == 'all':
        # 获取文件名称,提取名称中的年份排序 由小到大
        files = glob.glob(args.input + '/*.xls')
        files = sorted(files, key=year_in_file_name)

        for file in files:
            print(file)
            try:
                df = pd.read_excel(file)
            except xlrd.biffh.XLRDError:
                new_excel = utils.unlock_excel_to_new_file(file, 'unlock/')
                df = pd.read_excel(new_excel)
            cur_file_tables = utils.get_tables(df)

            save_to_sql(cur_file_tables)
            print("添加成功")
    elif args.model == 'append':

        try:
            df = pd.read_excel(args.file)
        except xlrd.biffh.XLRDError:
            new_excel = utils.unlock_excel_to_new_file(
                args.file, output_dir='./unlocked_files/')
            df = pd.read_excel(new_excel)

        cur_file_tables = utils.get_tables(df)

        save_to_sql(cur_file_tables)
Exemplo n.º 11
0
import subprocess, glob, os, sys
sys.path.append(".")
import utils
tables = utils.get_tables()
for table in tables:
    subprocess.call([
        "adb", "pull", "/sdcard/opendatakit/default/config/tables/" + table +
        "/properties.csv", "properties.csv"
    ])
    props = open("properties.csv", "r").read().split("\n")
    found = []
    for i in range(len(props)):
        row = props[i].split(",")
        if len(row) < 5: continue
        if row[2] == "defaultViewType":
            row[4] = "LIST"
            found.append("viewtype")
        if row[2] == "listViewFileName":
            row[4] = "config/assets/table.html#" + table
            found.append("listfile")
        if row[2] == "detailViewFileName":
            row[4] = "config/assets/detail.html"
            found.append("detailfile")
        props[i] = ",".join(row)
    if not "viewtype" in found:
        props.append("Table,default,defaultViewType,string,LIST")
    if not "listfile" in found:
        props.append(
            "Table,default,listViewFileName,string,config/assets/table.html#" +
            table)
    if not "detailfile" in found: