|
|
@ -11,10 +11,11 @@ sys.path.append(os.getcwd() + "/class/core") |
|
|
|
import mw |
|
|
|
import mw |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cmd = 'ls /usr/local/lib/ | grep python | cut -d \\ -f 1 | awk \'END {print}\'' |
|
|
|
# cmd = 'ls /usr/local/lib/ | grep python | cut -d \\ -f 1 | awk \'END {print}\'' |
|
|
|
info = mw.execShell(cmd) |
|
|
|
# info = mw.execShell(cmd) |
|
|
|
p = "/usr/local/lib/" + info[0].strip() + "/site-packages" |
|
|
|
# p = "/usr/local/lib/" + info[0].strip() + "/site-packages" |
|
|
|
sys.path.append(p) |
|
|
|
# sys.path.append(p) |
|
|
|
|
|
|
|
|
|
|
|
import psutil |
|
|
|
import psutil |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -61,6 +62,13 @@ def getArgs(): |
|
|
|
return tmp |
|
|
|
return tmp |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def checkArgs(data, ck=[]): |
|
|
|
|
|
|
|
for i in range(len(ck)): |
|
|
|
|
|
|
|
if not ck[i] in data: |
|
|
|
|
|
|
|
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!')) |
|
|
|
|
|
|
|
return (True, mw.returnJson(True, 'ok')) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getInitdConfTpl(): |
|
|
|
def getInitdConfTpl(): |
|
|
|
path = getPluginDir() + "/init.d/gogs.tpl" |
|
|
|
path = getPluginDir() + "/init.d/gogs.tpl" |
|
|
|
return path |
|
|
|
return path |
|
|
@ -218,8 +226,7 @@ def getDbConfValue(): |
|
|
|
return r |
|
|
|
return r |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def pMysqlDb(): |
|
|
|
def pMysqlDb(conf): |
|
|
|
conf = getDbConfValue() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
host = conf['HOST'].split(':') |
|
|
|
host = conf['HOST'].split(':') |
|
|
|
conn = mysqlDb.mysqlDb() |
|
|
|
conn = mysqlDb.mysqlDb() |
|
|
@ -232,6 +239,41 @@ def pMysqlDb(): |
|
|
|
return conn |
|
|
|
return conn |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def pSqliteDb(conf): |
|
|
|
|
|
|
|
# print(conf) |
|
|
|
|
|
|
|
import db |
|
|
|
|
|
|
|
psDb = db.Sql() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 默认 |
|
|
|
|
|
|
|
gsdir = getServerDir() + '/data' |
|
|
|
|
|
|
|
dbname = 'gogs' |
|
|
|
|
|
|
|
if conf['PATH'][0] == '/': |
|
|
|
|
|
|
|
# 绝对路径 |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
path = conf['PATH'].split('/') |
|
|
|
|
|
|
|
gsdir = getServerDir() + '/' + path[0] |
|
|
|
|
|
|
|
dbname = path[1].split('.')[0] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# print(gsdir, dbname) |
|
|
|
|
|
|
|
psDb.dbPos(gsdir, dbname) |
|
|
|
|
|
|
|
return psDb |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def pQuery(sql): |
|
|
|
|
|
|
|
conf = getDbConfValue() |
|
|
|
|
|
|
|
if conf['DB_TYPE'] == 'sqlite3': |
|
|
|
|
|
|
|
db = pSqliteDb(conf) |
|
|
|
|
|
|
|
data = db.query(sql, []).fetchall() |
|
|
|
|
|
|
|
return data |
|
|
|
|
|
|
|
elif conf['DB_TYPE'] == 'mysql': |
|
|
|
|
|
|
|
db = pMysqlDb(conf) |
|
|
|
|
|
|
|
return db.query(sql) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("仅支持mysql|sqlite3配置") |
|
|
|
|
|
|
|
exit(0) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def isSqlError(mysqlMsg): |
|
|
|
def isSqlError(mysqlMsg): |
|
|
|
# 检测数据库执行错误 |
|
|
|
# 检测数据库执行错误 |
|
|
|
_mysqlMsg = str(mysqlMsg) |
|
|
|
_mysqlMsg = str(mysqlMsg) |
|
|
@ -255,37 +297,35 @@ def isSqlError(mysqlMsg): |
|
|
|
return mw.returnData(True, 'OK') |
|
|
|
return mw.returnData(True, 'OK') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def start(): |
|
|
|
def gogsOp(method): |
|
|
|
|
|
|
|
|
|
|
|
file = initDreplace() |
|
|
|
file = initDreplace() |
|
|
|
data = mw.execShell(__SR + file + ' start') |
|
|
|
|
|
|
|
|
|
|
|
if not mw.isAppleSystem(): |
|
|
|
|
|
|
|
data = mw.execShell('systemctl ' + method + ' gogs') |
|
|
|
|
|
|
|
if data[1] == '': |
|
|
|
|
|
|
|
return 'ok' |
|
|
|
|
|
|
|
return 'fail' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data = mw.execShell(__SR + file + ' ' + method) |
|
|
|
if data[1] == '': |
|
|
|
if data[1] == '': |
|
|
|
return 'ok' |
|
|
|
return 'ok' |
|
|
|
return data[0] |
|
|
|
return data[0] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def start(): |
|
|
|
|
|
|
|
return gogsOp('start') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def stop(): |
|
|
|
def stop(): |
|
|
|
file = initDreplace() |
|
|
|
return gogsOp('stop') |
|
|
|
data = mw.execShell(__SR + file + ' stop') |
|
|
|
|
|
|
|
if data[1] == '': |
|
|
|
|
|
|
|
return 'ok' |
|
|
|
|
|
|
|
return data[1] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def restart(): |
|
|
|
def restart(): |
|
|
|
file = initDreplace() |
|
|
|
return gogsOp('restart') |
|
|
|
data = mw.execShell(__SR + file + ' restart') |
|
|
|
|
|
|
|
if data[1] == '': |
|
|
|
|
|
|
|
return 'ok' |
|
|
|
|
|
|
|
return data[1] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def reload(): |
|
|
|
def reload(): |
|
|
|
file = initDreplace() |
|
|
|
return gogsOp('reload') |
|
|
|
data = mw.execShell(__SR + file + ' reload') |
|
|
|
|
|
|
|
if data[1] == '': |
|
|
|
|
|
|
|
return 'ok' |
|
|
|
|
|
|
|
return data[1] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def initdStatus(): |
|
|
|
def initdStatus(): |
|
|
@ -391,15 +431,13 @@ def userList(): |
|
|
|
import math |
|
|
|
import math |
|
|
|
args = getArgs() |
|
|
|
args = getArgs() |
|
|
|
|
|
|
|
|
|
|
|
page = 1 |
|
|
|
data = checkArgs(args, ['page', 'page_size']) |
|
|
|
page_size = 10 |
|
|
|
if not data[0]: |
|
|
|
search = '' |
|
|
|
return data[1] |
|
|
|
if 'page' in args: |
|
|
|
|
|
|
|
page = int(args['page']) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if 'page_size' in args: |
|
|
|
|
|
|
|
page_size = int(args['page_size']) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
page = int(args['page']) |
|
|
|
|
|
|
|
page_size = int(args['page_size']) |
|
|
|
|
|
|
|
search = '' |
|
|
|
if 'search' in args: |
|
|
|
if 'search' in args: |
|
|
|
search = args['search'] |
|
|
|
search = args['search'] |
|
|
|
|
|
|
|
|
|
|
@ -407,17 +445,13 @@ def userList(): |
|
|
|
|
|
|
|
|
|
|
|
data['root_url'] = getRootUrl() |
|
|
|
data['root_url'] = getRootUrl() |
|
|
|
|
|
|
|
|
|
|
|
pm = pMysqlDb() |
|
|
|
|
|
|
|
start = (page - 1) * page_size |
|
|
|
start = (page - 1) * page_size |
|
|
|
list_count = pm.query('select count(id) as num from user') |
|
|
|
list_count = pQuery('select count(id) as num from user') |
|
|
|
count = list_count[0][0] |
|
|
|
count = list_count[0][0] |
|
|
|
|
|
|
|
list_data = pQuery( |
|
|
|
list_data = pm.query( |
|
|
|
|
|
|
|
'select id,name,email from user order by id desc limit ' + str(start) + ',' + str(page_size)) |
|
|
|
'select id,name,email from user order by id desc limit ' + str(start) + ',' + str(page_size)) |
|
|
|
|
|
|
|
data['list'] = mw.getPage({'count': count, 'p': page, |
|
|
|
page_info = {'count': count, 'p': page, |
|
|
|
'row': page_size, 'tojs': 'gogsUserList'}) |
|
|
|
'row': page_size, 'tojs': 'gogsUserList'} |
|
|
|
|
|
|
|
data['list'] = mw.getPage(page_info) |
|
|
|
|
|
|
|
data['page'] = page |
|
|
|
data['page'] = page |
|
|
|
data['page_size'] = page_size |
|
|
|
data['page_size'] = page_size |
|
|
|
data['page_count'] = int(math.ceil(count / page_size)) |
|
|
|
data['page_count'] = int(math.ceil(count / page_size)) |
|
|
@ -620,8 +654,7 @@ def getTotalStatistics(): |
|
|
|
st = status() |
|
|
|
st = status() |
|
|
|
data = {} |
|
|
|
data = {} |
|
|
|
if st.strip() == 'start': |
|
|
|
if st.strip() == 'start': |
|
|
|
pm = pMysqlDb() |
|
|
|
list_count = pQuery('select count(id) as num from repository') |
|
|
|
list_count = pm.query('select count(id) as num from repository') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if list_count.find("error") > -1: |
|
|
|
if list_count.find("error") > -1: |
|
|
|
data['status'] = False |
|
|
|
data['status'] = False |
|
|
|