From 75ece2a5debdbfc724ee6bcd4313ad44c83ab19e Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 25 Dec 2018 15:41:46 +0800 Subject: [PATCH] update --- app.py | 6 --- class/core/public.py | 12 ++++-- class/core/system_api.py | 9 ++++- class/core/task_api.py | 74 +++++++++++++++++++++++++++++++++++ route/__init__.py | 8 +++- route/config.py | 10 ----- route/control.py | 12 ------ route/task.py | 84 ---------------------------------------- 8 files changed, 96 insertions(+), 119 deletions(-) create mode 100755 class/core/task_api.py delete mode 100644 route/config.py delete mode 100644 route/control.py delete mode 100644 route/task.py diff --git a/app.py b/app.py index d652e210f..70bb36656 100644 --- a/app.py +++ b/app.py @@ -3,14 +3,8 @@ import sys import io import os - -sys.path.append(os.getcwd() + "/class/core") -import config from route import app - -# app = config.config().makeApp(__name__) - try: if __name__ == "__main__": app.run() diff --git a/class/core/public.py b/class/core/public.py index 823133754..b8614c7be 100755 --- a/class/core/public.py +++ b/class/core/public.py @@ -164,12 +164,16 @@ def getJson(data): return json.dumps(data) -def retOK(msg, data): - return returnJson(True, msg, data) +def returnData(status, msg, data): + return {'status': status, 'msg': msg, 'data': data} -def retFail(msg, data): - return returnJson(False, msg, data) +def retOK(data): + return {'status': True, 'msg': 'OK!', 'data': data} + + +def retFail(msg, data=None): + return {'status': False, 'msg': msg, 'data': data} def returnJson(status, msg, args=()): diff --git a/class/core/system_api.py b/class/core/system_api.py index 71bd73ccb..3c7144bef 100755 --- a/class/core/system_api.py +++ b/class/core/system_api.py @@ -22,9 +22,16 @@ class system_api: self.setupPath = public.getServerDir() ##### ----- start ----- ### - def network(self): + def networkApi(self): return self.getNetWork() + # @system.route("/update_server") + def updateServerApi(self): + stype = request.args.get('type', 'check') + version = request.args.get('version', '') + data = self.updateServer(stype, version) + return data + ##### ----- end ----- ### # 名取PID diff --git a/class/core/task_api.py b/class/core/task_api.py new file mode 100755 index 000000000..57921449d --- /dev/null +++ b/class/core/task_api.py @@ -0,0 +1,74 @@ +# coding: utf-8 + +import psutil +import time +import os +import sys +import public +import re +import json +import pwd + + +class task_api: + + def __init__(self): + pass + + def count(self): + c = public.M('tasks').where("status!=?", ('1',)).count() + return str(c) + + def list(self): + _list = public.M('tasks').where('', ()).field('id,name,type,status,addtime,start,end').limit( + '0,5').order('id desc').select() + _ret = {} + _ret['data'] = _list + + count = public.M('tasks').where('', ()).count() + _page = {} + _page['count'] = count + _page['tojs'] = 'remind' + + _ret['page'] = public.getPage(_page) + return public.getJson(_ret) + + def getExecLog(self): + file = os.getcwd() + "/tmp/panelExec.log" + v = public.getLastLine(file, 100) + return v + + def getTaskSpeed(self): + tempFile = os.getcwd() + '/tmp/panelExec.log' + freshFile = os.getcwd() + '/tmp/panelFresh' + + find = public.M('tasks').where('status=? OR status=?', + ('-1', '0')).field('id,type,name,execstr').find() + if not len(find): + return public.returnJson(False, '当前没有任务队列在执行-2!') + + isTask = os.getcwd() + '/tmp/panelTask.pl' + public.writeFile(isTask, 'True') + + echoMsg = {} + echoMsg['name'] = find['name'] + echoMsg['execstr'] = find['execstr'] + if find['type'] == 'download': + import json + try: + tmp = public.readFile(tempFile) + if len(tmp) < 10: + return public.returnMsg(False, '当前没有任务队列在执行-3!') + echoMsg['msg'] = json.loads(tmp) + echoMsg['isDownload'] = True + except: + db.Sql().table('tasks').where( + "id=?", (find['id'],)).save('status', ('0',)) + return public.returnMsg(False, '当前没有任务队列在执行-4!') + else: + echoMsg['msg'] = public.getLastLine(tempFile, 20) + echoMsg['isDownload'] = False + + echoMsg['task'] = public.M('tasks').where("status!=?", ('1',)).field( + 'id,status,name,type').order("id asc").select() + return public.getJson(echoMsg) diff --git a/route/__init__.py b/route/__init__.py index 48b460280..6bac12a4b 100755 --- a/route/__init__.py +++ b/route/__init__.py @@ -43,13 +43,17 @@ def funConvert(fun): def publicObject(toObject, func, action=None, get=None): - name = funConvert(func) + name = funConvert(func) + 'Api' if hasattr(toObject, name): efunc = 'toObject.' + name + '()' data = eval(efunc) return public.getJson(data) + return public.retFail('Access Exception!') - return 'fail' + +@app.route("/check_login", methods=['POST', 'GET']) +def checkLogin(): + return "true" @app.route('//', methods=['POST', 'GET']) diff --git a/route/config.py b/route/config.py deleted file mode 100644 index 22ac9486f..000000000 --- a/route/config.py +++ /dev/null @@ -1,10 +0,0 @@ -# coding:utf-8 - -from flask import Blueprint, render_template - -config = Blueprint('config', __name__, template_folder='templates') - - -@config.route("/") -def index(): - return render_template('default/config.html') diff --git a/route/control.py b/route/control.py deleted file mode 100644 index 630f221cc..000000000 --- a/route/control.py +++ /dev/null @@ -1,12 +0,0 @@ -# coding:utf-8 - -from flask import Flask -from flask import Blueprint, render_template - - -control = Blueprint('control', __name__, template_folder='templates') - - -@control.route("/") -def index(): - return render_template('default/control.html') diff --git a/route/task.py b/route/task.py deleted file mode 100644 index b6801928a..000000000 --- a/route/task.py +++ /dev/null @@ -1,84 +0,0 @@ -# coding:utf-8 - -import os -import sys - -from flask import Flask -from flask import Blueprint, render_template - - -task = Blueprint('task', __name__, template_folder='templates') - -sys.path.append("/class/core") -import public - - -@task.route("/") -def index(): - return render_template('default/site.html') - - -@task.route("/count") -def count(): - c = public.M('tasks').where("status!=?", ('1',)).count() - return str(c) - - -@task.route("/list", methods=['GET', 'POST']) -def list(): - _list = public.M('tasks').where('', ()).field('id,name,type,status,addtime,start,end').limit( - '0,5').order('id desc').select() - _ret = {} - _ret['data'] = _list - - count = public.M('tasks').where('', ()).count() - _page = {} - _page['count'] = count - _page['tojs'] = 'remind' - - _ret['page'] = public.getPage(_page) - return public.getJson(_ret) - - -@task.route('/get_exec_log', methods=['POST']) -def getExecLog(): - file = os.getcwd() + "/tmp/panelExec.log" - v = public.getLastLine(file, 100) - return v - - -@task.route("/get_task_speed", methods=['GET', 'POST']) -def getTaskSpeed(): - tempFile = os.getcwd() + '/tmp/panelExec.log' - freshFile = os.getcwd() + '/tmp/panelFresh' - - find = public.M('tasks').where('status=? OR status=?', - ('-1', '0')).field('id,type,name,execstr').find() - if not len(find): - return public.returnJson(False, '当前没有任务队列在执行-2!') - - isTask = os.getcwd() + '/tmp/panelTask.pl' - public.writeFile(isTask, 'True') - - echoMsg = {} - echoMsg['name'] = find['name'] - echoMsg['execstr'] = find['execstr'] - if find['type'] == 'download': - import json - try: - tmp = public.readFile(tempFile) - if len(tmp) < 10: - return public.returnMsg(False, '当前没有任务队列在执行-3!') - echoMsg['msg'] = json.loads(tmp) - echoMsg['isDownload'] = True - except: - db.Sql().table('tasks').where( - "id=?", (find['id'],)).save('status', ('0',)) - return public.returnMsg(False, '当前没有任务队列在执行-4!') - else: - echoMsg['msg'] = public.getLastLine(tempFile, 20) - echoMsg['isDownload'] = False - - echoMsg['task'] = public.M('tasks').where("status!=?", ('1',)).field( - 'id,status,name,type').order("id asc").select() - return public.getJson(echoMsg)