添加filedispose
This commit is contained in:
69
server/filedispose/Package.py
Normal file
69
server/filedispose/Package.py
Normal file
@@ -0,0 +1,69 @@
|
||||
# coding=utf-8
|
||||
#!/bin/python
|
||||
#cding=utf-8
|
||||
# encoding=utf8
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
name = "filedispose"
|
||||
Version = "V0.2"
|
||||
|
||||
def install(new_client_socket,post,Versino,Headers,info,prin):
|
||||
pkg=""
|
||||
try:
|
||||
fs = open("server/server.ini", "rb")
|
||||
pkg = fs.read().decode("utf-8").split('\n')
|
||||
except Exception as e:
|
||||
prin(new_client_socket,(e.args).encode("utf-8"))
|
||||
inpkg = "install"
|
||||
for i in pkg:
|
||||
if i.split('\r')[0] == name:
|
||||
inpkg = ""
|
||||
prin(new_client_socket,("install " + name + " " + Version + "\n\r").encode("utf-8"))
|
||||
os.system("cp -rf .out/" + name + "_" + Version + ".pkg/.out/* ./")
|
||||
|
||||
if inpkg == "install":
|
||||
os.system("echo " + name + ">>server/server.ini")
|
||||
# prin(new_client_socket,("END\n\r").encode("utf-8"))
|
||||
os.system("rm -rf .out/" + name + "_" + Version + ".pkg")
|
||||
def remove():
|
||||
os.system("rm -rf server/" + name)
|
||||
os.system("rm -rf web/" + name)
|
||||
def out():
|
||||
#os.system("cp -rf web/" + name + " .out/web/")
|
||||
os.system("cp -rf web/Ace_Admin/" + name + " .out/web/Ace_Admin/")
|
||||
os.system("cp -rf server/" + name + " .out/server/")
|
||||
|
||||
rm('.out/server/','__pycache__')
|
||||
|
||||
# os.system("find .out/ -name __pycache__")
|
||||
def rm(dir,name):
|
||||
path = os.listdir(dir)
|
||||
for p in path:
|
||||
if os.path.isdir(dir + p):
|
||||
if p == name:
|
||||
os.system("rm -rf " + dir + name)
|
||||
else:
|
||||
rm(dir + p + '/',name)
|
||||
def info():
|
||||
print("Package:" + name)
|
||||
print("name:文件处理")
|
||||
print("Version:" + Version)
|
||||
print("Depends:main")
|
||||
print("License:GPL-2.0")
|
||||
print("Description:文件处理")
|
||||
print("issued:pkg")
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) == 1:
|
||||
sys.argv = sys.argv[0],"install"
|
||||
|
||||
if sys.argv[1] == "install":
|
||||
install('','','','','')
|
||||
elif sys.argv[1] == "remove":
|
||||
remove()
|
||||
elif sys.argv[1] == "out":
|
||||
out()
|
||||
else:
|
||||
info()
|
||||
42
server/filedispose/api/api.py
Normal file
42
server/filedispose/api/api.py
Normal file
@@ -0,0 +1,42 @@
|
||||
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import imp
|
||||
|
||||
def main(new_client_socket,RUL_CS,post_data,Headers,info,user):
|
||||
httpserver = imp.load_source("server/main/httpserver.py","server/main/httpserver.py")
|
||||
type = ""
|
||||
|
||||
post = RUL_CS
|
||||
for i in post:
|
||||
tmp = i.split('=')
|
||||
if tmp[0] == 'type':
|
||||
type = tmp[1]
|
||||
|
||||
if type == "index":
|
||||
data = '\
|
||||
<div class="tabbable" >\
|
||||
<ul class="nav nav-tabs" id="myTab">\
|
||||
<li style="float: right">\
|
||||
<a data-toggle="tab" href="#tabdata" onclick="click:addtab();return false;">\
|
||||
添加 \
|
||||
</a>\
|
||||
</li>\
|
||||
</ul>\
|
||||
<div class="tab-content" style="height: 100%;" id="tabn">\
|
||||
<div id="tabdata" class="tab-pane fade">\
|
||||
<div id="tabs"></div>\
|
||||
</div>\
|
||||
</div>\
|
||||
</div>\
|
||||
<script type="text/javascript">\
|
||||
//function index(){\
|
||||
document.getElementById("biaotou").innerHTML = "123";\
|
||||
//}\
|
||||
</script>'
|
||||
httpserver.httppostchar(new_client_socket,"200",data.encode("utf-8"),"text/html;charset=UTF-8",Headers,info)
|
||||
return
|
||||
httpserver = imp.load_source("server/main/httpserver.py","server/main/httpserver.py")
|
||||
httpserver.httppostchar(new_client_socket,"400","400 bad request".encode("utf-8"),"text/html;charset=UTF-8",Headers,info)
|
||||
|
||||
5
server/filedispose/biao.json
Normal file
5
server/filedispose/biao.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "文件处理",
|
||||
"link": "filedispose?",
|
||||
"fa": "fa-tachometer"
|
||||
}
|
||||
43
server/filedispose/default/add/api.py
Normal file
43
server/filedispose/default/add/api.py
Normal file
@@ -0,0 +1,43 @@
|
||||
# coding=utf-8
|
||||
#!/bin/python
|
||||
|
||||
import imp
|
||||
import os
|
||||
|
||||
def main(new_client_socket,RUL_CS,post_data,Headers,info,user):
|
||||
httpserver = imp.load_source("server/main/httpserver.py","server/main/httpserver.py")
|
||||
sql = imp.load_source("server/main/filesql.py","server/main/filesql.py")
|
||||
|
||||
dir = ''
|
||||
name = ''
|
||||
post = RUL_CS
|
||||
for i in post:
|
||||
tmp = i.split('=')
|
||||
if tmp[0] == 'dir':
|
||||
dir = tmp[1]
|
||||
if tmp[0] == 'name':
|
||||
name = tmp[1]
|
||||
json = ''
|
||||
|
||||
if name == "":
|
||||
json = '名称呢'
|
||||
else:
|
||||
if not os.path.exists(".config/filenocopy"):
|
||||
os.mkdir(".config/filenocopy")
|
||||
if not os.path.exists(".config/filenocopy/default.db"):
|
||||
data = {}
|
||||
data["name"] = "name"
|
||||
data["dir"] = "dir"
|
||||
sql.new(".config/filenocopy/default.db",data)
|
||||
fo = sql.catlen(".config/filenocopy/default.db")
|
||||
fsdata = sql.cat(".config/filenocopy/default.db",name,0)
|
||||
if not fsdata:
|
||||
data = {}
|
||||
data["name"] = name
|
||||
data["dir"] = dir
|
||||
sql.prin(".config/filenocopy/default.db",data)
|
||||
json = '添加成功'
|
||||
else:
|
||||
json = '已存在'
|
||||
|
||||
httpserver.httppostchar(new_client_socket,"200",json.encode('utf-8'),"text/html;charset=UTF-8",Headers,info)
|
||||
37
server/filedispose/default/info/api.py
Normal file
37
server/filedispose/default/info/api.py
Normal file
@@ -0,0 +1,37 @@
|
||||
# coding=utf-8
|
||||
#!/bin/python
|
||||
|
||||
import imp
|
||||
import os
|
||||
import psutil
|
||||
|
||||
def main(new_client_socket,RUL_CS,post_data,Headers,info,user):
|
||||
httpserver = imp.load_source("server/main/httpserver.py","server/main/httpserver.py")
|
||||
sql = imp.load_source("server/main/filesql.py","server/main/filesql.py")
|
||||
|
||||
json = ''
|
||||
fo = sql.catlen(".config/filenocopy/default.db")
|
||||
|
||||
json += '{"fo":' + str(fo) + ',"data":['
|
||||
for i in sql.catall(".config/filenocopy/default.db"):
|
||||
i = i.split(b'\t')
|
||||
json += '{"dir":"' + i[0].decode("utf-8") + '","name":"' + i[1].decode("utf-8") +'"},'
|
||||
json += '{}]}'
|
||||
httpserver.httppostchar(new_client_socket,"200",json.encode('utf-8'),"application/json",Headers,info)
|
||||
|
||||
def get_free_space_mb(folder):
|
||||
import platform
|
||||
import ctypes
|
||||
import os
|
||||
"""
|
||||
获取磁盘剩余空间
|
||||
:param folder: 磁盘路径 例如 D:\\
|
||||
:return: 剩余空间 单位 G
|
||||
"""
|
||||
if platform.system() == 'Windows':
|
||||
free_bytes = ctypes.c_ulonglong(0)
|
||||
ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(folder), None, None, ctypes.pointer(free_bytes))
|
||||
return free_bytes.value / 1024 / 1024
|
||||
else:
|
||||
st = os.statvfs(folder)
|
||||
return st.f_bavail * st.f_frsize / 1024 / 1024
|
||||
400
server/filedispose/filemd5cp/api.py
Normal file
400
server/filedispose/filemd5cp/api.py
Normal file
@@ -0,0 +1,400 @@
|
||||
# coding=utf-8
|
||||
#!/bin/python
|
||||
|
||||
import imp
|
||||
import os
|
||||
import sys
|
||||
|
||||
def runn(new_client_socket,httpserver,sql,x,indir):
|
||||
dirn = os.listdir(x[0].decode('utf-8') + indir)
|
||||
dirn.sort(reverse=False)
|
||||
for i in dirn:
|
||||
dir = x[0].decode('utf-8') + indir + '/' + i
|
||||
if os.path.isdir(dir):
|
||||
httpserver.websockfsstr(new_client_socket,('d ' + x[1].decode('utf-8') + indir + '/' + i + '\r\n').encode("utf-8"))
|
||||
runn(new_client_socket,httpserver,sql,x,indir + '/' + i)
|
||||
if len(os.listdir(dir)) == 0:
|
||||
os.rmdir(dir)
|
||||
else:
|
||||
fsdata = sql.cat(".config/filenocopy/data.db",i,0)
|
||||
if not fsdata:
|
||||
fsdata = sql.cat(".config/filenocopy/temp.db",i,0)
|
||||
if not fsdata:
|
||||
addr = sql.cat(".config/filenocopy/default.db",i.split('.')[-1],0)
|
||||
if not addr:
|
||||
addr = indir[1:]
|
||||
else:
|
||||
addr = addr[1].decode('utf-8')
|
||||
httpserver.websockfsstr(new_client_socket,('n ' + x[1].decode('utf-8') + indir + '/' + i + '\t' + addr + '\t' + i + '\r\n').encode("utf-8"))
|
||||
else:
|
||||
httpserver.websockfsstr(new_client_socket,('f ' + x[1].decode('utf-8') + indir + '/' + i + '\t' + fsdata[1].decode('utf-8') + '\t' + i + '\r\n').encode("utf-8"))
|
||||
mvrun(new_client_socket,httpserver,sql,x[0].decode('utf-8') + indir + '/' + i,fsdata)
|
||||
else:
|
||||
httpserver.websockfsstr(new_client_socket,('f ' + x[1].decode('utf-8') + indir + '/' + i + '\t' + fsdata[1].decode('utf-8') + '\t' + i + '\r\n').encode("utf-8"))
|
||||
mvrun(new_client_socket,httpserver,sql,x[0].decode('utf-8') + indir + '/' + i,fsdata)
|
||||
|
||||
def mvrun(new_client_socket,httpserver,sql,indir,fsdata):
|
||||
size = os.stat(indir).st_size / 1024 / 1024 + 100
|
||||
outdir = ''
|
||||
for i in sql.catall(".config/filenocopy/outdir.db"):
|
||||
i = i.split(b'\t')
|
||||
outsize = get_free_space_mb(i[0].decode("utf-8"))
|
||||
if size < outsize:
|
||||
outdir = i
|
||||
break
|
||||
if outdir == '':
|
||||
httpserver.websockfsstr(new_client_socket,('b ' + '剩余空间不够' + '\r\n').encode("utf-8"))
|
||||
elif os.stat(indir).st_size == 0:
|
||||
httpserver.websockfsstr(new_client_socket,('b ' + '文件损坏' + '\r\n').encode("utf-8"))
|
||||
else:
|
||||
md5 = get_file_md5(new_client_socket,httpserver,sql,indir,"md5")
|
||||
dir = outdir[0] + b'/' + outdir[1] + b'/' + fsdata[1] + b'/' + fsdata[0]
|
||||
dir = dir.decode("utf-8")
|
||||
if not os.path.exists(dir):
|
||||
cpcp(new_client_socket,httpserver,sql,indir,outdir,fsdata)
|
||||
outmd5 = get_file_md5(new_client_socket,httpserver,sql,outdir[0].decode("utf-8") + '/' + outdir[1].decode("utf-8") + '/' + fsdata[1].decode("utf-8") + "/" + indir.split('/')[-1],"verify")
|
||||
if md5 == outmd5:
|
||||
data = {}
|
||||
if not os.path.exists(".config/filenocopy/data.db"):
|
||||
data["name"] = "name"
|
||||
data["dir"] = "dir"
|
||||
data["md5"] = "md5"
|
||||
data["diskname"] = "diskname"
|
||||
data["diakdir"] = "diakdir"
|
||||
sql.new(".config/filenocopy/data.db",data)
|
||||
data["name"] = fsdata[0].decode("utf-8")
|
||||
data["dir"] = fsdata[1].decode("utf-8")
|
||||
data["md5"] = outmd5
|
||||
data["diskname"] = outdir[1].decode("utf-8")
|
||||
data["diakdir"] = outdir[0].decode("utf-8")
|
||||
if sql.prin(".config/filenocopy/data.db",data):
|
||||
if sql.rmt(".config/filenocopy/temp.db",fsdata[0].decode("utf-8"),0):
|
||||
|
||||
os.remove(indir)
|
||||
if os.path.exists(indir):
|
||||
httpserver.websockfsstr(new_client_socket,("b " + "Delete old file ERROR" + '\r\n').encode("utf-8"))
|
||||
else:
|
||||
httpserver.websockfsstr(new_client_socket,("b " + "OK" + '\r\n').encode("utf-8"))
|
||||
else:
|
||||
httpserver.websockfsstr(new_client_socket,("b " + "SQL Delet error" + '\r\n').encode("utf-8"))
|
||||
else:
|
||||
httpserver.websockfsstr(new_client_socket,("b " + "SQL write error" + '\r\n').encode("utf-8"))
|
||||
|
||||
|
||||
def cpcp(new_client_socket,httpserver,sql,file,outdata,outdir):
|
||||
'''
|
||||
复制文件
|
||||
:param new_client_socket: socket
|
||||
:param httpserver: httpserver
|
||||
:param sql: sql
|
||||
:param file_name: 文件
|
||||
:param outdata: 目录
|
||||
:return: md5值
|
||||
'''
|
||||
#print()
|
||||
import time
|
||||
if os.path.exists(outdata[0].decode('utf-8') + "/" + outdata[1].decode('utf-8') + '/' + outdir[1].decode('utf-8') + '') == False:
|
||||
name = outdir[1].decode('utf-8').split('/')
|
||||
for nnnnnnn in name[1:]:
|
||||
if os.path.exists(outdata[0].decode('utf-8') + "/" + outdata[1].decode('utf-8') + '/' + name[0] + '') == False:
|
||||
os.mkdir(outdata[0].decode('utf-8') + "/" + outdata[1].decode('utf-8') + '/' + name[0] + '')
|
||||
name[0] = name[0] + '/' + nnnnnnn
|
||||
name = name[0]
|
||||
if os.path.exists(outdata[0].decode('utf-8') + "/" + outdata[1].decode('utf-8') + '/' + outdir[1].decode('utf-8') + '') == False:
|
||||
os.mkdir(outdata[0].decode('utf-8') + "/" + outdata[1].decode('utf-8') + '/' + outdir[1].decode('utf-8') + '')
|
||||
cpsize = 1024 * 1024 * 1
|
||||
size = os.stat(file).st_size
|
||||
wsize=0
|
||||
cptt = '--s '
|
||||
cpsd = 0
|
||||
cptemp = 0
|
||||
cptime = time.strftime("%S", time.localtime())
|
||||
ramall = ""
|
||||
if size < 1024:
|
||||
ramall = str(size)[:4] + "B"
|
||||
elif size < (1024 * 1024):
|
||||
ramall = str(size / 1024)[:4] + "KB"
|
||||
elif size < (1024 * 1024 * 1024):
|
||||
ramall = str(size / 1024 / 1024)[:4] + "MB"
|
||||
elif size < (1024 * 1024 * 1024 * 1024):
|
||||
ramall = str(size / 1024 / 1024 / 1024)[:4] + "GB"
|
||||
#m = hashlib.md5() #创建md5对象
|
||||
res = "cp " + ramall + ' <br>'
|
||||
res = res + str(wsize) + ' / ' + str(size) + ' <br>'
|
||||
res = res + 'percent: {:.2%}'.format(wsize/size) + ' <br>'
|
||||
res = res + cptt
|
||||
cpsd += cptemp
|
||||
httpserver.websockfsstr(new_client_socket,("b " + res + '\r\n').encode("utf-8"))
|
||||
fsw = open(outdata[0].decode('utf-8') + "/" + outdata[1].decode('utf-8') + '/' + outdir[1].decode('utf-8') + '/' + file.split("/")[-1],'wb')
|
||||
with open(file,'rb') as fobj:
|
||||
while True:
|
||||
data = fobj.read(cpsize)
|
||||
wsize = wsize + len(data)
|
||||
cpsd += len(data)
|
||||
if cptime != time.strftime("%S", time.localtime()):
|
||||
cptime = time.strftime("%S", time.localtime())
|
||||
res = "cp " + ramall + ' <br>'
|
||||
res = res + str(wsize) + ' / ' + str(size) + ' <br>'
|
||||
res = res + 'percent: {:.2%}'.format(wsize/size) + ' <br>'
|
||||
res = res + cptt
|
||||
if cpsd != 0:
|
||||
cpss = (size - wsize) // cpsd
|
||||
else:
|
||||
cpss = 0
|
||||
cpttk = len(cptt)
|
||||
if cpss < 60:
|
||||
cptt = str(cpss)
|
||||
cptt += 's '
|
||||
elif cpss < 3600:
|
||||
cptt = str(cpss // 60)
|
||||
cptt += 'm'
|
||||
cptt += str(cpss % 60)
|
||||
cptt += 's '
|
||||
else:
|
||||
cptt = str(cpss // 3600)
|
||||
cptt += 'h'
|
||||
cptt += str((cpss % 3600) // 60)
|
||||
cptt += 'm'
|
||||
cptt += str(cpss % 60)
|
||||
cptt += 's '
|
||||
if len(cptt) < cpttk:
|
||||
cpttk = cpttk - len(cptt)
|
||||
else:
|
||||
cpttk = 0
|
||||
if cpsd < 1024:
|
||||
cpsdB = str(cpsd)[:6] + "B"
|
||||
elif cpsd < (1024 * 1024):
|
||||
cpsdB = str(cpsd / 1024)[:6] + "KB"
|
||||
elif cpsd < (1024 * 1024 * 1024):
|
||||
cpsdB = str(cpsd / 1024 / 1024)[:6] + "MB"
|
||||
elif cpsd < (1024 * 1024 * 1024 * 1024):
|
||||
cpsdB = str(cpsd / 1024 / 1024 / 1024)[:6] + "GB"
|
||||
cpsd = 0
|
||||
res += cpsdB
|
||||
res += '/s'
|
||||
cpttrun = cpttk
|
||||
while cpttrun != 0:
|
||||
res += ' '
|
||||
cpttrun = cpttrun - 1
|
||||
httpserver.websockfsstr(new_client_socket,("b " + res + '\r\n').encode("utf-8"))
|
||||
if not data:
|
||||
res = "cp " + ramall + ' <br>'
|
||||
res = res + str(wsize) + ' / ' + str(size) + ' <br>'
|
||||
res = res + 'percent: {:.2%}'.format(wsize/size) + ' <br>'
|
||||
res = res + cptt
|
||||
if cpsd != 0:
|
||||
cpss = (size - wsize) // cpsd
|
||||
else:
|
||||
cpss = 0
|
||||
cpttk = len(cptt)
|
||||
if cpss < 60:
|
||||
cptt = str(cpss)
|
||||
cptt += 's '
|
||||
elif cpss < 3600:
|
||||
cptt = str(cpss // 60)
|
||||
cptt += 'm'
|
||||
cptt += str(cpss % 60)
|
||||
cptt += 's '
|
||||
else:
|
||||
cptt = str(cpss // 3600)
|
||||
cptt += 'h'
|
||||
cptt += str((cpss % 3600) // 60)
|
||||
cptt += 'm'
|
||||
cptt += str(cpss % 60)
|
||||
cptt += 's '
|
||||
if len(cptt) < cpttk:
|
||||
cpttk = cpttk - len(cptt)
|
||||
else:
|
||||
cpttk = 0
|
||||
if cpsd < 1024:
|
||||
cpsdB = str(cpsd)[:6] + "B"
|
||||
elif cpsd < (1024 * 1024):
|
||||
cpsdB = str(cpsd / 1024)[:6] + "KB"
|
||||
elif cpsd < (1024 * 1024 * 1024):
|
||||
cpsdB = str(cpsd / 1024 / 1024)[:6] + "MB"
|
||||
elif cpsd < (1024 * 1024 * 1024 * 1024):
|
||||
cpsdB = str(cpsd / 1024 / 1024 / 1024)[:6] + "GB"
|
||||
cpsd = 0
|
||||
res += cpsdB
|
||||
res += '/s'
|
||||
cpttrun = cpttk
|
||||
while cpttrun != 0:
|
||||
res += ' '
|
||||
cpttrun = cpttrun - 1
|
||||
httpserver.websockfsstr(new_client_socket,("b " + res + '\r\n').encode("utf-8"))
|
||||
break
|
||||
#m.update(data) #更新md5对象
|
||||
fsw.write(data)
|
||||
fsw.close()
|
||||
|
||||
|
||||
def get_file_md5(new_client_socket,httpserver,sql,file_name,md5text):
|
||||
'''
|
||||
计算文件的md5
|
||||
:param new_client_socket: socket
|
||||
:param httpserver: httpserver
|
||||
:param sql: sql
|
||||
:param file_name: 文件
|
||||
:return: md5值
|
||||
'''
|
||||
import time
|
||||
import hashlib
|
||||
cpsize = 1024 * 1024 * 1
|
||||
size = os.stat(file_name).st_size
|
||||
wsize=0
|
||||
cptt = '--s '
|
||||
cpsd = 0
|
||||
cptemp = 0
|
||||
cptime = time.strftime("%S", time.localtime())
|
||||
ramall = ""
|
||||
if size < 1024:
|
||||
ramall = str(size)[:4] + "B"
|
||||
elif size < (1024 * 1024):
|
||||
ramall = str(size / 1024)[:4] + "KB"
|
||||
elif size < (1024 * 1024 * 1024):
|
||||
ramall = str(size / 1024 / 1024)[:4] + "MB"
|
||||
elif size < (1024 * 1024 * 1024 * 1024):
|
||||
ramall = str(size / 1024 / 1024 / 1024)[:4] + "GB"
|
||||
m = hashlib.md5() #创建md5对象
|
||||
res = md5text + " " + ramall + ' <br>'
|
||||
res = res + str(wsize) + ' / ' + str(size) + ' <br>'
|
||||
res = res + 'percent: {:.2%}'.format(wsize/size) + ' <br>'
|
||||
res = res + cptt
|
||||
cpsd += cptemp
|
||||
httpserver.websockfsstr(new_client_socket,("b " + res + '\r\n').encode("utf-8"))
|
||||
with open(file_name,'rb') as fobj:
|
||||
while True:
|
||||
data = fobj.read(cpsize)
|
||||
wsize = wsize + len(data)
|
||||
cpsd += len(data)
|
||||
if cptime != time.strftime("%S", time.localtime()):
|
||||
cptime = time.strftime("%S", time.localtime())
|
||||
res = md5text + " " + ramall + ' <br>'
|
||||
res = res + str(wsize) + ' / ' + str(size) + ' <br>'
|
||||
res = res + 'percent: {:.2%}'.format(wsize/size) + ' <br>'
|
||||
res = res + cptt
|
||||
if cpsd != 0:
|
||||
cpss = (size - wsize) // cpsd
|
||||
else:
|
||||
cpss = 0
|
||||
cpttk = len(cptt)
|
||||
if cpss < 60:
|
||||
cptt = str(cpss)
|
||||
cptt += 's '
|
||||
elif cpss < 3600:
|
||||
cptt = str(cpss // 60)
|
||||
cptt += 'm'
|
||||
cptt += str(cpss % 60)
|
||||
cptt += 's '
|
||||
else:
|
||||
cptt = str(cpss // 3600)
|
||||
cptt += 'h'
|
||||
cptt += str((cpss % 3600) // 60)
|
||||
cptt += 'm'
|
||||
cptt += str(cpss % 60)
|
||||
cptt += 's '
|
||||
if len(cptt) < cpttk:
|
||||
cpttk = cpttk - len(cptt)
|
||||
else:
|
||||
cpttk = 0
|
||||
if cpsd < 1024:
|
||||
cpsdB = str(cpsd)[:6] + "B"
|
||||
elif cpsd < (1024 * 1024):
|
||||
cpsdB = str(cpsd / 1024)[:6] + "KB"
|
||||
elif cpsd < (1024 * 1024 * 1024):
|
||||
cpsdB = str(cpsd / 1024 / 1024)[:6] + "MB"
|
||||
elif cpsd < (1024 * 1024 * 1024 * 1024):
|
||||
cpsdB = str(cpsd / 1024 / 1024 / 1024)[:6] + "GB"
|
||||
cpsd = 0
|
||||
res += cpsdB
|
||||
res += '/s'
|
||||
cpttrun = cpttk
|
||||
while cpttrun != 0:
|
||||
res += ' '
|
||||
cpttrun = cpttrun - 1
|
||||
httpserver.websockfsstr(new_client_socket,("b " + res + '\r\n').encode("utf-8"))
|
||||
if not data:
|
||||
res = md5text + " " + ramall + ' <br>'
|
||||
res = res + str(wsize) + ' / ' + str(size) + ' <br>'
|
||||
res = res + 'percent: {:.2%}'.format(wsize/size) + ' <br>'
|
||||
res = res + cptt
|
||||
if cpsd != 0:
|
||||
cpss = (size - wsize) // cpsd
|
||||
else:
|
||||
cpss = 0
|
||||
cpttk = len(cptt)
|
||||
if cpss < 60:
|
||||
cptt = str(cpss)
|
||||
cptt += 's '
|
||||
elif cpss < 3600:
|
||||
cptt = str(cpss // 60)
|
||||
cptt += 'm'
|
||||
cptt += str(cpss % 60)
|
||||
cptt += 's '
|
||||
else:
|
||||
cptt = str(cpss // 3600)
|
||||
cptt += 'h'
|
||||
cptt += str((cpss % 3600) // 60)
|
||||
cptt += 'm'
|
||||
cptt += str(cpss % 60)
|
||||
cptt += 's '
|
||||
if len(cptt) < cpttk:
|
||||
cpttk = cpttk - len(cptt)
|
||||
else:
|
||||
cpttk = 0
|
||||
if cpsd < 1024:
|
||||
cpsdB = str(cpsd)[:6] + "B"
|
||||
elif cpsd < (1024 * 1024):
|
||||
cpsdB = str(cpsd / 1024)[:6] + "KB"
|
||||
elif cpsd < (1024 * 1024 * 1024):
|
||||
cpsdB = str(cpsd / 1024 / 1024)[:6] + "MB"
|
||||
elif cpsd < (1024 * 1024 * 1024 * 1024):
|
||||
cpsdB = str(cpsd / 1024 / 1024 / 1024)[:6] + "GB"
|
||||
cpsd = 0
|
||||
res += cpsdB
|
||||
res += '/s'
|
||||
cpttrun = cpttk
|
||||
while cpttrun != 0:
|
||||
res += ' '
|
||||
cpttrun = cpttrun - 1
|
||||
httpserver.websockfsstr(new_client_socket,("b " + res + '\r\n').encode("utf-8"))
|
||||
break
|
||||
m.update(data) #更新md5对象
|
||||
return m.hexdigest() #返回md5对象
|
||||
|
||||
def run(new_client_socket,httpserver,sql):
|
||||
sys.setrecursionlimit(3000)
|
||||
#forxh = 0
|
||||
for i in sql.catall(".config/filenocopy/indir.db"):
|
||||
i = i.split(b'\t')
|
||||
runn(new_client_socket,httpserver,sql,i,'')
|
||||
|
||||
def main(new_client_socket,RUL_CS,post_data,Headers,info,user):
|
||||
httpserver = imp.load_source("server/main/httpserver.py","server/main/httpserver.py")
|
||||
sql = imp.load_source("server/main/filesql.py","server/main/filesql.py")
|
||||
httpserver.websockinit(new_client_socket,Headers,info)
|
||||
|
||||
#data = httpserver.websockrx(new_client_socket)
|
||||
#data = httpserver.websockrx(new_client_socket)
|
||||
|
||||
#httpserver.websockfsstr(new_client_socket,b'6')
|
||||
run(new_client_socket,httpserver,sql)
|
||||
|
||||
httpserver.websockendstr(new_client_socket,b"END\r\n")
|
||||
|
||||
def get_free_space_mb(folder):
|
||||
import platform
|
||||
import ctypes
|
||||
import os
|
||||
"""
|
||||
获取磁盘剩余空间
|
||||
:param folder: 磁盘路径 例如 D:\\
|
||||
:return: 剩余空间 单位 G
|
||||
"""
|
||||
if platform.system() == 'Windows':
|
||||
free_bytes = ctypes.c_ulonglong(0)
|
||||
ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(folder), None, None, ctypes.pointer(free_bytes))
|
||||
return free_bytes.value / 1024 / 1024
|
||||
else:
|
||||
st = os.statvfs(folder)
|
||||
return st.f_bavail * st.f_frsize / 1024 / 1024
|
||||
39
server/filedispose/filenocopy/add/api.py
Normal file
39
server/filedispose/filenocopy/add/api.py
Normal file
@@ -0,0 +1,39 @@
|
||||
# coding=utf-8
|
||||
#!/bin/python
|
||||
|
||||
import imp
|
||||
import os
|
||||
|
||||
def main(new_client_socket,RUL_CS,post_data,Headers,info,user):
|
||||
httpserver = imp.load_source("server/main/httpserver.py","server/main/httpserver.py")
|
||||
sql = imp.load_source("server/main/filesql.py","server/main/filesql.py")
|
||||
import json
|
||||
post_data = post_data.decode("utf-8")
|
||||
post_data = json.loads(post_data,strict=False)
|
||||
dir = post_data["dir"]
|
||||
name = post_data["name"]
|
||||
id = post_data["id"]
|
||||
json = '{"id":"' + id + '",'
|
||||
|
||||
if name == "":
|
||||
json += '"data":"名称呢"'
|
||||
else:
|
||||
if not os.path.exists(".config/filenocopy"):
|
||||
os.mkdir(".config/filenocopy")
|
||||
if not os.path.exists(".config/filenocopy/temp.db"):
|
||||
data = {}
|
||||
data["name"] = "name"
|
||||
data["dir"] = "dir"
|
||||
sql.new(".config/filenocopy/temp.db",data)
|
||||
fo = sql.catlen(".config/filenocopy/temp.db")
|
||||
fsdata = sql.cat(".config/filenocopy/temp.db",name,0)
|
||||
if not fsdata:
|
||||
data = {}
|
||||
data["name"] = name
|
||||
data["dir"] = dir
|
||||
sql.prin(".config/filenocopy/temp.db",data)
|
||||
json += '"data":"添加成功"'
|
||||
else:
|
||||
json += '"data":"已存在"'
|
||||
json += "}"
|
||||
httpserver.httppostchar(new_client_socket,"200",json.encode('utf-8'),"text/html;charset=UTF-8",Headers,info)
|
||||
52
server/filedispose/filenocopy/api.py
Normal file
52
server/filedispose/filenocopy/api.py
Normal file
@@ -0,0 +1,52 @@
|
||||
# coding=utf-8
|
||||
#!/bin/python
|
||||
|
||||
import imp
|
||||
import os
|
||||
import sys
|
||||
|
||||
def runn(new_client_socket,httpserver,sql,x,indir):
|
||||
dirn = os.listdir(x[0].decode('utf-8') + indir)
|
||||
dirn.sort(reverse=False)
|
||||
for i in dirn:
|
||||
dir = x[0].decode('utf-8') + indir + '/' + i
|
||||
if os.path.isdir(dir):
|
||||
httpserver.websockfsstr(new_client_socket,('d ' + x[1].decode('utf-8') + indir + '/' + i + '\r\n').encode("utf-8"))
|
||||
runn(new_client_socket,httpserver,sql,x,indir + '/' + i)
|
||||
else:
|
||||
fsdata = sql.cat(".config/filenocopy/data.db",i,0)
|
||||
if not fsdata:
|
||||
fsdata = sql.cat(".config/filenocopy/temp.db",i,0)
|
||||
if not fsdata:
|
||||
addr = sql.cat(".config/filenocopy/default.db",i.split('.')[-1],0)
|
||||
if not addr:
|
||||
addr = indir[1:]
|
||||
else:
|
||||
addr = addr[1].decode('utf-8')
|
||||
httpserver.websockfsstr(new_client_socket,('n ' + x[1].decode('utf-8') + indir + '/' + i + '\t' + addr + '\t' + i + '\r\n').encode("utf-8"))
|
||||
else:
|
||||
httpserver.websockfsstr(new_client_socket,('f ' + x[1].decode('utf-8') + indir + '/' + i + '\t' + fsdata[1].decode('utf-8') + '\t' + i + '\r\n').encode("utf-8"))
|
||||
else:
|
||||
httpserver.websockfsstr(new_client_socket,('f ' + x[1].decode('utf-8') + indir + '/' + i + '\t' + fsdata[1].decode('utf-8') + '\t' + i + '\r\n').encode("utf-8"))
|
||||
|
||||
forxh = 0
|
||||
def run(new_client_socket,httpserver,sql):
|
||||
sys.setrecursionlimit(3000)
|
||||
#forxh = 0
|
||||
for i in sql.catall(".config/filenocopy/indir.db"):
|
||||
i = i.split(b'\t')
|
||||
runn(new_client_socket,httpserver,sql,i,'')
|
||||
|
||||
def main(new_client_socket,RUL_CS,post_data,Headers,info,user):
|
||||
httpserver = imp.load_source("server/main/httpserver.py","server/main/httpserver.py")
|
||||
sql = imp.load_source("server/main/filesql.py","server/main/filesql.py")
|
||||
httpserver.websockinit(new_client_socket,Headers,info)
|
||||
|
||||
data = sql.catlen(".config/filenocopy/disk.db")
|
||||
#data = httpserver.websockrx(new_client_socket)
|
||||
#data = httpserver.websockrx(new_client_socket)
|
||||
|
||||
#httpserver.websockfsstr(new_client_socket,b'6')
|
||||
run(new_client_socket,httpserver,sql)
|
||||
|
||||
httpserver.websockendstr(new_client_socket,b"END\r\n")
|
||||
38
server/filedispose/indir/add/api.py
Normal file
38
server/filedispose/indir/add/api.py
Normal file
@@ -0,0 +1,38 @@
|
||||
# coding=utf-8
|
||||
#!/bin/python
|
||||
|
||||
import imp
|
||||
import os
|
||||
|
||||
def main(new_client_socket,RUL_CS,post_data,Headers,info,user):
|
||||
httpserver = imp.load_source("server/main/httpserver.py","server/main/httpserver.py")
|
||||
sql = imp.load_source("server/main/filesql.py","server/main/filesql.py")
|
||||
|
||||
dir = ''
|
||||
post = RUL_CS
|
||||
for i in post:
|
||||
tmp = i.split('=')
|
||||
if tmp[0] == 'dir':
|
||||
dir = tmp[1]
|
||||
|
||||
json = ''
|
||||
if os.path.exists(dir):
|
||||
if not os.path.exists(".config/filenocopy"):
|
||||
os.mkdir(".config/filenocopy")
|
||||
if not os.path.exists(".config/filenocopy/indir.db"):
|
||||
data = {}
|
||||
data["dir"] = "dir"
|
||||
sql.new(".config/filenocopy/indir.db",data)
|
||||
fo = sql.catlen(".config/filenocopy/indir.db")
|
||||
fsdata = sql.cat(".config/filenocopy/indir.db",dir,0)
|
||||
if not fsdata:
|
||||
data = {}
|
||||
data["dir"] = dir
|
||||
sql.prin(".config/filenocopy/indir.db",data)
|
||||
json = '添加成功'
|
||||
else:
|
||||
json = '目录已添加'
|
||||
else:
|
||||
json = '目录不存在'
|
||||
|
||||
httpserver.httppostchar(new_client_socket,"200",json.encode('utf-8'),"text/html;charset=UTF-8",Headers,info)
|
||||
22
server/filedispose/indir/info/api.py
Normal file
22
server/filedispose/indir/info/api.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# coding=utf-8
|
||||
#!/bin/python
|
||||
|
||||
import imp
|
||||
import os
|
||||
|
||||
def main(new_client_socket,RUL_CS,post_data,Headers,info,user):
|
||||
httpserver = imp.load_source("server/main/httpserver.py","server/main/httpserver.py")
|
||||
sql = imp.load_source("server/main/filesql.py","server/main/filesql.py")
|
||||
|
||||
json = ''
|
||||
fo = sql.catlen(".config/filenocopy/indir.db")
|
||||
|
||||
json += '{"fo":' + str(fo) + ',"data":['
|
||||
for i in sql.catall(".config/filenocopy/indir.db"):
|
||||
i = i.split(b'\t')
|
||||
if os.path.exists(i[0].decode("utf-8")):
|
||||
json += '{"dir":"' + i[0].decode("utf-8") + '","status":"正常"},'
|
||||
else:
|
||||
json += '{"dir":"' + i[0].decode("utf-8") + '","status":"No Dir"},'
|
||||
json += '{}]}'
|
||||
httpserver.httppostchar(new_client_socket,"200",json.encode('utf-8'),"application/json",Headers,info)
|
||||
58
server/filedispose/outdir/add/api.py
Normal file
58
server/filedispose/outdir/add/api.py
Normal file
@@ -0,0 +1,58 @@
|
||||
# coding=utf-8
|
||||
#!/bin/python
|
||||
|
||||
import imp
|
||||
import os
|
||||
|
||||
def main(new_client_socket,RUL_CS,post_data,Headers,info,user):
|
||||
httpserver = imp.load_source("server/main/httpserver.py","server/main/httpserver.py")
|
||||
sql = imp.load_source("server/main/filesql.py","server/main/filesql.py")
|
||||
|
||||
dir = ''
|
||||
name = ''
|
||||
post = RUL_CS
|
||||
for i in post:
|
||||
tmp = i.split('=')
|
||||
if tmp[0] == 'dir':
|
||||
dir = tmp[1]
|
||||
if tmp[0] == 'name':
|
||||
name = tmp[1]
|
||||
|
||||
if name == "":
|
||||
name = dir.split('/')[-1]
|
||||
|
||||
json = ''
|
||||
if os.path.exists(dir):
|
||||
if not os.path.exists(".config/filenocopy"):
|
||||
os.mkdir(".config/filenocopy")
|
||||
if not os.path.exists(".config/filenocopy/outdir.db"):
|
||||
data = {}
|
||||
data["dir"] = "dir"
|
||||
data["name"] = "name"
|
||||
sql.new(".config/filenocopy/outdir.db",data)
|
||||
fo = sql.catlen(".config/filenocopy/outdir.db")
|
||||
fsdata = sql.cat(".config/filenocopy/outdir.db",dir,0)
|
||||
if not fsdata:
|
||||
if not os.path.exists(dir + "/" + name):
|
||||
if not os.path.exists(dir + "/" + name + ".db"):
|
||||
data = {}
|
||||
data["dir"] = "dir"
|
||||
data["name"] = "name"
|
||||
sql.new(dir + "/" + name + ".db",data)
|
||||
data = {}
|
||||
data["dir"] = dir
|
||||
data["name"] = name
|
||||
sql.prin(".config/filenocopy/outdir.db",data)
|
||||
sql.prin(dir + "/" + name + ".db",data)
|
||||
os.mkdir(dir + "/" + name)
|
||||
json = '添加成功'
|
||||
else:
|
||||
json = '存在数据库文件'
|
||||
else:
|
||||
json = '目录非空'
|
||||
else:
|
||||
json = '目录已添加'
|
||||
else:
|
||||
json = '目录不存在'
|
||||
|
||||
httpserver.httppostchar(new_client_socket,"200",json.encode('utf-8'),"text/html;charset=UTF-8",Headers,info)
|
||||
73
server/filedispose/outdir/info/api.py
Normal file
73
server/filedispose/outdir/info/api.py
Normal file
@@ -0,0 +1,73 @@
|
||||
# coding=utf-8
|
||||
#!/bin/python
|
||||
|
||||
import imp
|
||||
import os
|
||||
import psutil
|
||||
|
||||
def main(new_client_socket,RUL_CS,post_data,Headers,info,user):
|
||||
httpserver = imp.load_source("server/main/httpserver.py","server/main/httpserver.py")
|
||||
sql = imp.load_source("server/main/filesql.py","server/main/filesql.py")
|
||||
|
||||
json = ''
|
||||
fo = sql.catlen(".config/filenocopy/outdir.db")
|
||||
|
||||
json += '{"fo":' + str(fo) + ',"data":['
|
||||
for i in sql.catall(".config/filenocopy/outdir.db"):
|
||||
i = i.split(b'\t')
|
||||
if os.path.exists(i[0].decode("utf-8")):
|
||||
size = get_free_space_mb(i[0].decode("utf-8"))
|
||||
if size > 10000:
|
||||
size = size / 1000
|
||||
size = str(size).split('.')
|
||||
if len(size) == 1:
|
||||
size = size[0] + '.' + "00G"
|
||||
else:
|
||||
size = size[0] + '.' + size[1][:4] + "G"
|
||||
else:
|
||||
size = str(size).split('.')
|
||||
if len(size) == 1:
|
||||
size = size[0] + '.' + "00M"
|
||||
else:
|
||||
size = size[0] + '.' + size[1][:4] + "M"
|
||||
disk = psutil.disk_usage(i[0].decode("utf-8")).total
|
||||
disk = disk / 1000
|
||||
disk = disk / 1000
|
||||
if disk > 10000:
|
||||
disk = disk / 1000
|
||||
disk = str(disk).split('.')
|
||||
if len(disk) == 1:
|
||||
disk = disk[0] + '.' + "00G"
|
||||
else:
|
||||
disk = disk[0] + '.' + disk[1][:4] + "G"
|
||||
else:
|
||||
disk = str(disk).split('.')
|
||||
if len(disk) == 1:
|
||||
disk = disk[0] + '.' + "00M"
|
||||
else:
|
||||
disk = disk[0] + '.' + disk[1][:4] + "M"
|
||||
if os.path.exists(i[0].decode("utf-8") + '/' + i[1].decode("utf-8") + '.db'):
|
||||
json += '{"dir":"' + i[0].decode("utf-8") + '","name":"' + i[1].decode("utf-8") +'","Size":"' + disk + ' / ' + size + '","status":"正常"},'
|
||||
else:
|
||||
json += '{"dir":"' + i[0].decode("utf-8") + '","name":"' + i[1].decode("utf-8") +'","Size":"' + disk + ' / ' + size + '","status":"数据库不见了"},'
|
||||
else:
|
||||
json += '{"dir":"' + i[0].decode("utf-8") + '","name":"' + i[1].decode("utf-8") +'","Size":"ERR","status":"No Dir"},'
|
||||
json += '{}]}'
|
||||
httpserver.httppostchar(new_client_socket,"200",json.encode('utf-8'),"application/json",Headers,info)
|
||||
|
||||
def get_free_space_mb(folder):
|
||||
import platform
|
||||
import ctypes
|
||||
import os
|
||||
"""
|
||||
获取磁盘剩余空间
|
||||
:param folder: 磁盘路径 例如 D:\\
|
||||
:return: 剩余空间 单位 G
|
||||
"""
|
||||
if platform.system() == 'Windows':
|
||||
free_bytes = ctypes.c_ulonglong(0)
|
||||
ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(folder), None, None, ctypes.pointer(free_bytes))
|
||||
return free_bytes.value / 1024 / 1024
|
||||
else:
|
||||
st = os.statvfs(folder)
|
||||
return st.f_bavail * st.f_frsize / 1024 / 1024
|
||||
Reference in New Issue
Block a user