ryry-cli 2.100__tar.gz → 3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ryry_cli-2.100 → ryry_cli-3.0}/PKG-INFO +1 -1
- {ryry_cli-2.100 → ryry_cli-3.0}/ryry/constant.py +2 -2
- {ryry_cli-2.100 → ryry_cli-3.0}/ryry/ryry_service.py +17 -8
- {ryry_cli-2.100 → ryry_cli-3.0}/ryry/ryry_webapi.py +89 -2
- {ryry_cli-2.100 → ryry_cli-3.0}/ryry/server_func.py +17 -24
- {ryry_cli-2.100 → ryry_cli-3.0}/ryry/store.py +32 -18
- {ryry_cli-2.100 → ryry_cli-3.0}/ryry/task.py +9 -0
- {ryry_cli-2.100 → ryry_cli-3.0}/ryry/taskUtils.py +0 -12
- {ryry_cli-2.100 → ryry_cli-3.0}/ryry_cli.egg-info/PKG-INFO +1 -1
- {ryry_cli-2.100 → ryry_cli-3.0}/setup.py +1 -1
- {ryry_cli-2.100 → ryry_cli-3.0}/LICENSE +0 -0
- {ryry_cli-2.100 → ryry_cli-3.0}/README.md +0 -0
- {ryry_cli-2.100 → ryry_cli-3.0}/ryry/__init__.py +0 -0
- {ryry_cli-2.100 → ryry_cli-3.0}/ryry/main.py +0 -0
- {ryry_cli-2.100 → ryry_cli-3.0}/ryry/ryry_server_socket.py +0 -0
- {ryry_cli-2.100 → ryry_cli-3.0}/ryry/ryry_widget.py +0 -0
- {ryry_cli-2.100 → ryry_cli-3.0}/ryry/script_template/__init__.py +0 -0
- {ryry_cli-2.100 → ryry_cli-3.0}/ryry/script_template/main.py +0 -0
- {ryry_cli-2.100 → ryry_cli-3.0}/ryry/script_template/run.py +0 -0
- {ryry_cli-2.100 → ryry_cli-3.0}/ryry/upload.py +0 -0
- {ryry_cli-2.100 → ryry_cli-3.0}/ryry/utils.py +0 -0
- {ryry_cli-2.100 → ryry_cli-3.0}/ryry_cli.egg-info/SOURCES.txt +0 -0
- {ryry_cli-2.100 → ryry_cli-3.0}/ryry_cli.egg-info/dependency_links.txt +0 -0
- {ryry_cli-2.100 → ryry_cli-3.0}/ryry_cli.egg-info/entry_points.txt +0 -0
- {ryry_cli-2.100 → ryry_cli-3.0}/ryry_cli.egg-info/requires.txt +0 -0
- {ryry_cli-2.100 → ryry_cli-3.0}/ryry_cli.egg-info/top_level.txt +0 -0
- {ryry_cli-2.100 → ryry_cli-3.0}/setup.cfg +0 -0
|
@@ -139,15 +139,24 @@ class ryryStateThread(Thread):
|
|
|
139
139
|
if cnt >= (60*60) and cnt/(60*60)%1 <= self.tik_time/3600:
|
|
140
140
|
taskUtils.idlingNotify(cnt)
|
|
141
141
|
#clear trush
|
|
142
|
-
|
|
142
|
+
now = time.time()
|
|
143
|
+
threshold = 24 * 3600
|
|
144
|
+
for root, dirs, files in os.walk(constant.base_path):
|
|
143
145
|
for file in files:
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
146
|
+
full_path = os.path.join(root, file)
|
|
147
|
+
if (
|
|
148
|
+
file.endswith(".in") or
|
|
149
|
+
file.endswith(".out") or
|
|
150
|
+
file.startswith("local_")
|
|
151
|
+
):
|
|
152
|
+
# 检查文件是否超过 24 小时
|
|
153
|
+
mtime = os.path.getmtime(full_path)
|
|
154
|
+
if now - mtime > threshold:
|
|
155
|
+
try:
|
|
156
|
+
os.remove(full_path)
|
|
157
|
+
except Exception as e:
|
|
158
|
+
pass
|
|
159
|
+
break # 只处理当前目录,不递归子目录
|
|
151
160
|
#更新机器性能
|
|
152
161
|
store.writeDeviceInfo(utils.deviceInfo())
|
|
153
162
|
except:
|
|
@@ -3,7 +3,7 @@ import uuid, requests, calendar, time
|
|
|
3
3
|
from requests.adapters import HTTPAdapter
|
|
4
4
|
from urllib3.util.retry import Retry
|
|
5
5
|
|
|
6
|
-
from ryry import store, utils, taskUtils, constant
|
|
6
|
+
from ryry import store, utils, taskUtils, constant, task
|
|
7
7
|
|
|
8
8
|
def _domain_post(func, params, files={}, timeout=10, domain="api.dalipen.com"):
|
|
9
9
|
headers = {
|
|
@@ -49,6 +49,29 @@ def ServerTaskConfig():
|
|
|
49
49
|
return min_wait_time, max_wait_time, consecutive_step
|
|
50
50
|
|
|
51
51
|
def GetTask(widget_list):
|
|
52
|
+
all_files = set(os.listdir(constant.base_path))
|
|
53
|
+
if len(all_files) > 0:
|
|
54
|
+
for filename in all_files:
|
|
55
|
+
if filename.startswith("local_") and not filename.endswith(".result"):
|
|
56
|
+
result_filename = filename + ".result"
|
|
57
|
+
if result_filename in all_files:
|
|
58
|
+
continue # 有 .result 文件,跳过
|
|
59
|
+
file_path = os.path.join(constant.base_path, filename)
|
|
60
|
+
try:
|
|
61
|
+
with open(file_path, "r", encoding="utf-8") as f:
|
|
62
|
+
params = json.load(f)
|
|
63
|
+
|
|
64
|
+
config = params.get("config", {})
|
|
65
|
+
widget_id = config.get("widget_id")
|
|
66
|
+
if widget_id in widget_list:
|
|
67
|
+
return [{
|
|
68
|
+
"taskUUID": params.get("taskUUID", filename),
|
|
69
|
+
"config": json.dumps(config),
|
|
70
|
+
"data": params.get("data", {}),
|
|
71
|
+
"timeout": params.get("timeout", 600)
|
|
72
|
+
}]
|
|
73
|
+
except Exception as e:
|
|
74
|
+
continue
|
|
52
75
|
req = {
|
|
53
76
|
"widget_map": json.dumps(widget_list),
|
|
54
77
|
"limit": 1,
|
|
@@ -143,6 +166,15 @@ def retryLastTaskNotify():
|
|
|
143
166
|
pass
|
|
144
167
|
|
|
145
168
|
def TaskNotify(taskUUID, status, msg, dataStr, failSaveNotify=True):
|
|
169
|
+
if taskUUID.startswith("local_"):
|
|
170
|
+
with open(os.path.join(constant.base_path, taskUUID + ".result"), "w") as f:
|
|
171
|
+
json.dump( {
|
|
172
|
+
"finish": True,
|
|
173
|
+
"success": status,
|
|
174
|
+
"data": dataStr,
|
|
175
|
+
"progress": 100
|
|
176
|
+
}, f)
|
|
177
|
+
return True
|
|
146
178
|
req = {
|
|
147
179
|
"task_uuid": taskUUID,
|
|
148
180
|
"status": status,
|
|
@@ -158,6 +190,15 @@ def TaskNotify(taskUUID, status, msg, dataStr, failSaveNotify=True):
|
|
|
158
190
|
return r3
|
|
159
191
|
|
|
160
192
|
def TaskUpdateProgress(taskUUID, progress, dataStr):
|
|
193
|
+
if taskUUID.startswith("local_"):
|
|
194
|
+
with open(os.path.join(constant.base_path, taskUUID + ".result"), "w") as f:
|
|
195
|
+
json.dump( {
|
|
196
|
+
"finish": False,
|
|
197
|
+
"success": False,
|
|
198
|
+
"data": dataStr,
|
|
199
|
+
"progress": progress
|
|
200
|
+
}, f)
|
|
201
|
+
return True
|
|
161
202
|
req = {
|
|
162
203
|
"task_uuid": taskUUID,
|
|
163
204
|
"progress": progress,
|
|
@@ -168,6 +209,15 @@ def TaskUpdateProgress(taskUUID, progress, dataStr):
|
|
|
168
209
|
return True
|
|
169
210
|
|
|
170
211
|
def TaskCancel(taskUUID):
|
|
212
|
+
if taskUUID.startswith("local_"):
|
|
213
|
+
with open(os.path.join(constant.base_path, taskUUID + ".result"), "w") as f:
|
|
214
|
+
json.dump( {
|
|
215
|
+
"finish": True,
|
|
216
|
+
"success": False,
|
|
217
|
+
"data": "",
|
|
218
|
+
"progress": 100
|
|
219
|
+
}, f)
|
|
220
|
+
return True
|
|
171
221
|
req = {
|
|
172
222
|
"task_uuid": taskUUID,
|
|
173
223
|
}
|
|
@@ -176,6 +226,14 @@ def TaskCancel(taskUUID):
|
|
|
176
226
|
return False
|
|
177
227
|
return True
|
|
178
228
|
|
|
229
|
+
def removeLocalTask(taskUUID):
|
|
230
|
+
if taskUUID.startswith("local_"):
|
|
231
|
+
if os.path.exists(os.path.join(constant.base_path, taskUUID)):
|
|
232
|
+
os.remove(os.path.join(constant.base_path, taskUUID))
|
|
233
|
+
if os.path.exists(os.path.join(constant.base_path, taskUUID + ".result")):
|
|
234
|
+
os.remove(os.path.join(constant.base_path, taskUUID + ".result"))
|
|
235
|
+
return True
|
|
236
|
+
|
|
179
237
|
def multiTaskCancel(checkUUIDs):
|
|
180
238
|
req = {
|
|
181
239
|
"task_uuids": checkUUIDs
|
|
@@ -264,6 +322,23 @@ def CreateWidgetUUID():
|
|
|
264
322
|
return r3
|
|
265
323
|
|
|
266
324
|
#======================================== Task Function ==============================
|
|
325
|
+
def createLocalTask(widget_name, params, timeout):
|
|
326
|
+
taskUUID = "local_" + ''.join(str(uuid.uuid4()).split('-'))
|
|
327
|
+
params["task_id"] = taskUUID
|
|
328
|
+
widget_id = task.widgetIDWithWidgetName(widget_name)
|
|
329
|
+
with open(os.path.join(constant.base_path, taskUUID), "w") as f:
|
|
330
|
+
[]
|
|
331
|
+
json.dump({
|
|
332
|
+
"taskUUID": taskUUID,
|
|
333
|
+
"config": {
|
|
334
|
+
"widget_id": widget_id
|
|
335
|
+
},
|
|
336
|
+
"data": json.dumps(params),
|
|
337
|
+
"timeout": timeout
|
|
338
|
+
}, f)
|
|
339
|
+
print(f"local task {taskUUID} is ready!")
|
|
340
|
+
return taskUUID
|
|
341
|
+
|
|
267
342
|
def createTask(widget_name, params):
|
|
268
343
|
req = {
|
|
269
344
|
"widget_name": widget_name,
|
|
@@ -273,6 +348,7 @@ def createTask(widget_name, params):
|
|
|
273
348
|
r1, r2, r3 = _aigc_post("aigc/task/createTask", req)
|
|
274
349
|
if r1 != 0:
|
|
275
350
|
raise Exception(f"create task fail!, reason={r2}")
|
|
351
|
+
print(f"task {r3} is pending now!")
|
|
276
352
|
return r3
|
|
277
353
|
|
|
278
354
|
def findWidget(name):
|
|
@@ -309,6 +385,17 @@ def getAutoDeployWidget():
|
|
|
309
385
|
return result
|
|
310
386
|
|
|
311
387
|
def checkTask(checkUUID):
|
|
388
|
+
if checkUUID.startswith("local_"):
|
|
389
|
+
if os.path.exists(os.path.join(constant.base_path, checkUUID + ".result")):
|
|
390
|
+
with open(os.path.join(constant.base_path, checkUUID + ".result"), "r") as f:
|
|
391
|
+
result_data = json.load(f)
|
|
392
|
+
finish = result_data["finish"]
|
|
393
|
+
success = result_data["success"]
|
|
394
|
+
data = result_data["data"]
|
|
395
|
+
progress = result_data["progress"]
|
|
396
|
+
return finish, success, data, progress
|
|
397
|
+
else:
|
|
398
|
+
return False, False, "", 0
|
|
312
399
|
req = {
|
|
313
400
|
"task_uuid": checkUUID
|
|
314
401
|
}
|
|
@@ -338,4 +425,4 @@ def multiCheckTask(checkUUIDs):
|
|
|
338
425
|
result.append([r3_item["uuid"], True, True, json.loads(r3_item["task_result"]), r3_item["progress"]])
|
|
339
426
|
elif r3_item["status"] == 3:
|
|
340
427
|
result.append([r3_item["uuid"], True, False, r3_item["fail_reason"], r3_item["progress"]])
|
|
341
|
-
return result
|
|
428
|
+
return result
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import time, urllib3, sys, os, uuid
|
|
1
|
+
import time, urllib3, sys, os, uuid, json
|
|
2
2
|
from threading import Thread, Lock
|
|
3
3
|
|
|
4
|
-
from ryry import ryry_webapi, upload, taskUtils, task
|
|
4
|
+
from ryry import ryry_webapi, upload, taskUtils, task, constant
|
|
5
5
|
|
|
6
6
|
lock = Lock()
|
|
7
7
|
def print_progress_bar(iteration, total, name, idx, total_bars):
|
|
@@ -39,33 +39,25 @@ class TaskThread(Thread):
|
|
|
39
39
|
self.checking = False
|
|
40
40
|
self.result = False, "Unknow"
|
|
41
41
|
if len(self.func) > 0:
|
|
42
|
+
self.checking = True
|
|
43
|
+
self.checkCount = 0
|
|
44
|
+
wait_time_step = 5
|
|
42
45
|
cmd = task.cmdWithWidgetName(self.func)
|
|
43
46
|
if cmd:
|
|
44
|
-
self.checkUUID =
|
|
45
|
-
self.params["task_id"] = self.checkUUID
|
|
46
|
-
taskUtils.appendTaskAndDomain(self.checkUUID, self.params["domain"])
|
|
47
|
-
executeSuccess, result_obj = task.executeLocalPython(self.checkUUID, cmd, self.params, self.timeout)
|
|
48
|
-
if executeSuccess and result_obj["status"] == 0:
|
|
49
|
-
self.call_back(self.idx, result_obj["result"])
|
|
50
|
-
return
|
|
47
|
+
self.checkUUID = ryry_webapi.createLocalTask(self.func, self.params, self.timeout)
|
|
51
48
|
else:
|
|
52
|
-
# run_server
|
|
53
49
|
self.checkUUID = ryry_webapi.createTask(self.func, self.params)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
time.sleep(wait_time_step)
|
|
51
|
+
while self.checking and self.checkCount < self.timeout / wait_time_step:
|
|
52
|
+
finish, success, data, progress = ryry_webapi.checkTask(self.checkUUID)
|
|
53
|
+
print_progress_bar(progress, 100, f"Task{self.idx} {self.func}", self.idx+1, self.total)
|
|
54
|
+
if finish:
|
|
55
|
+
self.checking = False
|
|
56
|
+
if success:
|
|
57
|
+
self.call_back(self.idx, data)
|
|
58
|
+
return
|
|
59
|
+
self.checkCount += 1
|
|
58
60
|
time.sleep(wait_time_step)
|
|
59
|
-
while self.checking and self.checkCount < self.timeout / wait_time_step:
|
|
60
|
-
finish, success, data, progress = ryry_webapi.checkTask(self.checkUUID)
|
|
61
|
-
print_progress_bar(progress, 100, f"Task{self.idx} {self.func}", self.idx+1, self.total)
|
|
62
|
-
if finish:
|
|
63
|
-
self.checking = False
|
|
64
|
-
if success:
|
|
65
|
-
self.call_back(self.idx, data)
|
|
66
|
-
return
|
|
67
|
-
self.checkCount += 1
|
|
68
|
-
time.sleep(wait_time_step)
|
|
69
61
|
else:
|
|
70
62
|
print(f"widget {self.func} not found")
|
|
71
63
|
self.call_back(self.idx, None)
|
|
@@ -73,6 +65,7 @@ class TaskThread(Thread):
|
|
|
73
65
|
def __del__(self):
|
|
74
66
|
if self.checking and self.checkUUID:
|
|
75
67
|
ryry_webapi.TaskCancel(self.checkUUID)
|
|
68
|
+
ryry_webapi.removeLocalTask(self.checkUUID)
|
|
76
69
|
|
|
77
70
|
class Task:
|
|
78
71
|
import urllib3
|
|
@@ -84,42 +84,56 @@ def removeWidget(widget_id):
|
|
|
84
84
|
if "widgets" not in read_data:
|
|
85
85
|
read_data["widgets"] = {}
|
|
86
86
|
widgetsMap = read_data["widgets"]
|
|
87
|
-
if widget_id
|
|
88
|
-
|
|
87
|
+
if widget_id == "all":
|
|
88
|
+
read_data["widgets"] = {}
|
|
89
|
+
else:
|
|
90
|
+
if widget_id in widgetsMap:
|
|
91
|
+
del widgetsMap[widget_id]
|
|
89
92
|
sp.write(read_data)
|
|
90
93
|
|
|
91
94
|
def disableWidget(widget_id):
|
|
92
95
|
sp = Store()
|
|
93
96
|
read_data = sp.read()
|
|
94
|
-
if "widgets" not in read_data:
|
|
97
|
+
if "widgets" not in read_data or not isinstance(read_data["widgets"], dict):
|
|
95
98
|
read_data["widgets"] = {}
|
|
96
99
|
widgetsMap = read_data["widgets"]
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
+
def block_one(key):
|
|
101
|
+
value = widgetsMap[key]
|
|
102
|
+
if isinstance(value, dict):
|
|
103
|
+
widgetsMap[key]["isBlock"] = True
|
|
100
104
|
else:
|
|
101
|
-
|
|
102
|
-
widgetsMap[widget_id] = {
|
|
105
|
+
widgetsMap[key] = {
|
|
103
106
|
"isBlock": True,
|
|
104
|
-
"path"
|
|
107
|
+
"path": value
|
|
105
108
|
}
|
|
106
|
-
sp.write(read_data)
|
|
107
109
|
|
|
110
|
+
if widget_id == "all":
|
|
111
|
+
for key in widgetsMap:
|
|
112
|
+
block_one(key)
|
|
113
|
+
elif widget_id in widgetsMap:
|
|
114
|
+
block_one(widget_id)
|
|
115
|
+
sp.write(read_data)
|
|
116
|
+
|
|
108
117
|
def enableWidget(widget_id):
|
|
109
118
|
sp = Store()
|
|
110
119
|
read_data = sp.read()
|
|
111
|
-
if "widgets" not in read_data:
|
|
112
|
-
read_data["widgets"] = {}
|
|
120
|
+
if "widgets" not in read_data or not isinstance(read_data["widgets"], dict):
|
|
121
|
+
read_data["widgets"] = {}
|
|
113
122
|
widgetsMap = read_data["widgets"]
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
123
|
+
def unblock_one(key):
|
|
124
|
+
value = widgetsMap[key]
|
|
125
|
+
if isinstance(value, dict):
|
|
126
|
+
widgetsMap[key]["isBlock"] = False
|
|
117
127
|
else:
|
|
118
|
-
|
|
119
|
-
widgetsMap[widget_id] = {
|
|
128
|
+
widgetsMap[key] = {
|
|
120
129
|
"isBlock": False,
|
|
121
|
-
"path"
|
|
130
|
+
"path": value
|
|
122
131
|
}
|
|
132
|
+
if widget_id == "all":
|
|
133
|
+
for key in widgetsMap:
|
|
134
|
+
unblock_one(key)
|
|
135
|
+
elif widget_id in widgetsMap:
|
|
136
|
+
unblock_one(widget_id)
|
|
123
137
|
sp.write(read_data)
|
|
124
138
|
|
|
125
139
|
#============================== device id ================================
|
|
@@ -118,6 +118,15 @@ def cmdWithWidgetName(name):
|
|
|
118
118
|
return map[widget_id]["path"]
|
|
119
119
|
return None
|
|
120
120
|
|
|
121
|
+
def widgetIDWithWidgetName(name):
|
|
122
|
+
map = store.widgetMap()
|
|
123
|
+
for widget_id in map.keys():
|
|
124
|
+
if "name" not in map[widget_id]:
|
|
125
|
+
continue
|
|
126
|
+
if map[widget_id]["name"] == name and map[widget_id]["isBlock"] == False:
|
|
127
|
+
return widget_id
|
|
128
|
+
return None
|
|
129
|
+
|
|
121
130
|
def executeLocalPython(taskUUID, cmd, param, timeout=3600):
|
|
122
131
|
# # 检查代码更新
|
|
123
132
|
# check_code_update()
|
|
@@ -27,18 +27,6 @@ def taskDomainWithUUID(taskUUID):
|
|
|
27
27
|
if taskUUID in task_config:
|
|
28
28
|
return task_config[taskUUID]["domain"]
|
|
29
29
|
return ""
|
|
30
|
-
def appendTaskAndDomain(taskUUID, subDomain):
|
|
31
|
-
task_config = {}
|
|
32
|
-
if os.path.exists(task_config_file):
|
|
33
|
-
with open(task_config_file, 'r') as f:
|
|
34
|
-
task_config = json.load(f)
|
|
35
|
-
task_config[taskUUID] = {
|
|
36
|
-
"pts": calendar.timegm(time.gmtime()),
|
|
37
|
-
"domain": subDomain
|
|
38
|
-
}
|
|
39
|
-
task_config["last_task_pts"] = task_config[taskUUID]["pts"]
|
|
40
|
-
with open(task_config_file, 'w') as f:
|
|
41
|
-
json.dump(task_config, f)
|
|
42
30
|
|
|
43
31
|
WECHAT_URL = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=1b006560-7012-4bf0-8c5e-a23830bc0a0b"
|
|
44
32
|
def uploadFile2Wechat(filepath):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|