程序优化

This commit is contained in:
dongchangxi committed 2023-11-20 10:53:38 +08:00
1 parent 2093ff5526
commit 10640a63c2
8 files changed
+260 -44

No files matched your search

+26 -4
View File
@@ -1,4 +1,4 @@
import redis,sys,os,re,oss2
import redis,sys,os,re,oss2,shutil,time
import platform
import xml.etree.ElementTree as ET
from PIL import ImageGrab
@@ -223,7 +223,29 @@ def uploadControlPointsOss(pid):
#截屏保存
def saveScreenImg(pid):
#获取当前的日志
if not os.path.exists(os.path.join("D:/screen/",time.strftime("%y-%m-%d", time.localtime()))):
os.makedirs(os.path.join("D:/screen/",time.strftime("%Y-%m-%d", time.localtime())))
if not os.path.exists(os.path.join(config.workdir,"screen", time.strftime("%y%m%d" time.localtime()))):
os.makedirs(os.path.join(config.workdir,"screen", time.strftime("%y%m%d" time.localtime())))
screenshot = ImageGrab .grab()
screenshot.save(os.path.join("D:/screen/",time.strftime("%Y-%-%d'time .localtime()"),str(pid)+".png"))
screenshot.save(os.path.join(config.workdir,"screen", time.strftime("%y%m%d" time.localtime())),str(pid)+".png")
#移动到e盘
if not os.path.exists(os.path.join(config.sharedir,"screen", time.strftime("%y%m%d" time.localtime()))):
os.makedirs(os.path.join(config.sharedir,"screen", time.strftime("%y%m%d" time.localtime())))
shutil.copytree(os.path.join(config.workdir,"screen", time.strftime("%y%m%d" time.localtime())), os.path.join(config.sharedir,"screen", time.strftime("%y%m%d" time.localtime())))
#文件夹的移动和删除
def removeFolder(pid):
#判断是否存在finished文件夹,没有则创建
if not os.path.exists(os.path.join(config.workdir, 'finished')):
os.makedirs(os.path.join(config.workdir, 'finished'))
#移动文件夹到指定路径,如果已经存在了就删除再移动
if os.path.exists(os.path.join(config.workdir, 'finished', pid)):
shutil.rmtree(os.path.join(config.workdir, 'finished', pid), ignore_errors=True)
shutil.move(os.path.join(config.workdir, pid), os.path.join(config.workdir, 'finished'))
#遍历finished 里的文件夹,超过三天的就都删除
for file in os.listdir(os.path.join(config.workdir, 'finished')):
if os.path.isdir(os.path.join(config.workdir, 'finished', file)):
file_time = os.path.getmtime(os.path.join(config.workdir, 'finished', file))
now_time = time.time()
if (now_time - file_time) > 259200:
shutil.rmtree(os.path.join(config.workdir, 'finished', file), ignore_errors=True)
+3 -1
View File
@@ -183,9 +183,11 @@ def down_obj_from_oss(workdir, pid, action):
prefix = f'objs/{action}/{pid}/'
filelist = oss2.ObjectIteratorV2(config.oss_bucket, prefix=prefix)
print('正在下载:', prefix)
obj_filename = ""
for file in filelist:
filename = file.key.split('/')[-1]
if filename.endswith('.obj'): obj_filename = filename
if filename.endswith('.obj'):
obj_filename = filename
# print('正在下载:', file.key)
localfile = os.path.join(workdir, action, pid, filename)
config.oss_bucket.get_object_to_file(file.key, localfile)
+4 -4
View File
@@ -18,7 +18,7 @@ def get_task(task_type):
with pymysqlAlias() as conn:
cursor = conn.cursor()
sql = f'select task_key from tasks where task_type = "{task_type}" and status = 0 order by priority desc, id asc limit 1'
sql = f'select task_key from tasks where status = 0 order by priority desc, id asc limit 1'
# print(f'sql: {sql}')
cursor.execute(sql)
data = cursor.fetchone()
@@ -40,7 +40,7 @@ def add_task(data):
if data["psid"] == '85':
sql = f'insert into tasks (task_type, task_key,studio_id) values ("{data["task_type"]}", "{data["task_key"]}","{data["psid"]}")'
else:
sql = f'insert into tasks (task_type, task_key, priority,studio_id) values ("{data["task_type"]}", "{data["task_key"]}", 1,"{data["psid"]}")'
sql = f'insert into tasks (task_type, task_key, priority,studio_id) values ("{data["task_type"]}", "{data["task_key"]}", {data["priority"]},"{data["psid"]}")'
# print(f'sql: {sql}')
cursor.execute(sql)
conn.commit()
@@ -66,7 +66,7 @@ def start_task(data):
cursor = conn.cursor()
hostname = socket.gethostname()
sql = f'update tasks set status = 1, hostname = "{hostname}", started_at = now(), updated_at = now() where task_type = "{data["task_type"]}" and task_key = "{data["task_key"]}"'
sql = f'update tasks set status = 1, hostname = "{hostname}", started_at = now(), updated_at = now() where task_key = "{data["task_key"]} and status = 0"'
# print(f'sql: {sql}')
cursor.execute(sql)
conn.commit()
@@ -80,7 +80,7 @@ def finish_task(data):
cursor = conn.cursor()
hostname = socket.gethostname()
sql = f'update tasks set status = 2, hostname = "{hostname}", finished_at = now(), updated_at = now() where task_type = "{data["task_type"]}" and task_key = "{data["task_key"]}"'
sql = f'update tasks set status = 2, hostname = "{hostname}", finished_at = now(), updated_at = now() where status = 1 and task_key = "{data["task_key"]}" '
# print(f'sql: {sql}')
cursor.execute(sql)
conn.commit()