Skip to content

Instantly share code, notes, and snippets.

@allrobot
Created April 14, 2023 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allrobot/14be27794f8a9cd7dd08de40a3e443e9 to your computer and use it in GitHub Desktop.
Save allrobot/14be27794f8a9cd7dd08de40a3e443e9 to your computer and use it in GitHub Desktop.
import datetime, ujson as json, os, re, traceback, zipfile, Script
import time
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from ujson import JSONDecodeError
from Vam_Dialogs import InterruptDialog
class Worker(QThread):
intReady = pyqtSignal(int)
showdialog = pyqtSignal(str)
finished = pyqtSignal()
# 定义变量集合
def __init__(self, script_path):
super(Worker, self).__init__()
# 初始化
self.error_text = ''
# self.searched_vars_name = set() # 存放已从meta.json依赖搜索过的依赖包名
self.current_path=os.path.realpath('.')
os.chdir(script_path)
# 获取文件名
self.exist_vars_path = Script.get_vars_path()
self.exist_vars = Script.get_vars_name()
self.exist_vars_full = Script.get_full_vars_name()
self.vars_dict = Script.get_vars_path_dict()
# 报错状态
self.error = False
self.CurrentFiles = 0
self.isPause = False
self.ignored=False
self.condition = QWaitCondition()
self.mutex = QMutex()
def pause(self):
self.isPause = True
def ignore(self):
self.ignored=True
def resume(self):
self.isPause = False
self.condition.wakeAll()
def scan_meta_json(self) -> None:
num=0
for file in self.exist_vars_path:
self.intReady.emit(self.CurrentFiles)
num+=1
# 上锁
self.mutex.lock()
if num==500:
self.error = True
self.error_text = f'AddonPackages{file[1:]}\n\n文件执行权限获取失败。\n\n请确认文件是否被系统占用。\n\n如果已关闭文件,点击返回继续处理操作任务。'
self.showdialog.emit(self.error_text)
if self.isPause:
self.condition.wait(self.mutex)
self.CurrentFiles += 1
print(file)
# 创建一个1秒的定时器
timer = QTimer()
timer.setSingleShot(True)
timer.start(1)
# 创建一个事件循环,并等待定时器超时
loop = QEventLoop()
timer.timeout.connect(loop.quit)
loop.exec()
self.mutex.unlock()
os.chdir(self.current_path)
self.finished.emit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment