lyrpy 2025.0.1__py3-none-any.whl → 2025.0.2__py3-none-any.whl

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.

Potentially problematic release.


This version of lyrpy might be problematic. Click here for more details.

Files changed (109) hide show
  1. SRC/LIB/__init__.py +21 -0
  2. SRC/lyrpy/LUConsole.py +402 -0
  3. SRC/lyrpy/LUConst.py +358 -0
  4. SRC/lyrpy/LUDateTime.py +205 -0
  5. SRC/lyrpy/LUDecotators.py +417 -0
  6. SRC/lyrpy/LUDict.py +116 -0
  7. SRC/lyrpy/LUDoc.py +62 -0
  8. SRC/lyrpy/LUErrors.py +79 -0
  9. SRC/lyrpy/LUFile.py +1228 -0
  10. SRC/lyrpy/LUFileUtils.py +501 -0
  11. SRC/lyrpy/LULog.py +2324 -0
  12. SRC/lyrpy/LUNetwork.py +277 -0
  13. SRC/lyrpy/LUNumUtils.py +305 -0
  14. SRC/lyrpy/LUObjects.py +208 -0
  15. SRC/lyrpy/LUObjectsYT.py +846 -0
  16. SRC/lyrpy/LUParserARG.py +364 -0
  17. SRC/lyrpy/LUParserINI.py +376 -0
  18. SRC/lyrpy/LUParserREG.py +514 -0
  19. SRC/lyrpy/LUProc.py +110 -0
  20. SRC/lyrpy/LUQThread.py +141 -0
  21. SRC/lyrpy/LUQTimer.py +197 -0
  22. SRC/lyrpy/LUSheduler.py +941 -0
  23. SRC/lyrpy/LUStrDecode.py +223 -0
  24. SRC/lyrpy/LUStrUtils.py +633 -0
  25. SRC/lyrpy/LUSupport.py +124 -0
  26. SRC/lyrpy/LUTelegram.py +428 -0
  27. SRC/lyrpy/LUThread.py +177 -0
  28. SRC/lyrpy/LUTimer.py +141 -0
  29. SRC/lyrpy/LUVersion.py +383 -0
  30. SRC/lyrpy/LUYouTube.py +203 -0
  31. SRC/lyrpy/LUos.py +807 -0
  32. SRC/lyrpy/LUsys.py +47 -0
  33. SRC/lyrpy/__init__.py +21 -0
  34. SRC/lyrpy/__main__.py +20 -0
  35. __SRC/LIB/__init__.py +0 -0
  36. __SRC/LIB/lyrpy/LUConsole.py +402 -0
  37. __SRC/LIB/lyrpy/LUConst.py +358 -0
  38. __SRC/LIB/lyrpy/LUDateTime.py +205 -0
  39. __SRC/LIB/lyrpy/LUDecotators.py +417 -0
  40. __SRC/LIB/lyrpy/LUDict.py +116 -0
  41. __SRC/LIB/lyrpy/LUDoc.py +62 -0
  42. __SRC/LIB/lyrpy/LUErrors.py +79 -0
  43. __SRC/LIB/lyrpy/LUFile.py +1228 -0
  44. __SRC/LIB/lyrpy/LUFileUtils.py +501 -0
  45. __SRC/LIB/lyrpy/LULog.py +2324 -0
  46. __SRC/LIB/lyrpy/LUNetwork.py +277 -0
  47. __SRC/LIB/lyrpy/LUNumUtils.py +305 -0
  48. __SRC/LIB/lyrpy/LUObjects.py +208 -0
  49. __SRC/LIB/lyrpy/LUObjectsYT.py +846 -0
  50. __SRC/LIB/lyrpy/LUParserARG.py +364 -0
  51. __SRC/LIB/lyrpy/LUParserINI.py +376 -0
  52. __SRC/LIB/lyrpy/LUParserREG.py +514 -0
  53. __SRC/LIB/lyrpy/LUProc.py +110 -0
  54. __SRC/LIB/lyrpy/LUQThread.py +141 -0
  55. __SRC/LIB/lyrpy/LUQTimer.py +197 -0
  56. __SRC/LIB/lyrpy/LUSheduler.py +941 -0
  57. __SRC/LIB/lyrpy/LUStrDecode.py +223 -0
  58. __SRC/LIB/lyrpy/LUStrUtils.py +633 -0
  59. __SRC/LIB/lyrpy/LUSupport.py +124 -0
  60. __SRC/LIB/lyrpy/LUTelegram.py +428 -0
  61. __SRC/LIB/lyrpy/LUThread.py +177 -0
  62. __SRC/LIB/lyrpy/LUTimer.py +141 -0
  63. __SRC/LIB/lyrpy/LUVersion.py +383 -0
  64. __SRC/LIB/lyrpy/LUYouTube.py +203 -0
  65. __SRC/LIB/lyrpy/LUos.py +807 -0
  66. __SRC/LIB/lyrpy/LUsys.py +47 -0
  67. __SRC/LIB/lyrpy/__init__.py +21 -0
  68. __SRC/LIB/lyrpy/__main__.py +20 -0
  69. __SRC/__init__.py +0 -0
  70. ____src/__init__.py +0 -0
  71. ____src/lyrpy/LUConsole.py +402 -0
  72. ____src/lyrpy/LUConst.py +358 -0
  73. ____src/lyrpy/LUDateTime.py +205 -0
  74. ____src/lyrpy/LUDecotators.py +417 -0
  75. ____src/lyrpy/LUDict.py +116 -0
  76. ____src/lyrpy/LUDoc.py +62 -0
  77. ____src/lyrpy/LUErrors.py +79 -0
  78. ____src/lyrpy/LUFile.py +1228 -0
  79. ____src/lyrpy/LUFileUtils.py +501 -0
  80. ____src/lyrpy/LULog.py +2324 -0
  81. ____src/lyrpy/LUNetwork.py +277 -0
  82. ____src/lyrpy/LUNumUtils.py +305 -0
  83. ____src/lyrpy/LUObjects.py +208 -0
  84. ____src/lyrpy/LUObjectsYT.py +846 -0
  85. ____src/lyrpy/LUParserARG.py +364 -0
  86. ____src/lyrpy/LUParserINI.py +376 -0
  87. ____src/lyrpy/LUParserREG.py +514 -0
  88. ____src/lyrpy/LUProc.py +110 -0
  89. ____src/lyrpy/LUQThread.py +141 -0
  90. ____src/lyrpy/LUQTimer.py +197 -0
  91. ____src/lyrpy/LUSheduler.py +941 -0
  92. ____src/lyrpy/LUStrDecode.py +223 -0
  93. ____src/lyrpy/LUStrUtils.py +633 -0
  94. ____src/lyrpy/LUSupport.py +124 -0
  95. ____src/lyrpy/LUTelegram.py +428 -0
  96. ____src/lyrpy/LUThread.py +177 -0
  97. ____src/lyrpy/LUTimer.py +141 -0
  98. ____src/lyrpy/LUVersion.py +383 -0
  99. ____src/lyrpy/LUYouTube.py +203 -0
  100. ____src/lyrpy/LUos.py +807 -0
  101. ____src/lyrpy/LUsys.py +47 -0
  102. ____src/lyrpy/__init__.py +21 -0
  103. ____src/lyrpy/__main__.py +20 -0
  104. {lyrpy-2025.0.1.dist-info → lyrpy-2025.0.2.dist-info}/METADATA +1 -1
  105. lyrpy-2025.0.2.dist-info/RECORD +145 -0
  106. lyrpy-2025.0.1.dist-info/RECORD +0 -43
  107. {lyrpy-2025.0.1.dist-info → lyrpy-2025.0.2.dist-info}/WHEEL +0 -0
  108. {lyrpy-2025.0.1.dist-info → lyrpy-2025.0.2.dist-info}/licenses/LICENSE +0 -0
  109. {lyrpy-2025.0.1.dist-info → lyrpy-2025.0.2.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,941 @@
1
+ """LUSheduler.py"""
2
+ # -*- coding: UTF-8 -*-
3
+ __annotations__ = """
4
+ =======================================================
5
+ Copyright (c) 2023-2024
6
+ Author:
7
+ Lisitsin Y.R.
8
+ Project:
9
+ LU_PY
10
+ Python (LU)
11
+ Module:
12
+ LUSheduler.py
13
+
14
+ =======================================================
15
+ """
16
+
17
+ #------------------------------------------
18
+ # БИБЛИОТЕКИ python
19
+ #------------------------------------------
20
+ import datetime
21
+ from calendar import monthrange
22
+ import threading
23
+ import logging
24
+
25
+ #------------------------------------------
26
+ # БИБЛИОТЕКИ сторонние
27
+ #------------------------------------------
28
+
29
+ #------------------------------------------
30
+ # БИБЛИОТЕКИ LU
31
+ #------------------------------------------
32
+ import lyrpy.LULog as LULog
33
+ import lyrpy.LUStrUtils as LUStrUtils
34
+ import lyrpy.LUDateTime as LUDateTime
35
+
36
+ minNN = 0
37
+ maxNN = 59
38
+ minHH = 0
39
+ maxHH = 23
40
+ minDW = 1
41
+ maxDW = 7
42
+ minMM = 1
43
+ maxMM = 12
44
+ minDD = 1
45
+ maxDD = 31
46
+ DelimPattern = ' '
47
+ DelimItem = ','
48
+ DelimItems = '-'
49
+ """
50
+ ------------------------------------------------------------------
51
+ NN-NN HH-HH DD-DD MM-MM DW-DW [Program]
52
+ NN,NN,.. HH,HH,... DD,DD,... MM,MM,... DW,DW,... [Program]
53
+ * * * * * [Program]
54
+ ------------------------------------------------------------------
55
+ """
56
+
57
+ def NotifyFileEvent():
58
+ #beginfunction
59
+ ...
60
+ #endfunction
61
+ TNotifyFileEvent = NotifyFileEvent
62
+
63
+ # --------------------------------------------
64
+ # TObjectsItem
65
+ # --------------------------------------------
66
+ class TShedulerEventItem (object):
67
+ """TShedulerEventItem"""
68
+ luClassName = 'TShedulerEventItem'
69
+
70
+ @staticmethod
71
+ def IsBitOn (Value: int, Bit: int) -> bool:
72
+ #beginfunction
73
+ # return n & (1<<b))
74
+ LResult = (Value & (1<<Bit)) != 0
75
+ return LResult
76
+ #endfunction
77
+
78
+ @staticmethod
79
+ def TurnBitOn (Value: int, Bit: int) -> int:
80
+ #beginfunction
81
+ #return value | (1<<bit)
82
+ LResult = Value | (1<<Bit)
83
+ return LResult
84
+ #endfunction
85
+
86
+ @staticmethod
87
+ def TurnBitOff (Value: int, Bit: int) -> int:
88
+ #beginfunction
89
+ # return value & ~(1<<bit)
90
+ LResult = Value & ~ (1<<Bit)
91
+ return LResult
92
+ #endfunction
93
+
94
+ #--------------------------------------------------
95
+ # constructor
96
+ #--------------------------------------------------
97
+ def __init__(self):
98
+ """ Constructor """
99
+ super().__init__()
100
+ self.__FDD: int = 0
101
+ self.__FMM: int = 0
102
+ self.__FDW: int = 0
103
+ self.__FHH: int = 0
104
+ self.__FNN1: int = 0
105
+ self.__FNN2: int = 0
106
+ self.__FList: () = list ()
107
+ self.__FNameEvent: str = ''
108
+ self.Clear()
109
+
110
+ #--------------------------------------------------
111
+ # destructor
112
+ #--------------------------------------------------
113
+ def __del__(self):
114
+ """ destructor """
115
+ #beginfunction
116
+ # удалить объект
117
+ del self.__FList
118
+ LClassName = self.__class__.__name__
119
+ # s = '{} уничтожен'.format (LClassName)
120
+ # LUConst.LULogger.log (LULog.DEBUGTEXT, s)
121
+ #print (s)
122
+ #endfunction
123
+
124
+ def Clear(self):
125
+ #beginfunction
126
+ ...
127
+ #endfunction
128
+
129
+ #--------------------------------------------------
130
+ # @property NameEvent
131
+ #--------------------------------------------------
132
+ # getter
133
+ @property
134
+ def NameEvent(self):
135
+ #beginfunction
136
+ return self.__FNameEvent
137
+ #endfunction
138
+ @NameEvent.setter
139
+ def NameEvent(self, Value: str):
140
+ #beginfunction
141
+ self.__FNameEvent: str = Value
142
+ #endfunction
143
+
144
+ def GetXX (self) -> ():
145
+ #beginfunction
146
+ return self.__FNN1,self.__FNN2,self.__FHH,self.__FDD,self.__FMM,self.__FDW
147
+ #endfunction
148
+
149
+ #--------------------------------------------------
150
+ # @property NN
151
+ #--------------------------------------------------
152
+ # property NN [Index: Integer]: Boolean read GetNN write SetNN;
153
+ def GetNN (self, Index: int) -> bool:
154
+ #beginfunction
155
+ LResult = False
156
+ if (Index >= minNN) and (Index <= maxNN):
157
+ if Index <= 31:
158
+ LResult = self.IsBitOn (self.__FNN1, Index)
159
+ else:
160
+ LResult = self.IsBitOn (self.__FNN2, Index-32)
161
+ #endif
162
+ #endif
163
+ return LResult
164
+ #endfunction
165
+ def SetNN (self, Index: int, Value: bool):
166
+ #beginfunction
167
+ if (Index >= minNN) and (Index <= maxNN):
168
+ if Index <= 31:
169
+ if Value:
170
+ self.__FNN1 = self.TurnBitOn (self.__FNN1, Index)
171
+ else:
172
+ self.__FNN1 = self.TurnBitOff (self.__FNN1, Index)
173
+ #endif
174
+ else:
175
+ if Value:
176
+ self.__FNN2 = self.TurnBitOn (self.__FNN2, Index-32)
177
+ else:
178
+ self.__FNN2 = self.TurnBitOff (self.__FNN2, Index-32)
179
+ #endif
180
+ #endif
181
+ #endif
182
+ #endfunction
183
+
184
+ #--------------------------------------------------
185
+ # @property HH
186
+ #--------------------------------------------------
187
+ # property HH [Index: Integer]: Boolean read GetHH write SetHH;
188
+ def GetHH (self, Index: int) -> bool:
189
+ #beginfunction
190
+ LResult = False
191
+ if (Index >= minHH) and (Index <= maxHH):
192
+ LResult = self.IsBitOn (self.__FHH, Index)
193
+ return LResult
194
+ #endfunction
195
+ def SetHH (self, Index: int, Value: bool):
196
+ #beginfunction
197
+ if (Index >= minHH) and (Index <= maxHH):
198
+ if Value:
199
+ self.__FHH = self.TurnBitOn (self.__FHH, Index)
200
+ else:
201
+ self.__FHH = self.TurnBitOff (self.__FHH, Index)
202
+ #endif
203
+ #endif
204
+ #endfunction
205
+
206
+ #--------------------------------------------------
207
+ # @property DD
208
+ #--------------------------------------------------
209
+ # property DD [Index: Integer]: Boolean read GetDD write SetDD;
210
+ def GetDD (self, Index: int) -> bool:
211
+ #beginfunction
212
+ LResult = False
213
+ if (Index >= minDD-1) and (Index <= maxDD-1):
214
+ # if (Index >= minDD - 1) and (Index <= maxDD):
215
+ LResult = self.IsBitOn (self.__FDD, Index)
216
+ return LResult
217
+ #endfunction
218
+ def SetDD (self, Index: int, Value: bool):
219
+ #beginfunction
220
+ if (Index >= minDD-1) and (Index <= maxDD-1):
221
+ if Value:
222
+ self.__FDD = self.TurnBitOn (self.__FDD, Index)
223
+ else:
224
+ self.__FDD = self.TurnBitOff (self.__FDD, Index)
225
+ #endif
226
+ #endif
227
+ #endfunction
228
+
229
+ #--------------------------------------------------
230
+ # @property MM
231
+ #--------------------------------------------------
232
+ # property MM [Index: Integer]: Boolean read GetMM write SetMM;
233
+ def GetMM (self, Index: int) -> bool:
234
+ #beginfunction
235
+ LResult = False
236
+ if (Index >= minMM-1) and (Index <= maxMM-1):
237
+ LResult = self.IsBitOn (self.__FMM, Index)
238
+ return LResult
239
+ #endfunction
240
+ def SetMM (self, Index: int, Value: bool):
241
+ #beginfunction
242
+ if (Index >= minMM-1) and (Index <= maxMM-1):
243
+ if Value:
244
+ self.__FMM = self.TurnBitOn (self.__FMM, Index)
245
+ else:
246
+ self.__FMM = self.TurnBitOff (self.__FMM, Index)
247
+ #endif
248
+ #endif
249
+ #endfunction
250
+
251
+ #--------------------------------------------------
252
+ # @property DW
253
+ #--------------------------------------------------
254
+ # property DW [Index: Integer]: Boolean read GetDW write SetDW;
255
+ def GetDW (self, Index: int) -> bool:
256
+ #beginfunction
257
+ LResult = False
258
+ if (Index >= minDW-1) and (Index <= maxDW-1):
259
+ LResult = self.IsBitOn (self.__FDW, Index)
260
+ return LResult
261
+ #endfunction
262
+ def SetDW (self, Index: int, Value: bool):
263
+ #beginfunction
264
+ if (Index >= minDW-1) and (Index <= maxDW-1):
265
+ if Value:
266
+ self.__FDW = self.TurnBitOn (self.__FDW, Index)
267
+ else:
268
+ self.__FDW = self.TurnBitOff (self.__FDW, Index)
269
+ #endif
270
+ #endif
271
+ #endfunction
272
+
273
+ #--------------------------------------------------
274
+ # @property XXString
275
+ #--------------------------------------------------
276
+ # property XXString[XXName: string]: string read GetXXString;
277
+ def GetXXString (self, XXName: str) -> str:
278
+ #beginfunction
279
+ LResult = ''
280
+ if XXName.upper() == 'DD':
281
+ for i in range (0, maxDD):
282
+ if self.GetDD(i):
283
+ LResult = LResult+LUStrUtils.AddChar(' ', str(i+1), 2)+','
284
+ else:
285
+ LResult = LResult + 'xx' + ','
286
+ #endif
287
+ #endfor
288
+ #endif
289
+ if XXName.upper() == 'MM':
290
+ for i in range (0, maxMM):
291
+ if self.GetMM(i):
292
+ LResult = LResult+LUStrUtils.AddChar(' ', str(i+1), 2)+','
293
+ else:
294
+ LResult = LResult + 'xx' + ','
295
+ #endif
296
+ #endfor
297
+ #endif
298
+ if XXName.upper() == 'DW':
299
+ for i in range (0, maxDW):
300
+ if self.GetDW(i):
301
+ LResult = LResult+LUStrUtils.AddChar(' ', str(i+1), 2)+','
302
+ else:
303
+ LResult = LResult + 'xx' + ','
304
+ #endif
305
+ #endfor
306
+ #endif
307
+ if XXName.upper() == 'HH':
308
+ for i in range (0, maxHH+1):
309
+ if self.GetHH(i):
310
+ LResult = LResult+LUStrUtils.AddChar(' ', str(i), 2)+','
311
+ else:
312
+ LResult = LResult + 'xx' + ','
313
+ #endif
314
+ #endfor
315
+ #endif
316
+ if XXName.upper() == 'NN':
317
+ for i in range (0, maxNN+1):
318
+ if self.GetNN(i):
319
+ LResult = LResult+LUStrUtils.AddChar(' ', str(i), 2)+','
320
+ else:
321
+ LResult = LResult + 'xx' + ','
322
+ #endif
323
+ #endfor
324
+ #endif
325
+ # удалить последний символ ',' в строке
326
+ LResult = LResult [:-1]
327
+ return LResult
328
+ #endfunction
329
+
330
+ def CreateList (self, Pattern: str, Lmin: int, Lmax: int):
331
+ #var
332
+ # i, j, WCount, i11, i12: Integer;
333
+ # S1, S11, S12: string;
334
+ #beginfunction
335
+ self.__FList.clear()
336
+ if Pattern == '*':
337
+ for j in range (Lmin, Lmax+1):
338
+ # self.__FList.append (str(j))
339
+ self.__FList.append (j)
340
+ else:
341
+ WCount = LUStrUtils.WordCount(Pattern, DelimItem)
342
+ for i in range (1, WCount+1):
343
+ s1 = LUStrUtils.ExtractWord (i, Pattern, DelimItem)
344
+ s11 = LUStrUtils.ExtractWord (1, s1, DelimItems)
345
+ s12 = LUStrUtils.ExtractWord (2, s1, DelimItems)
346
+ try:
347
+ i11 = int(s11)
348
+ except:
349
+ i11 = -1
350
+ #endtry
351
+ if i11 > Lmax: i11 = Lmax #endif
352
+ try:
353
+ i12 = int(s12)
354
+ except:
355
+ i12 = i11
356
+ #endtry
357
+ if i12 > Lmax: i12 = Lmax #endif
358
+ if i11 >= 0 and i12 >= 0:
359
+ # for j in range (i11, i12 + 1): self.__FList.append (str (j))
360
+ for j in range (i11, i12 + 1): self.__FList.append (j)
361
+ #endif
362
+ #endfor
363
+ #endif
364
+ #endfunction
365
+
366
+ # def NewPatterns (self, Patterns: str):
367
+ # #beginfunction
368
+ # self.__FDD = 0
369
+ # self.__FMM = 0
370
+ # self.__FDW = 0
371
+ # self.__FHH = 0
372
+ # self.__FNN1 = 0
373
+ # self.__FNN2 = 0
374
+ # self.AddPatterns (Patterns)
375
+ # #endfunction
376
+
377
+ def AddPatterns (self, Patterns: str):
378
+ #beginfunction
379
+ self.__FDD = 0
380
+ self.__FMM = 0
381
+ self.__FDW = 0
382
+ self.__FHH = 0
383
+ self.__FNN1 = 0
384
+ self.__FNN2 = 0
385
+ # NN
386
+ self.CreateList (LUStrUtils.ExtractWord (1, Patterns, DelimPattern), minNN, maxNN)
387
+ for item in self.__FList:
388
+ # self.SetNN(self.__FList.index(item), True)
389
+ self.SetNN(item, True)
390
+ # HH
391
+ self.CreateList (LUStrUtils.ExtractWord (2, Patterns, DelimPattern), minHH, maxHH)
392
+ for item in self.__FList:
393
+ # self.SetHH (self.__FList.index(item), True)
394
+ self.SetHH (item, True)
395
+ # DD
396
+ self.CreateList (LUStrUtils.ExtractWord (3, Patterns, DelimPattern), minDD, maxDD)
397
+ for item in self.__FList:
398
+ # self.SetDD (self.__FList.index(item), True)
399
+ self.SetDD (item-1, True)
400
+ # MM
401
+ self.CreateList (LUStrUtils.ExtractWord (4, Patterns, DelimPattern), minMM, maxMM)
402
+ for item in self.__FList:
403
+ # self.SetMM (self.__FList.index(item), True)
404
+ self.SetMM (item-1, True)
405
+ # DW
406
+ self.CreateList (LUStrUtils.ExtractWord (5, Patterns, DelimPattern), minDW, maxDW)
407
+ for item in self.__FList:
408
+ # self.SetDW (self.__FList.index (item), True)
409
+ self.SetDW (item-1, True)
410
+ #endfunction
411
+ #endclass
412
+
413
+ # --------------------------------------------
414
+ # TSheduler
415
+ # --------------------------------------------
416
+ class TSheduler (object):
417
+ """TSheduler"""
418
+ luClassName = 'TSheduler'
419
+
420
+ #--------------------------------------------------
421
+ # constructor
422
+ #--------------------------------------------------
423
+ def __init__ (self, *args, **kwargs):
424
+ """Constructor"""
425
+ #beginfunction
426
+ super ().__init__ (*args, **kwargs)
427
+ self.args = args
428
+ self.kwargs = kwargs
429
+ #
430
+ self.__FStopThread = False
431
+ #
432
+ self.__FShedulerEvents = list ()
433
+ #
434
+ self.__FNameEvents = list ()
435
+ # 'Следующий сеанс: ', self.DTEvents
436
+ self.__FDTEvents: datetime = 0
437
+ #
438
+ self.__FEnable: bool = False
439
+ #
440
+ self.__FOnSheduler: TNotifyFileEvent = None
441
+ #
442
+ self.__FOnShedulerEvent:TShedulerEventItem = None
443
+
444
+ #endfunction
445
+
446
+ #--------------------------------------------------
447
+ # destructor
448
+ #--------------------------------------------------
449
+ def __del__(self):
450
+ """destructor"""
451
+ #beginfunction
452
+ # удалить объект
453
+ del self.__FShedulerEvents
454
+ del self.__FNameEvents
455
+ LClassName = self.__class__.__name__
456
+ # s = '{} уничтожен'.format(LClassName)
457
+ # LUConst.LULogger.log (LULog.DEBUGTEXT, s)
458
+ #endfunction
459
+
460
+ #--------------------------------------------------
461
+ # @property OnSheduler
462
+ #--------------------------------------------------
463
+ # getter
464
+ @property
465
+ def OnSheduler(self) -> TNotifyFileEvent:
466
+ #beginfunction
467
+ return self.__FOnSheduler
468
+ #endfunction
469
+ @OnSheduler.setter
470
+ def OnSheduler(self, Value):
471
+ #beginfunction
472
+ self.__FOnSheduler = Value
473
+ self.__FFunction = Value
474
+ #endfunction
475
+
476
+ #--------------------------------------------------
477
+ # @property Enable
478
+ #--------------------------------------------------
479
+ # getter
480
+ @property
481
+ def Enable(self) -> bool:
482
+ #beginfunction
483
+ return self.__FEnable
484
+ #endfunction
485
+ @Enable.setter
486
+ def Enable(self, Value: bool):
487
+ #beginfunction
488
+ self.__FEnable: bool = Value
489
+ if Value:
490
+ self.CreateNextEvent (True)
491
+ #endif
492
+ #endfunction
493
+
494
+ # #--------------------------------------------------
495
+ # # @property ShedulerEvents
496
+ # #--------------------------------------------------
497
+ # # getter
498
+ # @property
499
+ # def ShedulerEvents(self):
500
+ # #beginfunction
501
+ # return self.__FShedulerEvents
502
+ # #endfunction
503
+ # @ShedulerEvents.setter
504
+ # def ShedulerEvents(self, Value: ()):
505
+ # #beginfunction
506
+ # self.__FShedulerEvents: () = Value
507
+ # #endfunction
508
+
509
+ #--------------------------------------------------
510
+ # @property OnShedulerEvent
511
+ #--------------------------------------------------
512
+ # getter
513
+ @property
514
+ def OnShedulerEvent(self) -> TShedulerEventItem:
515
+ #beginfunction
516
+ return self.__FOnShedulerEvent
517
+ #endfunction
518
+ @OnShedulerEvent.setter
519
+ def OnShedulerEvent(self, Value:TShedulerEventItem):
520
+ #beginfunction
521
+ self.__FOnShedulerEvent = Value
522
+ #endfunction
523
+
524
+ #--------------------------------------------------
525
+ # @property ShedulerEventItem
526
+ #--------------------------------------------------
527
+ def GetShedulerEventItem(self, ANameEvent: str) -> TShedulerEventItem:
528
+ #beginfunction
529
+ for item in self.__FShedulerEvents:
530
+ if item.NameEvent == ANameEvent:
531
+ return item
532
+ #endif
533
+ #endfor
534
+ return None
535
+ #endfunction
536
+
537
+ # #--------------------------------------------------
538
+ # # @property NameEvents
539
+ # #--------------------------------------------------
540
+ # # getter
541
+ # @property
542
+ # def NameEvents(self) -> list:
543
+ # #beginfunction
544
+ # self.CreateNextEvent (True)
545
+ # return self.__FNameEvents
546
+ # #endfunction
547
+
548
+ #--------------------------------------------------
549
+ # @property DTEvents
550
+ #--------------------------------------------------
551
+ # getter
552
+ @property
553
+ def DTEvents(self) -> datetime:
554
+ #beginfunction
555
+ return self.__FDTEvents
556
+ #endfunction
557
+
558
+ #--------------------------------------------------
559
+ # __run_Function
560
+ #--------------------------------------------------
561
+ def run_Function(self):
562
+ """__run_Function"""
563
+ #beginfunction
564
+ # s = '__run_Function...'
565
+ # LULog.LoggerTOOLS_AddDebug (s)
566
+ if self.__FEnable:
567
+ LPresentNow = LUDateTime.Now ()
568
+ LYear, LMonth, LDay = LUDateTime.DecodeDate (LPresentNow)
569
+ LHour, LMin, LSec, LMSec = LUDateTime.DecodeTime (LPresentNow)
570
+ LDTEventsNow = LUDateTime.EncodeDateTime (LYear, LMonth, LDay, LHour, LMin, 0, 0)
571
+ # print (LDTEventsNow, self.DTEvents)
572
+ if LDTEventsNow == self.DTEvents:
573
+ self.__Second ()
574
+ # 'Следующий сеанс: ', self.DTEvents
575
+ self.CreateNextEvent (False)
576
+ #endif
577
+ #endif
578
+ #endfunction
579
+
580
+ def CreateNextEvent (self, APrint: bool):
581
+ """__CreateNextEvent"""
582
+ #beginfunction
583
+ LPresent: datetime = LUDateTime.Now ()
584
+ LYear, LMonth, LDay = LUDateTime.DecodeDate (LPresent)
585
+ LHour, LMin, LSec, LMSec = LUDateTime.DecodeTime (LPresent)
586
+ LMin = LMin + 1
587
+ self.__FNameEvents.clear()
588
+ # Year
589
+ for LYear in range (LYear,LYear+1):
590
+ # Month
591
+ for LMonth in range (LMonth, maxMM):
592
+ # MaxDDWork = DateUtils.DaysInMonth (Present)
593
+ MaxDDWork = monthrange (LYear, LMonth)[1]
594
+ # Day of Month
595
+ for LDay in range (LDay, MaxDDWork+1):
596
+ LDayWeek = LUDateTime.DayOfWeek (LUDateTime.EncodeDate(LYear,LMonth,LDay))
597
+ LDayWeek = LDayWeek + 1
598
+ if LDayWeek == 0:
599
+ LDayWeek = 7
600
+ #endif
601
+ # Hour
602
+ for LHour in range (LHour, maxHH+1):
603
+ # Min
604
+ for LMin in range (LMin, maxNN+1):
605
+ # Check List Sheduler
606
+ for item in self.__FShedulerEvents:
607
+ self.OnShedulerEvent:TShedulerEventItem = item
608
+ bDay = self.OnShedulerEvent.GetDD (LDay-1)
609
+ bDayWeek = self.OnShedulerEvent.GetDW (LDayWeek-1)
610
+ bMonth = self.OnShedulerEvent.GetMM (LMonth-1)
611
+ bHour = self.OnShedulerEvent.GetHH (LHour)
612
+ bMin = self.OnShedulerEvent.GetNN (LMin)
613
+ # print (bDay, bDayWeek, bMonth, bHour, bMin)
614
+ if bDay and bDayWeek and bMonth and bHour and bMin:
615
+ self.__FNameEvents.append (self.OnShedulerEvent.NameEvent)
616
+ #endif
617
+ #endfor
618
+ if len(self.__FNameEvents) > 0:
619
+ break
620
+ #endif
621
+ #endfor
622
+ if len(self.__FNameEvents) == 0:
623
+ LMin = minNN
624
+ else:
625
+ break
626
+ #endif
627
+ #endfor
628
+ if len(self.__FNameEvents) == 0:
629
+ LHour = minHH
630
+ else:
631
+ break
632
+ #endif
633
+ #endfor
634
+ if len(self.__FNameEvents) == 0:
635
+ LDay = minDD
636
+ else:
637
+ break
638
+ #endif
639
+ #endfor
640
+ if len(self.__FNameEvents) == 0:
641
+ LMonth = minMM
642
+ else:
643
+ break
644
+ #endif
645
+ #endfor
646
+ if len(self.__FNameEvents) > 0:
647
+ D = LUDateTime.EncodeDate (LYear, LMonth, LDay)
648
+ T = LUDateTime.EncodeTime (LHour, LMin, 0, 0)
649
+ self.__FDTEvents = datetime.datetime.combine (D, T)
650
+ self.__FDTEvents = LUDateTime.EncodeDateTime (LYear, LMonth, LDay, LHour, LMin, 0, 0)
651
+ else:
652
+ self.__FDTEvents = LPresent
653
+ #endif
654
+ s = 'Следующий сеанс: ' + str (self.__FDTEvents)
655
+ if APrint:
656
+ LULog.LoggerAdd (LULog.LoggerTOOLS, logging.DEBUG, s)
657
+ #endif
658
+ #endfunction
659
+
660
+ def __Second (self):
661
+ """Second"""
662
+ #beginfunction
663
+ # s = 'Second...'
664
+ # LULog.LoggerTOOLS_AddDebug (s)
665
+ if self.__FEnable:
666
+ LPresent: datetime = LUDateTime.Now()
667
+ LHour, LMin, LSec, LMSec = LUDateTime.DecodeTime (LPresent)
668
+ # Check List Sheduler
669
+ LYear, LMonth, LDay = LUDateTime.DecodeDate (LPresent)
670
+ LDayWeek = LUDateTime.DayOfWeek (LPresent)
671
+ LDayWeek = LDayWeek + 1
672
+ if LDayWeek == 0:
673
+ LDayWeek = 7
674
+ for item in self.__FShedulerEvents:
675
+ LEvent: TShedulerEventItem = item
676
+ bDay = LEvent.GetDD (LDay-1)
677
+ bDayWeek = LEvent.GetDW (LDayWeek-1)
678
+ bMonth = LEvent.GetMM (LMonth-1)
679
+ bHour = LEvent.GetHH (LHour)
680
+ bMin = LEvent.GetNN (LMin)
681
+ if bDay and bDayWeek and bMonth and bHour and bMin:
682
+ self.OnShedulerEvent = item
683
+ if self.OnSheduler is not None:
684
+ self.OnSheduler (LEvent)
685
+ #endif
686
+ #endif
687
+ #endfor
688
+ #endif
689
+ #endfunction
690
+
691
+ def __CreateShedulerEvent(self) -> TShedulerEventItem:
692
+ #beginfunction
693
+ LResult: TShedulerEventItem = TShedulerEventItem()
694
+ self.__FShedulerEvents.append(LResult)
695
+ return LResult
696
+ #endfunction
697
+
698
+ def __DeleteEvent (self, ANameEvent: str):
699
+ #beginfunction
700
+ for item in self.__FShedulerEvents:
701
+ if item.NameEvent == ANameEvent:
702
+ self.__FShedulerEvents.remove(item)
703
+ break
704
+ #endif
705
+ #endfor
706
+ #endfunction
707
+
708
+ def AddEvent (self, ANameEvent:str, APatterns: str) -> TShedulerEventItem:
709
+ """AddEvent"""
710
+ #beginfunction
711
+ LEvent:TShedulerEventItem = None
712
+ for item in self.__FShedulerEvents:
713
+ if item.NameEvent == ANameEvent:
714
+ LEvent: TShedulerEventItem = item
715
+ break
716
+ #endif
717
+ #endfor
718
+
719
+ if LEvent is not None and LEvent.NameEvent == ANameEvent:
720
+ LEvent.AddPatterns (APatterns)
721
+ else:
722
+ LEvent:TShedulerEventItem = self.__CreateShedulerEvent()
723
+ LEvent.NameEvent = ANameEvent
724
+ LEvent.AddPatterns (APatterns)
725
+ #endif
726
+ return LEvent
727
+ #endfunction
728
+
729
+ @staticmethod
730
+ def PrintEvent (AEvent: TShedulerEventItem):
731
+ """PrintEvent"""
732
+ #beginfunction
733
+ LULog.LoggerAdd (LULog.LoggerTOOLS, logging.DEBUG, AEvent.NameEvent)
734
+ s = f'NN={AEvent.GetXXString ("NN")}'
735
+ LULog.LoggerAdd (LULog.LoggerTOOLS, logging.DEBUG, s)
736
+ s = f'HH={AEvent.GetXXString ("HH")}'
737
+ LULog.LoggerAdd (LULog.LoggerTOOLS, logging.DEBUG, s)
738
+ s = f'DD={AEvent.GetXXString ("DD")}'
739
+ LULog.LoggerAdd (LULog.LoggerTOOLS, logging.DEBUG, s)
740
+ s = f'MM={AEvent.GetXXString ("MM")}'
741
+ LULog.LoggerAdd (LULog.LoggerTOOLS, logging.DEBUG, s)
742
+ s = f'DW={AEvent.GetXXString ("DW")}'
743
+ LULog.LoggerAdd (LULog.LoggerTOOLS, logging.DEBUG, s)
744
+ #endfunction
745
+ #endclass
746
+
747
+ # --------------------------------------------
748
+ # TShedulerThread
749
+ # --------------------------------------------
750
+ class TShedulerThread (threading.Thread):
751
+ """TShedulerThread"""
752
+ luClassName = 'TShedulerThread'
753
+
754
+ #--------------------------------------------------
755
+ # constructor
756
+ #--------------------------------------------------
757
+ def __init__ (self, *args, **kwargs):
758
+ """Constructor"""
759
+ #beginfunction
760
+ super ().__init__ (*args, **kwargs)
761
+ self.args = args
762
+ self.kwargs = kwargs
763
+ #
764
+ self.__FStopThread = False
765
+ self.__FSheduler = TSheduler()
766
+ #endfunction
767
+
768
+ #--------------------------------------------------
769
+ # destructor
770
+ #--------------------------------------------------
771
+ def __del__(self):
772
+ """destructor"""
773
+ #beginfunction
774
+ LClassName = self.__class__.__name__
775
+ # s = '{} уничтожен'.format(LClassName)
776
+ # LUConst.LULogger.log (LULog.DEBUGTEXT, s)
777
+ #endfunction
778
+
779
+ #--------------------------------------------------
780
+ # @property Sheduler
781
+ #--------------------------------------------------
782
+ # getter
783
+ @property
784
+ def Sheduler(self) -> TSheduler:
785
+ #beginfunction
786
+ return self.__FSheduler
787
+ #endfunction
788
+
789
+
790
+ #--------------------------------------------------
791
+ # run
792
+ #--------------------------------------------------
793
+ def run(self):
794
+ """run - Запуск потока TSheduler"""
795
+ #beginfunction
796
+ s = 'run - Запуск потока TSheduler...'
797
+ LULog.LoggerAdd (LULog.LoggerTOOLS, logging.DEBUG, s)
798
+ super ().run()
799
+
800
+ if self.__FSheduler.DTEvents == 0:
801
+ self.__FSheduler.CreateNextEvent (False)
802
+ #endif
803
+ while not self.__FStopThread:
804
+ self.__FSheduler.run_Function ()
805
+ continue
806
+ #endwhile
807
+ #endfunction
808
+
809
+ #--------------------------------------------------
810
+ # StartSheduler
811
+ #--------------------------------------------------
812
+ def StartSheduler(self):
813
+ """StartSheduler"""
814
+ #beginfunction
815
+ s = 'StartSheduler...'
816
+ LULog.LoggerAdd (LULog.LoggerTOOLS, logging.DEBUG, s)
817
+ self.__FStopThread = False
818
+ self.__FSheduler.Enable = True
819
+ # self.__CreateNextEvent ()
820
+ self.start ()
821
+ #endfunction
822
+ #--------------------------------------------------
823
+ # StopSheduler
824
+ #--------------------------------------------------
825
+ def StopSheduler(self):
826
+ """StopSheduler"""
827
+ #beginfunction
828
+ s = 'StopSheduler...'
829
+ LULog.LoggerAdd (LULog.LoggerTOOLS, logging.DEBUG, s)
830
+ self.__FStopThread = True
831
+ self.__FSheduler.Enable = False
832
+ #endfunction
833
+ #endclass
834
+
835
+ # --------------------------------------------
836
+ # TShedulerTimer
837
+ # --------------------------------------------
838
+ class TShedulerTimer (threading.Timer):
839
+ """TSheduler"""
840
+ luClassName = 'TShedulerTimer'
841
+
842
+ #--------------------------------------------------
843
+ # constructor
844
+ #--------------------------------------------------
845
+ def __init__ (self, AInterval, AFunction, *args, **kwargs):
846
+ """Constructor"""
847
+ #beginfunction
848
+ super ().__init__ (AInterval, AFunction, *args, **kwargs)
849
+ self.args = args
850
+ self.kwargs = kwargs
851
+ #
852
+ self.__FSheduler = TSheduler()
853
+ #
854
+ self.__FStopThread = False
855
+ self.__FInterval = AInterval
856
+ self.__FFunction = AFunction
857
+ #endfunction
858
+
859
+ #--------------------------------------------------
860
+ # destructor
861
+ #--------------------------------------------------
862
+ def __del__ (self):
863
+ """destructor"""
864
+ #beginfunction
865
+ LClassName = self.__class__.__name__
866
+ # s = '{} уничтожен'.format (LClassName)
867
+ # LUConst.LULogger.log (LULog.DEBUGTEXT, s)
868
+ #endfunction
869
+
870
+ #--------------------------------------------------
871
+ # @property Sheduler
872
+ #--------------------------------------------------
873
+ # getter
874
+ @property
875
+ def Sheduler(self) -> TSheduler:
876
+ #beginfunction
877
+ return self.__FSheduler
878
+ #endfunction
879
+
880
+ #--------------------------------------------------
881
+ # run
882
+ #--------------------------------------------------
883
+ def run (self):
884
+ """run - Запуск таймера TShedulerTimer"""
885
+ #beginfunction
886
+ s = 'run - Запуск таймера TShedulerTimer...'
887
+ LULog.LoggerAdd (LULog.LoggerTOOLS, logging.DEBUG, s)
888
+
889
+ if self.__FSheduler.DTEvents == 0:
890
+ self.__FSheduler.CreateNextEvent (True)
891
+ #endif
892
+ while not self.__FStopThread:
893
+ self.__FSheduler.run_Function ()
894
+ continue
895
+ #endwhile
896
+ #endfunction
897
+
898
+ #--------------------------------------------------
899
+ # StartSheduler
900
+ #--------------------------------------------------
901
+ def StartSheduler (self):
902
+ """StartSheduler"""
903
+ #beginfunction
904
+ s = 'StartSheduler...'
905
+ LULog.LoggerAdd (LULog.LoggerTOOLS, logging.DEBUG, s)
906
+ self.__FStopThread = False
907
+ self.__FSheduler.Enable = True
908
+ # self.__CreateNextEvent (True)
909
+ self.start ()
910
+ #endfunction
911
+ #--------------------------------------------------
912
+ # StopSheduler
913
+ #--------------------------------------------------
914
+ def StopSheduler (self):
915
+ """StopSheduler"""
916
+ #beginfunction
917
+ s = 'StopSheduler...'
918
+ LULog.LoggerAdd (LULog.LoggerTOOLS, logging.DEBUG, s)
919
+ self.__FStopThread = True
920
+ self.__FSheduler.Enable = False
921
+ #endfunction
922
+ #endclass
923
+
924
+ #---------------------------------------------------------
925
+ # main
926
+ #---------------------------------------------------------
927
+ def main ():
928
+ #beginfunction
929
+ ...
930
+ #endfunction
931
+
932
+ #---------------------------------------------------------
933
+ #
934
+ #---------------------------------------------------------
935
+ #beginmodule
936
+ if __name__ == "__main__":
937
+ main()
938
+ #endif
939
+
940
+ #endmodule
941
+