Skip to content

Commit

Permalink
py3升级.1
Browse files Browse the repository at this point in the history
  • Loading branch information
midoks committed May 1, 2021
1 parent ce537c4 commit 463b76e
Show file tree
Hide file tree
Showing 15 changed files with 190 additions and 161 deletions.
10 changes: 7 additions & 3 deletions class/core/files_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ def getRecycleBinApi(self):
data['dirs'].append(tmp)
else:
data['files'].append(tmp)
except:
except Exception as e:
print(e)
continue
return mw.returnJson(True, 'OK', data)

Expand Down Expand Up @@ -451,7 +452,7 @@ def checkExistsFilesApi(self):
else:
filesx.append(filename)

print filesx
# print(filesx)

for fn in filesx:
if fn == '.':
Expand Down Expand Up @@ -795,6 +796,8 @@ def getDir(self, path, page=1, page_size=10, search=None):
pageObj = mw.getPageObject(info, '1,2,3,4,5,6,7,8')
data['PAGE'] = pageObj[0]

print('....eeee.11..')

i = 0
n = 0
for filename in os.listdir(path):
Expand Down Expand Up @@ -834,7 +837,8 @@ def getDir(self, path, page=1, page_size=10, search=None):
filenames.append(filename + ';' + size + ';' +
mtime + ';' + accept + ';' + user + ';' + link)
n += 1
except:
except Exception as e:
print(e)
continue

data['DIR'] = sorted(dirnames)
Expand Down
17 changes: 9 additions & 8 deletions class/core/mw.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import datetime
import subprocess
import re
import hashlib

import db

Expand Down Expand Up @@ -143,19 +142,19 @@ def getPageObject(args, result='1,2,3,4,5,8'):
info = {}

info['count'] = 0
if args.has_key('count'):
if 'count' in args:
info['count'] = int(args['count'])

info['row'] = 10
if args.has_key('row'):
if 'row' in args:
info['row'] = int(args['row'])

info['p'] = 1
if args.has_key('p'):
if 'p' in args:
info['p'] = int(args['p'])
info['uri'] = {}
info['return_js'] = ''
if args.has_key('tojs'):
if 'tojs' in args:
info['return_js'] = args['tojs']

return (page.GetPage(info, result), page)
Expand All @@ -165,9 +164,10 @@ def md5(str):
# 生成MD5
try:
m = hashlib.md5()
m.update(str)
m.update(str.encode("utf-8"))
return m.hexdigest()
except:
except Exception as ex:
print(ex)
return False


Expand Down Expand Up @@ -273,7 +273,8 @@ def readFile(filename):
fBody = fp.read()
fp.close()
return fBody
except:
except Exception as e:
# print('readFile:', e)
return False


Expand Down
50 changes: 27 additions & 23 deletions class/core/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def GetPage(self, pageInfo, limit='1,2,3,4,5,6,7,8'):
self.SHIFT = self.__START_NUM - 1

keys = limit.split(',')

pages = {}
# 起始页
pages['1'] = self.__GetStart()
Expand All @@ -70,14 +69,16 @@ def GetPage(self, pageInfo, limit='1,2,3,4,5,6,7,8'):

# 当前显示页与总页数
pages['6'] = "<span class='Pnumber'>" + \
bytes(self.__C_PAGE) + "/" + bytes(self.__COUNT_PAGE) + "</span>"
str(self.__C_PAGE) + "/" + \
str(self.__COUNT_PAGE) + "</span>"

# 本页显示开始与结束行
pages['7'] = "<span class='Pline'>" + self.__FO + \
bytes(self.__START_NUM) + "-" + \
bytes(self.__END_NUM) + self.__LINE + "</span>"
pages['7'] = "<span class='Pline'>" + str(self.__FO) + \
str(self.__START_NUM) + "-" + \
str(self.__END_NUM) + str(self.__LINE) + "</span>"
# 行数
pages['8'] = "<span class='Pcount'>" + self.__COUNT_START + \
bytes(self.__COUNT_ROW) + self.__COUNT_END + "</span>"
pages['8'] = "<span class='Pcount'>" + str(self.__COUNT_START) + \
str(self.__COUNT_ROW) + str(self.__COUNT_END) + "</span>"

# 构造返回数据
retuls = '<div>'
Expand All @@ -96,10 +97,11 @@ def __GetEnd(self):
else:
if self.__RTURN_JS == "":
endStr = "<a class='Pend' href='" + self.__URI + "p=" + \
bytes(self.__COUNT_PAGE) + "'>" + self.__END + "</a>"
str(self.__COUNT_PAGE) + "'>" + str(self.__END) + "</a>"
else:
endStr = "<a class='Pend' onclick='" + self.__RTURN_JS + \
"(" + bytes(self.__COUNT_PAGE) + ")'>" + self.__END + "</a>"
"(" + str(self.__COUNT_PAGE) + ")'>" + \
str(self.__END) + "</a>"
return endStr

def __GetNext(self):
Expand All @@ -110,10 +112,11 @@ def __GetNext(self):
else:
if self.__RTURN_JS == "":
nextStr = "<a class='Pnext' href='" + self.__URI + "p=" + \
bytes(self.__C_PAGE + 1) + "'>" + self.__NEXT + "</a>"
str(self.__C_PAGE + 1) + "'>" + str(self.__NEXT) + "</a>"
else:
nextStr = "<a class='Pnext' onclick='" + self.__RTURN_JS + \
"(" + bytes(self.__C_PAGE + 1) + ")'>" + self.__NEXT + "</a>"
"(" + str(self.__C_PAGE + 1) + ")'>" + \
str(self.__NEXT) + "</a>"

return nextStr

Expand All @@ -134,15 +137,15 @@ def __GetPages(self):
if page > 0:
if self.__RTURN_JS == "":
pages += "<a class='Pnum' href='" + self.__URI + \
"p=" + bytes(page) + "'>" + bytes(page) + "</a>"
"p=" + str(page) + "'>" + str(page) + "</a>"
else:
pages += "<a class='Pnum' onclick='" + self.__RTURN_JS + \
"(" + bytes(page) + ")'>" + bytes(page) + "</a>"
"(" + str(page) + ")'>" + str(page) + "</a>"

# 当前页
if self.__C_PAGE > 0:
pages += "<span class='Pcurrent'>" + \
bytes(self.__C_PAGE) + "</span>"
str(self.__C_PAGE) + "</span>"

# 当前页之后
if self.__C_PAGE <= self.__LIST_NUM:
Expand All @@ -157,10 +160,10 @@ def __GetPages(self):
break
if self.__RTURN_JS == "":
pages += "<a class='Pnum' href='" + self.__URI + \
"p=" + bytes(page) + "'>" + bytes(page) + "</a>"
"p=" + str(page) + "'>" + str(page) + "</a>"
else:
pages += "<a class='Pnum' onclick='" + self.__RTURN_JS + \
"(" + bytes(page) + ")'>" + bytes(page) + "</a>"
"(" + str(page) + ")'>" + str(page) + "</a>"

return pages

Expand All @@ -172,10 +175,11 @@ def __GetPrev(self):
else:
if self.__RTURN_JS == "":
startStr = "<a class='Ppren' href='" + self.__URI + "p=" + \
bytes(self.__C_PAGE - 1) + "'>" + self.__PREV + "</a>"
str(self.__C_PAGE - 1) + "'>" + str(self.__PREV) + "</a>"
else:
startStr = "<a class='Ppren' onclick='" + self.__RTURN_JS + \
"(" + bytes(self.__C_PAGE - 1) + ")'>" + self.__PREV + "</a>"
"(" + str(self.__C_PAGE - 1) + ")'>" + \
str(self.__PREV) + "</a>"
return startStr

def __GetStart(self):
Expand All @@ -186,10 +190,10 @@ def __GetStart(self):
else:
if self.__RTURN_JS == "":
startStr = "<a class='Pstart' href='" + \
self.__URI + "p=1'>" + self.__START + "</a>"
self.__URI + "p=1'>" + str(self.__START) + "</a>"
else:
startStr = "<a class='Pstart' onclick='" + \
self.__RTURN_JS + "(1)'>" + self.__START + "</a>"
self.__RTURN_JS + "(1)'>" + str(self.__START) + "</a>"
return startStr

def __GetCpage(self, p):
Expand All @@ -212,11 +216,11 @@ def __GetCountPage(self):
# 取总页数
return int(math.ceil(self.__COUNT_ROW / float(self.ROW)))

def __SetUri(self, input):
def __SetUri(self, sinput):
# 构造URI
uri = '?'
for key in input:
for key in sinput:
if key == 'p':
continue
uri += key + '=' + input[key] + '&'
uri += key + '=' + sinput[key] + '&'
return str(uri)
59 changes: 35 additions & 24 deletions class/core/plugins_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import json

import sys
reload(sys)
sys.setdefaultencoding('utf8')

# reload(sys)
# sys.setdefaultencoding('utf8')

import threading
import multiprocessing
Expand Down Expand Up @@ -61,11 +62,11 @@ def fileApi(self):
if f.strip() == '':
return ''

file = self.__plugin_dir + '/' + name + '/' + f
file = mw.getPluginDir() + '/' + name + '/' + f
if not os.path.exists(file):
return ''

c = mw.readFile(file)
c = open(file, 'rb').read()
return c

def indexListApi(self):
Expand Down Expand Up @@ -166,8 +167,8 @@ def uninstallApi(self):

data = mw.execShell(execstr)
if mw.isAppleSystem():
print execstr
print data[0], data[1]
print(execstr)
print(data[0], data[1])
return mw.returnJson(True, '卸载执行成功!')
# if data[1] == '':
# return mw.returnJson(True, '已将卸载成功!')
Expand Down Expand Up @@ -206,8 +207,10 @@ def runApi(self):

data = self.run(name, func, version, args, script)
if data[1] == '':
return mw.returnJson(True, "OK", data[0].strip())
return mw.returnJson(False, data[1].strip())
r = mw.returnJson(True, "OK", data[0].strip())
r = mw.returnJson(False, data[1].strip())

return r

def callbackApi(self):
name = request.form.get('name', '')
Expand Down Expand Up @@ -284,7 +287,7 @@ def inputZipApi(self):
return mw.returnJson(False, '临时文件不存在,请重新上传!')
plugin_path = mw.getPluginDir() + '/' + plugin_name
if not os.path.exists(plugin_path):
print mw.execShell('mkdir -p ' + plugin_path)
print(mw.execShell('mkdir -p ' + plugin_path))
mw.execShell("\cp -rf " + tmp_path + '/* ' + plugin_path + '/')
mw.execShell('chmod -R 755 ' + plugin_path)
p_info = mw.readFile(plugin_path + '/info.json')
Expand Down Expand Up @@ -382,7 +385,7 @@ def checkStatusMThreads(self, plugins_info):
t = threads[i].getResult()
plugins_info[i]['status'] = t
except Exception as e:
print 'checkStatusMThreads:', str(e)
print('checkStatusMThreads:', str(e))

return plugins_info

Expand Down Expand Up @@ -438,13 +441,13 @@ def getPluginInfo(self, info):
else:
checks = mw.getRootDir() + '/' + info['checks']

if info.has_key('path'):
if 'path' in info:
path = info['path']

if path[0:1] != '/':
path = mw.getRootDir() + '/' + path

if info.has_key('coexist') and info['coexist']:
if 'coexist' in info and info['coexist']:
coexist = True

pInfo = {
Expand Down Expand Up @@ -507,7 +510,7 @@ def makeList(self, data, sType='0'):
plugins_info = []

if (data['pid'] == sType):
if type(data['versions']) == list and data.has_key('coexist') and data['coexist']:
if type(data['versions']) == list and 'coexist' in data and data['coexist']:
tmp_data = self.makeCoexist(data)
for index in range(len(tmp_data)):
plugins_info.append(tmp_data[index])
Expand All @@ -517,7 +520,7 @@ def makeList(self, data, sType='0'):
return plugins_info

if sType == '0':
if type(data['versions']) == list and data.has_key('coexist') and data['coexist']:
if type(data['versions']) == list and 'coexist' in data and data['coexist']:
tmp_data = self.makeCoexist(data)
for index in range(len(tmp_data)):
plugins_info.append(tmp_data[index])
Expand All @@ -542,8 +545,8 @@ def getAllList(self, sType='0'):
tmp_data = self.makeList(data, sType)
for index in range(len(tmp_data)):
plugins_info.append(tmp_data[index])
except Exception, e:
print e
except Exception as e:
print(e)
return plugins_info

def getAllListPage(self, sType='0', page=1, pageSize=10):
Expand All @@ -560,8 +563,8 @@ def getAllListPage(self, sType='0', page=1, pageSize=10):
tmp_data = self.makeList(data, sType)
for index in range(len(tmp_data)):
plugins_info.append(tmp_data[index])
except Exception, e:
print e
except Exception as e:
print(e)

start = (page - 1) * pageSize
end = start + pageSize
Expand Down Expand Up @@ -733,8 +736,8 @@ def getIndexList(self):
tmp_data[index]['display'] = True
plist.append(tmp_data[index])
continue
except Exception, e:
print 'getIndexList:', e
except Exception as e:
print('getIndexList:', e)

# 使用gevent模式时,无法使用多进程
# plist = self.checkStatusMProcess(plist)
Expand Down Expand Up @@ -788,12 +791,20 @@ def run(self, name, func, version, args='', script='index'):
if not os.path.exists(path):
return ('', '')
data = mw.execShell(py_cmd)
# data = os.popen(py_cmd).read()

if mw.isAppleSystem():
print 'run', py_cmd
print('run', py_cmd)
# print os.path.exists(py_cmd)
return (data[0].strip(), data[1].strip())

t1 = ''
t2 = ''
if isinstance(data[1], bytes):
t1 = str(data[1], encoding='utf-8')

if isinstance(data[0], bytes):
t2 = str(data[0], encoding='utf-8')

return (t1.strip(), t2.strip())

# 映射包调用
def callback(self, name, func, args='', script='index'):
Expand All @@ -805,6 +816,6 @@ def callback(self, name, func, args='', script='index'):
eval_str = "__import__('" + script + "')." + func + '(' + args + ')'
newRet = eval(eval_str)
if mw.isAppleSystem():
print 'callback', eval_str
print('callback', eval_str)

return (True, newRet)
Loading

0 comments on commit 463b76e

Please sign in to comment.