lyrpy 0.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.
- lyr/LUConsole.py +402 -0
- lyr/LUConst.py +45 -0
- lyr/LUDateTime.py +207 -0
- lyr/LUDecotators.py +418 -0
- lyr/LUDict.py +117 -0
- lyr/LUDoc.py +61 -0
- lyr/LUErrors.py +80 -0
- lyr/LUFile.py +1174 -0
- lyr/LUFileUtils.py +486 -0
- lyr/LULog.py +2249 -0
- lyr/LUNetwork.py +277 -0
- lyr/LUNumUtils.py +305 -0
- lyr/LUObjects.py +208 -0
- lyr/LUObjectsYT.py +829 -0
- lyr/LUParserARG.py +365 -0
- lyr/LUParserINI.py +371 -0
- lyr/LUParserREG.py +510 -0
- lyr/LUProc.py +110 -0
- lyr/LUQThread.py +139 -0
- lyr/LUQTimer.py +197 -0
- lyr/LUSheduler.py +940 -0
- lyr/LUStrDecode.py +223 -0
- lyr/LUStrUtils.py +633 -0
- lyr/LUSupport.py +124 -0
- lyr/LUThread.py +176 -0
- lyr/LUTimer.py +139 -0
- lyr/LUVersion.py +380 -0
- lyr/LUYouTube.py +204 -0
- lyr/LUos.py +797 -0
- lyr/LUsys.py +47 -0
- lyr/__init__.py +21 -0
- lyr/__main__.py +19 -0
- lyrpy-0.0.2.dist-info/LICENSE +19 -0
- lyrpy-0.0.2.dist-info/METADATA +19 -0
- lyrpy-0.0.2.dist-info/RECORD +37 -0
- lyrpy-0.0.2.dist-info/WHEEL +5 -0
- lyrpy-0.0.2.dist-info/top_level.txt +1 -0
lyr/LUConsole.py
ADDED
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
"""LUConsole.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
|
+
LUConsole.py
|
|
13
|
+
|
|
14
|
+
=======================================================
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
#------------------------------------------
|
|
18
|
+
# БИБЛИОТЕКИ python
|
|
19
|
+
#------------------------------------------
|
|
20
|
+
import sys
|
|
21
|
+
import enum
|
|
22
|
+
|
|
23
|
+
#------------------------------------------
|
|
24
|
+
# БИБЛИОТЕКИ сторонние
|
|
25
|
+
#------------------------------------------
|
|
26
|
+
from colorama import Fore, Back, Style
|
|
27
|
+
|
|
28
|
+
#------------------------------------------
|
|
29
|
+
# БИБЛИОТЕКИ LU
|
|
30
|
+
#------------------------------------------
|
|
31
|
+
import lyr.LUSupport as LUSupport
|
|
32
|
+
|
|
33
|
+
#------------------------------------------
|
|
34
|
+
# CONST
|
|
35
|
+
#------------------------------------------
|
|
36
|
+
sBEGIN_hex = '\x1b['
|
|
37
|
+
sBEGIN_Unicode = '\u001b'
|
|
38
|
+
sBEGIN_oct = '\33['
|
|
39
|
+
sBEGIN = sBEGIN_hex
|
|
40
|
+
sEND = 'm'
|
|
41
|
+
sRESET = sBEGIN_oct+'0'+sEND # сброс к начальным значениям
|
|
42
|
+
sRESET_1 = sBEGIN_oct+'0'+';'+sEND # вернуться к начальному стилю
|
|
43
|
+
sRESET_2 = sBEGIN_oct+sEND
|
|
44
|
+
|
|
45
|
+
sR = '\r'
|
|
46
|
+
sB = '\b' # символ возврата
|
|
47
|
+
|
|
48
|
+
sERASE_LINE = '\x1b[2K' # erase line command
|
|
49
|
+
sCURSOR_UP_ONE = '\033[K'
|
|
50
|
+
|
|
51
|
+
#--------------------------------------
|
|
52
|
+
# Изменения стиля (Styles)
|
|
53
|
+
#--------------------------------------
|
|
54
|
+
cS_BOLD = '01' # Жирный
|
|
55
|
+
cS_02 = '02' # Блеклый
|
|
56
|
+
cS_ITALIC = '03' # Курсив
|
|
57
|
+
cS_UNDERLINE = '04' # Подчёркнутый
|
|
58
|
+
cS_05 = '05' # Мигание
|
|
59
|
+
cS_06 = '06'
|
|
60
|
+
cS_REVERSE = '07' # Реверс
|
|
61
|
+
cS_08 = '08'
|
|
62
|
+
cS_09 = '09' # Зачёркнутый
|
|
63
|
+
@enum.unique
|
|
64
|
+
class cStyles(enum.Enum):
|
|
65
|
+
"""cStyles"""
|
|
66
|
+
BOLD = cS_BOLD
|
|
67
|
+
ITALIC = cS_ITALIC
|
|
68
|
+
UNDERLINE = cS_UNDERLINE
|
|
69
|
+
REVERSE = cS_REVERSE
|
|
70
|
+
#endclass
|
|
71
|
+
#--------------------------------------
|
|
72
|
+
cStylesList = [cStyles.BOLD, cStyles.ITALIC, cStyles.UNDERLINE, cStyles.REVERSE]
|
|
73
|
+
|
|
74
|
+
#--------------------------------------
|
|
75
|
+
# Изменения цвета шрифта
|
|
76
|
+
#--------------------------------------
|
|
77
|
+
cFG8_BLACK = '30' # Чёрный
|
|
78
|
+
cFG8_RED = '31' # Красный
|
|
79
|
+
cFG8_GREEN = '32' # Зелёный
|
|
80
|
+
cFG8_YELLOW = '33' # Жёлтый
|
|
81
|
+
cFG8_BLUE = '34' # Синий
|
|
82
|
+
cFG8_MAGENTA = '35' # Фиолетовый (пурпурный цвет)
|
|
83
|
+
cFG8_CYAN = '36' # Бирюзовый (голубой цвет)
|
|
84
|
+
cFG8_WHITE = '37' # Белый
|
|
85
|
+
@enum.unique
|
|
86
|
+
class cFG8(enum.Enum):
|
|
87
|
+
"""cFG8"""
|
|
88
|
+
BLACK = cFG8_BLACK
|
|
89
|
+
RED = cFG8_RED
|
|
90
|
+
GREEN = cFG8_GREEN
|
|
91
|
+
YELLOW = cFG8_YELLOW
|
|
92
|
+
BLUE = cFG8_BLUE
|
|
93
|
+
MAGENTA = cFG8_MAGENTA
|
|
94
|
+
CYAN = cFG8_CYAN
|
|
95
|
+
WHITE = cFG8_WHITE
|
|
96
|
+
#endclass
|
|
97
|
+
#--------------------------------------
|
|
98
|
+
cFG8List = [cFG8.BLACK, cFG8.RED, cFG8.GREEN, cFG8.YELLOW, cFG8.BLUE, cFG8.MAGENTA, cFG8.CYAN, cFG8.WHITE]
|
|
99
|
+
|
|
100
|
+
#--------------------------------------
|
|
101
|
+
# Изменения цвета фона
|
|
102
|
+
#--------------------------------------
|
|
103
|
+
cBG8_BLACK = '40' # Чёрный
|
|
104
|
+
cBG8_RED = '41' # Красный
|
|
105
|
+
cBG8_GREEN = '42' # Зелёный
|
|
106
|
+
cBG8_YELLOW = '43' # Жёлтый
|
|
107
|
+
cBG8_BLUE = '44' # Синий
|
|
108
|
+
cBG8_MAGENTA = '45' # Фиолетовый (пурпурный цвет)
|
|
109
|
+
cBG8_CYAN = '46' # Бирюзовый (голубой цвет)
|
|
110
|
+
cBG8_WHITE = '47' # Белый
|
|
111
|
+
@enum.unique
|
|
112
|
+
class cBG8(enum.Enum):
|
|
113
|
+
"""cBG8"""
|
|
114
|
+
BLACK = cBG8_BLACK
|
|
115
|
+
RED = cBG8_RED
|
|
116
|
+
GREEN = cBG8_GREEN
|
|
117
|
+
YELLOW = cBG8_YELLOW
|
|
118
|
+
BLUE = cBG8_BLUE
|
|
119
|
+
MAGENTA = cBG8_MAGENTA
|
|
120
|
+
CYAN = cBG8_CYAN
|
|
121
|
+
WHITE = cBG8_WHITE
|
|
122
|
+
#endclass
|
|
123
|
+
#--------------------------------------
|
|
124
|
+
cBG8List = [cBG8.BLACK, cBG8.RED, cBG8.GREEN, cBG8.YELLOW, cBG8.BLUE, cBG8.MAGENTA, cBG8.CYAN, cBG8.WHITE]
|
|
125
|
+
|
|
126
|
+
#--------------------------------------
|
|
127
|
+
# Избранные цвета 8
|
|
128
|
+
#--------------------------------------
|
|
129
|
+
# красный текст - для обозначения ошибок
|
|
130
|
+
# \033[ 01; 03; 04; 07; '__'; '__' m
|
|
131
|
+
ERROR_ESC = '\033['+'31'+'m'
|
|
132
|
+
ERROR_s = ''
|
|
133
|
+
ERROR_cFG8 = cFG8_RED
|
|
134
|
+
ERROR_cBG8 = ''
|
|
135
|
+
# жирный красный текст - для обозначения критических ошибок
|
|
136
|
+
ERROR_CRITICAL_ESC = '\033['+'01'+'31'+'m'
|
|
137
|
+
ERROR_CRITICAL_s = cS_BOLD
|
|
138
|
+
ERROR_CRITICAL_cFG8 = cFG8_RED
|
|
139
|
+
ERROR_CRITICAL_cBG8 = ''
|
|
140
|
+
# зеленый текст - успешное выполнение
|
|
141
|
+
SUCCESS_ESC = '\033['+'32'+'m'
|
|
142
|
+
SUCCESS_s = ''
|
|
143
|
+
SUCCESS_cFG8 = cFG8_GREEN
|
|
144
|
+
SUCCESS_sBG8 = ''
|
|
145
|
+
# красный курсив - текст ошибки
|
|
146
|
+
ERROR_TEXT_ESC = '\033['+'03'+'31'+'m'
|
|
147
|
+
ERROR_TEXT_s = cS_ITALIC
|
|
148
|
+
ERROR_TEXT_cFG8 = cFG8_RED
|
|
149
|
+
ERROR_TEXT_cBG8 = ''
|
|
150
|
+
# выделение основного, как будто жёлтым маркером
|
|
151
|
+
MARKER_ESC = '\033['+'43'+'m'
|
|
152
|
+
MARKER_s = ''
|
|
153
|
+
MARKER_cFG8 = ''
|
|
154
|
+
MARKER_cBG8 = cBG8_YELLOW
|
|
155
|
+
# жирный белый на черном
|
|
156
|
+
BOLD_ESC = '\033['+'01'+'31'+'40'+'m'
|
|
157
|
+
BOLD_s = cS_BOLD
|
|
158
|
+
BOLD_cFG8 = cFG8_WHITE
|
|
159
|
+
BOLD_cBG8 = cBG8_BLACK
|
|
160
|
+
|
|
161
|
+
#--------------------------------------
|
|
162
|
+
# Больше цветов: аж целых 256
|
|
163
|
+
# Совсем много цветов
|
|
164
|
+
# Этот формат не всегда поддерживается стандартными консолями.
|
|
165
|
+
#--------------------------------------
|
|
166
|
+
# Некоторые будут негодовать: "256 цветов и нет моего любимого терракотового, какой ужас!".
|
|
167
|
+
# Для таких ценителей существует формат, который уже поддерживает 24 битные цвета (3 канала RGB по 256 градаций).
|
|
168
|
+
# Для не ценителей поясню, что терракотовый кодируется как — (201, 100, 59) или #c9643b.
|
|
169
|
+
# Синтаксис в этом формате выглядит вот так:
|
|
170
|
+
# цвет текста
|
|
171
|
+
# \33[+38;2;⟨r⟩;⟨g⟩;⟨b⟩ m
|
|
172
|
+
# цвет фона
|
|
173
|
+
# \33[+48;2;⟨r⟩;⟨g⟩;⟨b⟩ m
|
|
174
|
+
#--------------------------------------
|
|
175
|
+
# \033[ 01; 03; 04; 07; 38;05;222; 48;05;22 m
|
|
176
|
+
#--------------------------------------
|
|
177
|
+
# Изменения цвета шрифта
|
|
178
|
+
#--------------------------------------
|
|
179
|
+
sFG256_BEGIN = '38;05;'
|
|
180
|
+
#--------------------------------------
|
|
181
|
+
# Изменения цвета фона
|
|
182
|
+
#--------------------------------------
|
|
183
|
+
sBG256_BEGIN = '48;05;'
|
|
184
|
+
#--------------------------------------
|
|
185
|
+
#--------------------------------------
|
|
186
|
+
# Избранные цвета 256
|
|
187
|
+
#--------------------------------------
|
|
188
|
+
sFG256_01 = '38;05;'+'15'
|
|
189
|
+
sBG256_01 = '48;05;'+'21'
|
|
190
|
+
sColor256_01 = sBEGIN_oct+cS_BOLD+';'+sFG256_01+';'+sBG256_01+sEND
|
|
191
|
+
|
|
192
|
+
#--------------------------------------
|
|
193
|
+
# colorama
|
|
194
|
+
#--------------------------------------
|
|
195
|
+
# список доступных фронтальных цветов
|
|
196
|
+
#--------------------------------------
|
|
197
|
+
FOREGROUND = [Fore.BLACK, Fore.RED, Fore.GREEN, Fore.YELLOW, Fore.BLUE, Fore.MAGENTA, Fore.CYAN, Fore.WHITE]
|
|
198
|
+
#--------------------------------------
|
|
199
|
+
# список доступных фоновых цветов
|
|
200
|
+
#--------------------------------------
|
|
201
|
+
BACKGROUND = [Back.BLACK, Back.RED, Back.GREEN, Back.YELLOW, Back.BLUE, Back.MAGENTA, Back.CYAN, Back.WHITE]
|
|
202
|
+
#
|
|
203
|
+
BRIGHTNESS = [Style.DIM, Style.NORMAL, Style.BRIGHT]
|
|
204
|
+
|
|
205
|
+
#-------------------------------------------------
|
|
206
|
+
# FormatColorStr (s, AStyles:()='', AFG8:str='', ABG8:str='', AFG256:str='', ABG256:str='', AESC:str=''):
|
|
207
|
+
#-------------------------------------------------
|
|
208
|
+
def FormatColorStr (s, **kwargs) -> str:
|
|
209
|
+
"""FormatColorStr"""
|
|
210
|
+
#beginfunction
|
|
211
|
+
AStyles:() = kwargs.get('AStyles')
|
|
212
|
+
AFG8:str = kwargs.get ('AFG8')
|
|
213
|
+
ABG8:str = kwargs.get ('ABG8')
|
|
214
|
+
AFG256:str = kwargs.get ('AFG256')
|
|
215
|
+
ABG256:str = kwargs.get ('ABG256')
|
|
216
|
+
AESC:str = kwargs.get ('AESC')
|
|
217
|
+
|
|
218
|
+
LResult = ''
|
|
219
|
+
if AESC is not None:
|
|
220
|
+
LResult = LResult + AESC + s + sRESET
|
|
221
|
+
else:
|
|
222
|
+
LStyles = LUSupport.TupleToStr (AStyles)
|
|
223
|
+
# --------------------------------------------
|
|
224
|
+
if len(LStyles) > 0 \
|
|
225
|
+
or AFG8 is not None or ABG8 is not None \
|
|
226
|
+
or AFG256 is not None or ABG256 is not None:
|
|
227
|
+
LResult = sBEGIN
|
|
228
|
+
# --------------------------------------------
|
|
229
|
+
if len (LStyles) > 0:
|
|
230
|
+
LResult = LResult + LStyles
|
|
231
|
+
# --------------------------------------------
|
|
232
|
+
if AFG8 is not None:
|
|
233
|
+
if len (LStyles) > 0:
|
|
234
|
+
LResult = LResult + ';' + AFG8
|
|
235
|
+
else:
|
|
236
|
+
LResult = LResult + AFG8
|
|
237
|
+
# --------------------------------------------
|
|
238
|
+
if ABG8 is not None:
|
|
239
|
+
if len (LStyles) > 0 or AFG8 is not None:
|
|
240
|
+
LResult = LResult + ';' + ABG8
|
|
241
|
+
else:
|
|
242
|
+
LResult = LResult + ABG8
|
|
243
|
+
# --------------------------------------------
|
|
244
|
+
if AFG8 is None and ABG8 is None:
|
|
245
|
+
if AFG256 is not None:
|
|
246
|
+
if len (LStyles) > 0:
|
|
247
|
+
LResult = LResult + ';' + sFG256_BEGIN + AFG256
|
|
248
|
+
else:
|
|
249
|
+
LResult = LResult + sFG256_BEGIN +AFG256
|
|
250
|
+
# --------------------------------------------
|
|
251
|
+
if ABG256 is not None:
|
|
252
|
+
if len (LStyles) > 0 or AFG256 is not None:
|
|
253
|
+
LResult = LResult + ';' + sBG256_BEGIN + ABG256
|
|
254
|
+
else:
|
|
255
|
+
LResult = LResult + sBG256_BEGIN + ABG256
|
|
256
|
+
# --------------------------------------------
|
|
257
|
+
if len (LResult) > 0:
|
|
258
|
+
LResult = LResult + sEND + s + sRESET
|
|
259
|
+
else:
|
|
260
|
+
LResult = s
|
|
261
|
+
return LResult
|
|
262
|
+
#endfunction
|
|
263
|
+
|
|
264
|
+
#-------------------------------------------------
|
|
265
|
+
# Write (s, AStyles:()='', AFG8:str='', ABG8:str='', AFG256:str='', ABG256:str='', AESC:str=''):
|
|
266
|
+
#-------------------------------------------------
|
|
267
|
+
def Write (s, **kwargs):
|
|
268
|
+
"""Write"""
|
|
269
|
+
#beginfunction
|
|
270
|
+
_s = s
|
|
271
|
+
if LUSupport.IsTerminal():
|
|
272
|
+
sys.stdout.write (_s)
|
|
273
|
+
else:
|
|
274
|
+
if len(kwargs):
|
|
275
|
+
__s = FormatColorStr(_s, **kwargs)
|
|
276
|
+
sys.stdout.write (__s)
|
|
277
|
+
else:
|
|
278
|
+
sys.stdout.write (_s)
|
|
279
|
+
#endif
|
|
280
|
+
#endif
|
|
281
|
+
sys.stdout.flush ()
|
|
282
|
+
#endfunction
|
|
283
|
+
|
|
284
|
+
#-------------------------------------------------
|
|
285
|
+
# WriteLN (s, AStyles:()='', AFG8:str='', ABG8:str='', AFG256:str='', ABG256:str='', AESC:str=''):
|
|
286
|
+
#-------------------------------------------------
|
|
287
|
+
def WriteLN (s, **kwargs):
|
|
288
|
+
"""WriteLN"""
|
|
289
|
+
#beginfunction
|
|
290
|
+
Write (s, **kwargs)
|
|
291
|
+
sys.stdout.write ('\n')
|
|
292
|
+
sys.stdout.flush ()
|
|
293
|
+
#endfunction
|
|
294
|
+
|
|
295
|
+
#-------------------------------------------------
|
|
296
|
+
# ClearLine
|
|
297
|
+
#-------------------------------------------------
|
|
298
|
+
def ClearLine():
|
|
299
|
+
"""ClearLine"""
|
|
300
|
+
#beginfunction
|
|
301
|
+
# if ISTerminal():
|
|
302
|
+
# sys.stdout.write ('\r')
|
|
303
|
+
# else:
|
|
304
|
+
# sys.stdout.write(sCURSOR_UP_ONE)
|
|
305
|
+
# sys.stdout.write(sERASE_LINE+'\r')
|
|
306
|
+
# #endif
|
|
307
|
+
sys.stdout.write ('\r')
|
|
308
|
+
#endfunction
|
|
309
|
+
|
|
310
|
+
#-------------------------------------------------
|
|
311
|
+
# ReadParam
|
|
312
|
+
#-------------------------------------------------
|
|
313
|
+
def ReadParam (ATitle: str, ADefault: str) -> str:
|
|
314
|
+
"""ReadParam"""
|
|
315
|
+
#beginfunction
|
|
316
|
+
WriteLN ('Введите ('+ATitle+')['+ADefault+']: ', AStyles=cS_ITALIC, AFG8=cFG8_RED, ABG8=cBG8_WHITE)
|
|
317
|
+
LReadParam: str = input ("")
|
|
318
|
+
if LReadParam == "":
|
|
319
|
+
LReadParam = ADefault
|
|
320
|
+
#endif
|
|
321
|
+
return LReadParam
|
|
322
|
+
#endfunction
|
|
323
|
+
|
|
324
|
+
#--------------------------------------------------------------------
|
|
325
|
+
# Pause
|
|
326
|
+
#--------------------------------------------------------------------
|
|
327
|
+
def Pause (Aprompt: str = ''):
|
|
328
|
+
"""Pause"""
|
|
329
|
+
#beginfunction
|
|
330
|
+
if Aprompt == '':
|
|
331
|
+
Aprompt = "Press any key to continue"
|
|
332
|
+
#endif
|
|
333
|
+
if Aprompt != '':
|
|
334
|
+
WriteLN (Aprompt, AStyles=cS_ITALIC, AFG8=cFG8_RED, ABG8=cBG8_WHITE)
|
|
335
|
+
#endif
|
|
336
|
+
x = sys.stdin.read (1)
|
|
337
|
+
#endfunction
|
|
338
|
+
|
|
339
|
+
#--------------------------------------------------------------------
|
|
340
|
+
# pause2
|
|
341
|
+
#--------------------------------------------------------------------
|
|
342
|
+
def pause2 (ADelay:int=0, Aprompt:str=''):
|
|
343
|
+
"""pause2"""
|
|
344
|
+
#beginfunction
|
|
345
|
+
LDelay = ADelay
|
|
346
|
+
LPrompt = Aprompt
|
|
347
|
+
LLoop = 0
|
|
348
|
+
LCounter = 0
|
|
349
|
+
LInterval = 0.2
|
|
350
|
+
LPause = -1
|
|
351
|
+
if Aprompt == '':
|
|
352
|
+
LPrompt = "Press any key to continue"
|
|
353
|
+
#endif
|
|
354
|
+
if LPrompt != '':
|
|
355
|
+
WriteLN(LPrompt)
|
|
356
|
+
#endif
|
|
357
|
+
if LDelay > 0:
|
|
358
|
+
LDelay = LDelay + 1
|
|
359
|
+
while LPause == -1 and LDelay > 1.0 + LInterval:
|
|
360
|
+
LDelay = LDelay - LInterval
|
|
361
|
+
#LCounter = "[" + int(LDelay) + "]:"
|
|
362
|
+
#Write (LCounter)
|
|
363
|
+
#sleep (LInterval)
|
|
364
|
+
#for loop in range (1, len(LCounter), 1):
|
|
365
|
+
# Write (chr(8)+" "+chr(8))
|
|
366
|
+
#endfor
|
|
367
|
+
#if kbhit():
|
|
368
|
+
#LPause = sys.stdin.read(1)
|
|
369
|
+
#endif
|
|
370
|
+
#endwhile
|
|
371
|
+
else:
|
|
372
|
+
LPause = sys.stdin.read(1)
|
|
373
|
+
#endif
|
|
374
|
+
#endfunction
|
|
375
|
+
|
|
376
|
+
#------------------------------------------------------
|
|
377
|
+
# PasswdFromKbd
|
|
378
|
+
#------------------------------------------------------
|
|
379
|
+
#def PasswdFromKbd(Prompt = ''):
|
|
380
|
+
##beginfunction
|
|
381
|
+
# WriteLN ("w/n", "")
|
|
382
|
+
# WriteLN ("w+/n", "$Admin_Password_Desc")
|
|
383
|
+
# PasswdFromKbd = fnGetM("*")
|
|
384
|
+
#endfunction
|
|
385
|
+
|
|
386
|
+
#------------------------------------------------------
|
|
387
|
+
# main
|
|
388
|
+
#------------------------------------------------------
|
|
389
|
+
def main ():
|
|
390
|
+
#beginfunction
|
|
391
|
+
print('main LUConsole.py ...')
|
|
392
|
+
#endfunction
|
|
393
|
+
|
|
394
|
+
#------------------------------------------
|
|
395
|
+
#
|
|
396
|
+
#------------------------------------------
|
|
397
|
+
#beginmodule
|
|
398
|
+
if __name__ == "__main__":
|
|
399
|
+
main()
|
|
400
|
+
#endif
|
|
401
|
+
|
|
402
|
+
#endmodule
|
lyr/LUConst.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""LUConst.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
|
+
LUConst.py
|
|
13
|
+
|
|
14
|
+
=======================================================
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
#------------------------------------------
|
|
18
|
+
# БИБЛИОТЕКИ python
|
|
19
|
+
#------------------------------------------
|
|
20
|
+
|
|
21
|
+
#------------------------------------------
|
|
22
|
+
# БИБЛИОТЕКИ сторонние
|
|
23
|
+
#------------------------------------------
|
|
24
|
+
|
|
25
|
+
#------------------------------------------
|
|
26
|
+
# БИБЛИОТЕКИ LU
|
|
27
|
+
#------------------------------------------
|
|
28
|
+
|
|
29
|
+
#-------------------------------------------------------------------------------
|
|
30
|
+
#
|
|
31
|
+
#-------------------------------------------------------------------------------
|
|
32
|
+
def main ():
|
|
33
|
+
#beginfunction
|
|
34
|
+
print('main LUConst.py ...')
|
|
35
|
+
#endfunction
|
|
36
|
+
|
|
37
|
+
#------------------------------------------
|
|
38
|
+
#
|
|
39
|
+
#------------------------------------------
|
|
40
|
+
#beginmodule
|
|
41
|
+
if __name__ == "__main__":
|
|
42
|
+
main()
|
|
43
|
+
#endif
|
|
44
|
+
|
|
45
|
+
#endmodule
|
lyr/LUDateTime.py
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"""LUDateTime.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
|
+
LUDateTime.py
|
|
13
|
+
|
|
14
|
+
=======================================================
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
#------------------------------------------
|
|
18
|
+
# БИБЛИОТЕКИ python
|
|
19
|
+
#------------------------------------------
|
|
20
|
+
import datetime
|
|
21
|
+
import time
|
|
22
|
+
import calendar
|
|
23
|
+
import logging
|
|
24
|
+
import platform
|
|
25
|
+
|
|
26
|
+
#------------------------------------------
|
|
27
|
+
# БИБЛИОТЕКИ сторонние
|
|
28
|
+
#------------------------------------------
|
|
29
|
+
|
|
30
|
+
#------------------------------------------
|
|
31
|
+
# БИБЛИОТЕКИ LU
|
|
32
|
+
#------------------------------------------
|
|
33
|
+
import lyr.LUSupport as LUSupport
|
|
34
|
+
|
|
35
|
+
#------------------------------------------
|
|
36
|
+
# CONST
|
|
37
|
+
#------------------------------------------
|
|
38
|
+
cFormatDateTimeLog01 = ('%H:%M:%S', '%d/%m/%Y %H:%M:%S')
|
|
39
|
+
cFormatDateTimeLog02 = ('%H%M%S', '%Y%m%d %H%M%S')
|
|
40
|
+
cFormatDateTimeLog04 = ('', '%Y%m%d%H%M%S%f')
|
|
41
|
+
cFormatDateTimeLog05 = ('%d/%m/%Y %H:%M:%S', '%H:%M:%S')
|
|
42
|
+
|
|
43
|
+
cFormatDateYYMMDD_01 = ('', '%Y%m%d')
|
|
44
|
+
cFormatDateYYMM_01 = ('', '%Y%m')
|
|
45
|
+
|
|
46
|
+
if platform.system() == 'Windows':
|
|
47
|
+
cFormatDateYYMMDD_02 = ('', r'%Y\%m\%d')
|
|
48
|
+
cFormatDateYYMM_02 = ('', r'%Y\%m')
|
|
49
|
+
#endif
|
|
50
|
+
if platform.system() == 'Linux':
|
|
51
|
+
cFormatDateYYMMDD_02 = ('', r'%Y/%m/%d')
|
|
52
|
+
cFormatDateYYMM_02 = ('', r'%Y/%m')
|
|
53
|
+
#endif
|
|
54
|
+
|
|
55
|
+
#---------------------------------------------------------------
|
|
56
|
+
# Now
|
|
57
|
+
#---------------------------------------------------------------
|
|
58
|
+
def Now () -> datetime:
|
|
59
|
+
"""Now"""
|
|
60
|
+
#beginfunction
|
|
61
|
+
LResult = datetime.datetime.now ()
|
|
62
|
+
return LResult
|
|
63
|
+
#endfunction
|
|
64
|
+
|
|
65
|
+
#---------------------------------------------------------------
|
|
66
|
+
# DateTimeStr
|
|
67
|
+
#---------------------------------------------------------------
|
|
68
|
+
def DateTimeStr (ATimeOnly: bool, ADateTime: datetime.datetime, AFormat: (), Amsecs: bool) -> str:
|
|
69
|
+
"""DateTimeStr"""
|
|
70
|
+
#beginfunction
|
|
71
|
+
msecs = ADateTime.microsecond
|
|
72
|
+
msecs = msecs // 1000
|
|
73
|
+
smsecs = LUStrUtils.AddChar('0', str(msecs), 3)
|
|
74
|
+
# ct = time.time ()
|
|
75
|
+
# msecs = int((ct - int(ct)) * 1000) + 0.0 # see gh-89047
|
|
76
|
+
if ATimeOnly:
|
|
77
|
+
if Amsecs:
|
|
78
|
+
LResult = ADateTime.strftime (AFormat[0]+' '+smsecs)
|
|
79
|
+
else:
|
|
80
|
+
LResult = ADateTime.strftime (AFormat [0])
|
|
81
|
+
#endif
|
|
82
|
+
else:
|
|
83
|
+
if Amsecs:
|
|
84
|
+
LResult = ADateTime.strftime (AFormat[1]+' '+smsecs)
|
|
85
|
+
else:
|
|
86
|
+
LResult = ADateTime.strftime (AFormat[1])
|
|
87
|
+
#endif
|
|
88
|
+
#endif
|
|
89
|
+
return LResult
|
|
90
|
+
#endfunction
|
|
91
|
+
|
|
92
|
+
#---------------------------------------------------------------
|
|
93
|
+
# DecodeDate
|
|
94
|
+
#---------------------------------------------------------------
|
|
95
|
+
def DecodeDate (ADateTime: datetime.datetime):
|
|
96
|
+
"""DecodeDate"""
|
|
97
|
+
#beginfunction
|
|
98
|
+
LDate = ADateTime
|
|
99
|
+
LTuple = (LDate.year, LDate.month, LDate.day)
|
|
100
|
+
return LTuple
|
|
101
|
+
#endfunction
|
|
102
|
+
|
|
103
|
+
#---------------------------------------------------------------
|
|
104
|
+
# EncodeDate
|
|
105
|
+
#---------------------------------------------------------------
|
|
106
|
+
def EncodeDate (AYear: int, AMonth: int, ADay: int) -> datetime.date:
|
|
107
|
+
"""EncodeDate"""
|
|
108
|
+
#beginfunction
|
|
109
|
+
return datetime.date(AYear, AMonth, ADay)
|
|
110
|
+
#endfunction
|
|
111
|
+
|
|
112
|
+
#---------------------------------------------------------------
|
|
113
|
+
# DecodeTime
|
|
114
|
+
#---------------------------------------------------------------
|
|
115
|
+
def DecodeTime (ADateTime: datetime.datetime):
|
|
116
|
+
"""DecodeTime"""
|
|
117
|
+
#beginfunction
|
|
118
|
+
LTuple = (ADateTime.hour, ADateTime.minute, ADateTime.second, ADateTime.microsecond)
|
|
119
|
+
return LTuple
|
|
120
|
+
#endfunction
|
|
121
|
+
|
|
122
|
+
#---------------------------------------------------------------
|
|
123
|
+
# EncodeTime
|
|
124
|
+
#---------------------------------------------------------------
|
|
125
|
+
def EncodeTime (AHour: int, AMin: int, ASec: int, AMSec: int) -> datetime.time:
|
|
126
|
+
"""EncodeTime"""
|
|
127
|
+
#beginfunction
|
|
128
|
+
return datetime.time(AHour, AMin, ASec, AMSec)
|
|
129
|
+
#endfunction
|
|
130
|
+
|
|
131
|
+
#---------------------------------------------------------------
|
|
132
|
+
# EncodeDateTime
|
|
133
|
+
#---------------------------------------------------------------
|
|
134
|
+
def EncodeDateTime (AYear: int, AMonth: int, ADay: int, AHour: int, AMin: int, ASec: int, AMSec: int) -> datetime.datetime:
|
|
135
|
+
"""EncodeDate"""
|
|
136
|
+
#beginfunction
|
|
137
|
+
return datetime.datetime(AYear, AMonth, ADay, AHour, AMin, ASec, AMSec)
|
|
138
|
+
#endfunction
|
|
139
|
+
|
|
140
|
+
#---------------------------------------------------------------
|
|
141
|
+
# DayOfWeek
|
|
142
|
+
#---------------------------------------------------------------
|
|
143
|
+
def DayOfWeek (ADateTime: datetime.date):
|
|
144
|
+
"""DayOfWeek"""
|
|
145
|
+
#beginfunction
|
|
146
|
+
return ADateTime.weekday()
|
|
147
|
+
#endfunction
|
|
148
|
+
|
|
149
|
+
#---------------------------------------------------------------
|
|
150
|
+
# DaysInMonth
|
|
151
|
+
#---------------------------------------------------------------
|
|
152
|
+
def DaysInMonth (AYear: int, AMonth: int):
|
|
153
|
+
"""DaysInMonth"""
|
|
154
|
+
#beginfunction
|
|
155
|
+
return monthrange (AYear, AMonth) [1]
|
|
156
|
+
#endfunction
|
|
157
|
+
|
|
158
|
+
#---------------------------------------------------------------
|
|
159
|
+
# IsLeapYear
|
|
160
|
+
#---------------------------------------------------------------
|
|
161
|
+
def IsLeapYear(AYear: int) -> bool:
|
|
162
|
+
"""IsLeapYear"""
|
|
163
|
+
#beginfunction
|
|
164
|
+
return (AYear % 4 == 0) and ((AYear % 100 != 0) or (AYear % 400 == 0))
|
|
165
|
+
#endfunction
|
|
166
|
+
|
|
167
|
+
#---------------------------------------------------------------
|
|
168
|
+
# DaysPerMonth
|
|
169
|
+
#---------------------------------------------------------------
|
|
170
|
+
def DaysPerMonth(AYear: int, AMonth: int) -> int:
|
|
171
|
+
"""DaysPerMonth"""
|
|
172
|
+
LDaysInMonth = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
|
|
173
|
+
#beginfunction
|
|
174
|
+
LResult = LDaysInMonth[AMonth]
|
|
175
|
+
if (AMonth == 2) and IsLeapYear(AYear):
|
|
176
|
+
LResult = LResult + 1
|
|
177
|
+
#endif
|
|
178
|
+
return LResult
|
|
179
|
+
#endfunction
|
|
180
|
+
|
|
181
|
+
#---------------------------------------------------------------
|
|
182
|
+
# GenerateObjectIDStr
|
|
183
|
+
#---------------------------------------------------------------
|
|
184
|
+
def GenerateObjectIDStr (AObjectID: datetime.datetime) -> str:
|
|
185
|
+
"""GenerateObjectIDStr"""
|
|
186
|
+
#beginfunction
|
|
187
|
+
LResult = DateTimeStr (False, AObjectID, cFormatDateTimeLog04,Amsecs = False)
|
|
188
|
+
return LResult
|
|
189
|
+
#endfunction
|
|
190
|
+
|
|
191
|
+
#---------------------------------------------------------------
|
|
192
|
+
# main
|
|
193
|
+
#---------------------------------------------------------------
|
|
194
|
+
def main ():
|
|
195
|
+
#beginfunction
|
|
196
|
+
print('main LUDatTime.py ...')
|
|
197
|
+
#endfunction
|
|
198
|
+
|
|
199
|
+
#------------------------------------------
|
|
200
|
+
#
|
|
201
|
+
#------------------------------------------
|
|
202
|
+
#beginmodule
|
|
203
|
+
if __name__ == "__main__":
|
|
204
|
+
main()
|
|
205
|
+
#endif
|
|
206
|
+
|
|
207
|
+
#endmodule
|