Exemple #1
0
def praseData(request_body):
    action = request_body['action']
    sysout.info(mTag, 'action=' + str(action))
    if action == 'save_email':
        #save email request
        return saveEmail(request_body['email'])
    else:
        # pass
        return {'status': '0', 'result': 'bad request 40004'}
Exemple #2
0
def application(environ, start_response):
    # 定义请求的类型和当前请求成功的code
    start_response('200 OK', [('Content-Type', 'application/json')])
    # environ是当前请求的所有数据,包括Header和URL,body
    request_body = environ["wsgi.input"].read(
        int(environ.get("CONTENT_LENGTH", 0))).decode('utf-8')
    sysout.info(mTag, 'request: ' + str(request_body))
    request_body = json.loads(request_body)
    response = praseData(request_body)
    return [json.dumps(response)]
Exemple #3
0
def connect(dbhost, dbport, dbuser, dbpasswd, dbName):
    try:
        conn = pymysql.connect(host=dbhost, port=int(dbport), user=dbuser, passwd=dbpasswd, db = dbName)
        # cur = conn.cursor()
        # cur.execute('show databases')
        sysout.info(mTag, 'db connect success! '+str(dbhost)+":"+str(dbport))
        # sysout.info(mTag, str(conn))
        return conn
    except Exception as e:
        sysout.err(mTag, 'db connect failed : ' + str(e))
Exemple #4
0
def saveData(sql):
    sysout.info(mTag, sql)
    try:
        conn = connect(mdbHost, mdbport, mdbUser, mdbPwd, mdbAmino)
        cur = conn.cursor()
        cur.execute(sql)
        conn.commit()
        cur.close()
        conn.close()
        return True
    except Exception as e:
        sysout.err(mTag, 'db save failed : ' + str(e))
        return False
Exemple #5
0
def praseData(request_body):
    if type(request_body) != type({}):
        return resp_err_params
    else:
        action = request_body['action']
        sysout.info(TAG, 'action=' + str(action))

        # functions = {
        #     'initproject': initProject(request_body),
        #     'newVersion': newVersion(request_body)
        # }

        if action == 'initProject':
            return initProject(request_body)
        elif action == 'newVersion':
            return newVersion(request_body)
        elif action == 'runWithVm':
            return runWithVm(request_body)
        elif action == 'deleteProject':
            return deleteProject(request_body)
        elif action == 'getMyFiles':
            return getMyFiles(request_body)
        else:
            return {'status': 0, 'result': 'request & params not support!!!'}
Exemple #6
0
def run():
    # httpd = HTTPServer(mServer, AmiHTTPServer)
    httpd = make_server(mHost, mPort, application)
    sysout.info(mTag, 'http server is running on ' + str(mServer))
    httpd.serve_forever()
Exemple #7
0
 def __init__(self, cmd):
     self.popen = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
     pid = self.popen.pid
     sysout.info(TAG, 'Popen.pid:' + str(pid))
Exemple #8
0
# charset=utf-8

from base import sysout
from config import config, string
from server import httpServer

TAG = "NotebookServer"

warning = '\n ---- \n System Warning:\n ---- \n Before u start the NotebookServer, u have to make sure that u have already installed the module "Jupyter Notebook"! \n' + " Even though, there'll be some error when u use it !! \n ---- ---- ---- ---- \n"

if __name__ == '__main__':
    print(warning)
    sysout.info("", TAG + " is starting...")
    httpServer.run()