Exemplo n.º 1
0
def check_version():
    if sys.version_info < (3, 0):
        sys.stdout.write('Please use python 3.x to run this script!\n')
        sys.exit(255)


check_version()

# prepare logger
jobname = os.path.splitext(os.path.basename(__file__))[0]
rootdir = os.path.dirname(os.path.abspath(__file__))
log_path = rootdir + os.path.sep + 'log'
log_file = log_path + os.path.sep + jobname + '.log'
if not os.path.exists(log_path):
    os.makedirs(log_path, 0o775)
logger = mylogger(jobname, log_file)


# make sure dir exist
def __makesuredirexist__(path):
    if not os.path.exists(path):
        logger.warning('path does not exist: {}'.format(path))
        logger.warning('auto create {}'.format(path))
        os.makedirs(path, 0o775)


# make sure file exist
def __makesurefileexist__(path):
    if not os.path.exists(path):
        logger.warning('path does not exist: {}'.format(path))
        logger.warning('auto create {}'.format(path))
Exemplo n.º 2
0
import os
import traceback
from flask import Flask, request, make_response
from Utils.loggerhandler import mylogger
from Utils.staticfile import ai_static_file
from webApi import ai_web_api

__author__ = 'wemiam'

import json

app = Flask(__name__)

# prepare logger
log_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + os.path.sep + 'Log' + os.path.sep + 'startapp.log'
logger = mylogger(os.path.splitext(os.path.basename(__file__))[0], log_path)

app.register_blueprint(ai_web_api)
app.register_blueprint(ai_static_file)


@app.before_request
def before_request():
    logger.info('request %s %s %s %s %s', request.remote_addr, request.method, request.scheme, request.full_path, json.dumps(request.json, ensure_ascii=False, indent=2))


@app.after_request
def after_request(response):
    if request.blueprint == 'ai_static_file':
        logger.info('response static file %s' , request.path)
    else: