lyrpy 2024.0.4__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 (149) hide show
  1. SRC/LIB/__init__.py +21 -0
  2. SRC/LIB/lyrpy/LUConst.py +358 -0
  3. {lyrpy → SRC/LIB/lyrpy}/LUDateTime.py +2 -4
  4. {lyrpy → SRC/LIB/lyrpy}/LUDecotators.py +2 -3
  5. {lyrpy → SRC/LIB/lyrpy}/LUDict.py +0 -1
  6. {lyrpy → SRC/LIB/lyrpy}/LUDoc.py +4 -3
  7. {lyrpy → SRC/LIB/lyrpy}/LUErrors.py +0 -1
  8. {lyrpy → SRC/LIB/lyrpy}/LUFile.py +115 -61
  9. {lyrpy → SRC/LIB/lyrpy}/LUFileUtils.py +60 -45
  10. {lyrpy → SRC/LIB/lyrpy}/LULog.py +267 -191
  11. {lyrpy → SRC/LIB/lyrpy}/LUObjects.py +4 -4
  12. {lyrpy → SRC/LIB/lyrpy}/LUObjectsYT.py +39 -22
  13. {lyrpy → SRC/LIB/lyrpy}/LUParserARG.py +2 -3
  14. {lyrpy → SRC/LIB/lyrpy}/LUParserINI.py +8 -3
  15. {lyrpy → SRC/LIB/lyrpy}/LUParserREG.py +5 -1
  16. {lyrpy → SRC/LIB/lyrpy}/LUQThread.py +6 -4
  17. {lyrpy → SRC/LIB/lyrpy}/LUQTimer.py +5 -5
  18. {lyrpy → SRC/LIB/lyrpy}/LUSheduler.py +24 -23
  19. SRC/LIB/lyrpy/LUTelegram.py +428 -0
  20. {lyrpy → SRC/LIB/lyrpy}/LUThread.py +7 -6
  21. {lyrpy → SRC/LIB/lyrpy}/LUTimer.py +5 -3
  22. {lyrpy → SRC/LIB/lyrpy}/LUVersion.py +4 -1
  23. {lyrpy → SRC/LIB/lyrpy}/LUYouTube.py +6 -7
  24. {lyrpy → SRC/LIB/lyrpy}/LUos.py +13 -3
  25. SRC/LIB/lyrpy/__init__.py +21 -0
  26. {lyrpy → SRC/LIB/lyrpy}/__main__.py +20 -19
  27. SRC/__init__.py +0 -0
  28. SRC/lyrpy/LUConsole.py +402 -0
  29. SRC/lyrpy/LUConst.py +358 -0
  30. SRC/lyrpy/LUDateTime.py +205 -0
  31. SRC/lyrpy/LUDecotators.py +417 -0
  32. SRC/lyrpy/LUDict.py +116 -0
  33. SRC/lyrpy/LUDoc.py +62 -0
  34. SRC/lyrpy/LUErrors.py +79 -0
  35. SRC/lyrpy/LUFile.py +1228 -0
  36. SRC/lyrpy/LUFileUtils.py +501 -0
  37. SRC/lyrpy/LULog.py +2324 -0
  38. SRC/lyrpy/LUNetwork.py +277 -0
  39. SRC/lyrpy/LUNumUtils.py +305 -0
  40. SRC/lyrpy/LUObjects.py +208 -0
  41. SRC/lyrpy/LUObjectsYT.py +846 -0
  42. SRC/lyrpy/LUParserARG.py +364 -0
  43. SRC/lyrpy/LUParserINI.py +376 -0
  44. SRC/lyrpy/LUParserREG.py +514 -0
  45. SRC/lyrpy/LUProc.py +110 -0
  46. SRC/lyrpy/LUQThread.py +141 -0
  47. SRC/lyrpy/LUQTimer.py +197 -0
  48. SRC/lyrpy/LUSheduler.py +941 -0
  49. SRC/lyrpy/LUStrDecode.py +223 -0
  50. SRC/lyrpy/LUStrUtils.py +633 -0
  51. SRC/lyrpy/LUSupport.py +124 -0
  52. SRC/lyrpy/LUTelegram.py +428 -0
  53. SRC/lyrpy/LUThread.py +177 -0
  54. SRC/lyrpy/LUTimer.py +141 -0
  55. SRC/lyrpy/LUVersion.py +383 -0
  56. SRC/lyrpy/LUYouTube.py +203 -0
  57. SRC/lyrpy/LUos.py +807 -0
  58. lyrpy/LUConst.py → SRC/lyrpy/LUsys.py +12 -10
  59. SRC/lyrpy/__init__.py +21 -0
  60. lyrpy/__init__.py → SRC/lyrpy/__main__.py +2 -3
  61. TESTS/__init__.py +0 -0
  62. TESTS/test_lyrpy.py +4 -0
  63. TESTS/test_main.py +10 -0
  64. __SRC/LIB/__init__.py +0 -0
  65. __SRC/LIB/lyrpy/LUConsole.py +402 -0
  66. __SRC/LIB/lyrpy/LUConst.py +358 -0
  67. __SRC/LIB/lyrpy/LUDateTime.py +205 -0
  68. __SRC/LIB/lyrpy/LUDecotators.py +417 -0
  69. __SRC/LIB/lyrpy/LUDict.py +116 -0
  70. __SRC/LIB/lyrpy/LUDoc.py +62 -0
  71. __SRC/LIB/lyrpy/LUErrors.py +79 -0
  72. __SRC/LIB/lyrpy/LUFile.py +1228 -0
  73. __SRC/LIB/lyrpy/LUFileUtils.py +501 -0
  74. __SRC/LIB/lyrpy/LULog.py +2324 -0
  75. __SRC/LIB/lyrpy/LUNetwork.py +277 -0
  76. __SRC/LIB/lyrpy/LUNumUtils.py +305 -0
  77. __SRC/LIB/lyrpy/LUObjects.py +208 -0
  78. __SRC/LIB/lyrpy/LUObjectsYT.py +846 -0
  79. __SRC/LIB/lyrpy/LUParserARG.py +364 -0
  80. __SRC/LIB/lyrpy/LUParserINI.py +376 -0
  81. __SRC/LIB/lyrpy/LUParserREG.py +514 -0
  82. __SRC/LIB/lyrpy/LUProc.py +110 -0
  83. __SRC/LIB/lyrpy/LUQThread.py +141 -0
  84. __SRC/LIB/lyrpy/LUQTimer.py +197 -0
  85. __SRC/LIB/lyrpy/LUSheduler.py +941 -0
  86. __SRC/LIB/lyrpy/LUStrDecode.py +223 -0
  87. __SRC/LIB/lyrpy/LUStrUtils.py +633 -0
  88. __SRC/LIB/lyrpy/LUSupport.py +124 -0
  89. __SRC/LIB/lyrpy/LUTelegram.py +428 -0
  90. __SRC/LIB/lyrpy/LUThread.py +177 -0
  91. __SRC/LIB/lyrpy/LUTimer.py +141 -0
  92. __SRC/LIB/lyrpy/LUVersion.py +383 -0
  93. __SRC/LIB/lyrpy/LUYouTube.py +203 -0
  94. __SRC/LIB/lyrpy/LUos.py +807 -0
  95. __SRC/LIB/lyrpy/LUsys.py +47 -0
  96. __SRC/LIB/lyrpy/__init__.py +21 -0
  97. __SRC/LIB/lyrpy/__main__.py +20 -0
  98. __SRC/__init__.py +0 -0
  99. ____src/__init__.py +0 -0
  100. ____src/lyrpy/LUConsole.py +402 -0
  101. ____src/lyrpy/LUConst.py +358 -0
  102. ____src/lyrpy/LUDateTime.py +205 -0
  103. ____src/lyrpy/LUDecotators.py +417 -0
  104. ____src/lyrpy/LUDict.py +116 -0
  105. ____src/lyrpy/LUDoc.py +62 -0
  106. ____src/lyrpy/LUErrors.py +79 -0
  107. ____src/lyrpy/LUFile.py +1228 -0
  108. ____src/lyrpy/LUFileUtils.py +501 -0
  109. ____src/lyrpy/LULog.py +2324 -0
  110. ____src/lyrpy/LUNetwork.py +277 -0
  111. ____src/lyrpy/LUNumUtils.py +305 -0
  112. ____src/lyrpy/LUObjects.py +208 -0
  113. ____src/lyrpy/LUObjectsYT.py +846 -0
  114. ____src/lyrpy/LUParserARG.py +364 -0
  115. ____src/lyrpy/LUParserINI.py +376 -0
  116. ____src/lyrpy/LUParserREG.py +514 -0
  117. ____src/lyrpy/LUProc.py +110 -0
  118. ____src/lyrpy/LUQThread.py +141 -0
  119. ____src/lyrpy/LUQTimer.py +197 -0
  120. ____src/lyrpy/LUSheduler.py +941 -0
  121. ____src/lyrpy/LUStrDecode.py +223 -0
  122. ____src/lyrpy/LUStrUtils.py +633 -0
  123. ____src/lyrpy/LUSupport.py +124 -0
  124. ____src/lyrpy/LUTelegram.py +428 -0
  125. ____src/lyrpy/LUThread.py +177 -0
  126. ____src/lyrpy/LUTimer.py +141 -0
  127. ____src/lyrpy/LUVersion.py +383 -0
  128. ____src/lyrpy/LUYouTube.py +203 -0
  129. ____src/lyrpy/LUos.py +807 -0
  130. ____src/lyrpy/LUsys.py +47 -0
  131. ____src/lyrpy/__init__.py +21 -0
  132. ____src/lyrpy/__main__.py +20 -0
  133. lyrpy-2025.0.2.dist-info/METADATA +21 -0
  134. lyrpy-2025.0.2.dist-info/RECORD +145 -0
  135. {lyrpy-2024.0.4.dist-info → lyrpy-2025.0.2.dist-info}/WHEEL +1 -1
  136. lyrpy-2025.0.2.dist-info/top_level.txt +2 -0
  137. lyrpy-2024.0.4.data/data/data/text.txt +0 -1
  138. lyrpy-2024.0.4.dist-info/METADATA +0 -44
  139. lyrpy-2024.0.4.dist-info/RECORD +0 -38
  140. lyrpy-2024.0.4.dist-info/top_level.txt +0 -1
  141. {lyrpy → SRC/LIB/lyrpy}/LUConsole.py +0 -0
  142. {lyrpy → SRC/LIB/lyrpy}/LUNetwork.py +0 -0
  143. {lyrpy → SRC/LIB/lyrpy}/LUNumUtils.py +0 -0
  144. {lyrpy → SRC/LIB/lyrpy}/LUProc.py +0 -0
  145. {lyrpy → SRC/LIB/lyrpy}/LUStrDecode.py +0 -0
  146. {lyrpy → SRC/LIB/lyrpy}/LUStrUtils.py +0 -0
  147. {lyrpy → SRC/LIB/lyrpy}/LUSupport.py +0 -0
  148. {lyrpy → SRC/LIB/lyrpy}/LUsys.py +0 -0
  149. {lyrpy-2024.0.4.dist-info → lyrpy-2025.0.2.dist-info/licenses}/LICENSE +0 -0
@@ -0,0 +1,501 @@
1
+ """LUFileUtils.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
+ LUFileUtils.py
13
+
14
+ =======================================================
15
+ """
16
+
17
+ #------------------------------------------
18
+ # БИБЛИОТЕКИ python
19
+ #------------------------------------------
20
+ import os
21
+ import stat
22
+ import sys
23
+ import time
24
+ import chardet
25
+ import logging
26
+
27
+ #------------------------------------------
28
+ # БИБЛИОТЕКИ сторонние
29
+ #------------------------------------------
30
+ import datetime
31
+ import shutil
32
+ import platform
33
+ # if platform.system() == 'Windows':
34
+ # import win32api
35
+ # import win32con
36
+ # #endif
37
+
38
+ #------------------------------------------
39
+ # БИБЛИОТЕКА LU
40
+ #------------------------------------------
41
+ import lyrpy.LUErrors as LUErrors
42
+ import lyrpy.LUFile as LUFile
43
+ import lyrpy.LUStrDecode as LUStrDecode
44
+ import lyrpy.LULog as LULog
45
+ import lyrpy.LUDateTime as LUDateTime
46
+
47
+ #------------------------------------------
48
+ #CONST
49
+ #------------------------------------------
50
+ GLevel = 0
51
+ GFileCount = 0
52
+ GFileSize = 0
53
+ GDir = ''
54
+ GMask = '.*'
55
+ GDirCount = 0
56
+ GLevelMAX = sys.maxsize
57
+
58
+ #-------------------------------------------------------------------------------
59
+ # __OUTFILE
60
+ #-------------------------------------------------------------------------------
61
+ def __OUTFILE (s: str, OutFile: str):
62
+ #beginfunction
63
+ if OutFile and s != '':
64
+ if OutFile.upper () == 'CONSOLE':
65
+ print (s)
66
+ else:
67
+ LUFile.WriteStrToFile (OutFile, s + '\n')
68
+ #endif
69
+ #endif
70
+ #endfunction
71
+
72
+ #-------------------------------------------------------------------------------
73
+ # __ListFile
74
+ #-------------------------------------------------------------------------------
75
+ def __ListFile (APathSource, AMask, APathDest,
76
+ _OutFile, _Option, _FuncDir, _FuncFile) -> int:
77
+ global GFileCount
78
+ global GFileSize
79
+ #beginfunction
80
+ LFileCount = 0
81
+ with os.scandir(APathSource) as LFiles:
82
+ for LFile in LFiles:
83
+ if not LFile.is_symlink ():
84
+ if LFile.is_file() and LUFile.CheckFileNameMask (LFile.name, AMask):
85
+ #------------------------------------------------------------
86
+ # class os.DirEntry - Это файл
87
+ #------------------------------------------------------------
88
+ LBaseName = os.path.basename (LFile.path)
89
+ LFileTimeSource = LUFile.GetFileDateTime (LFile.path)[2]
90
+ LFileSizeSource = LUFile.GetFileSize (LFile.path)
91
+
92
+ GFileCount = GFileCount + 1
93
+ LFileCount = LFileCount + 1
94
+ GFileSize = GFileSize + LFileSizeSource
95
+
96
+ match _Option:
97
+ case 1 | 11:
98
+ s = f'{LFileTimeSource:%d.%m.%Y %H:%M} {LFileSizeSource:-17,d} {LBaseName:s}'
99
+ case 2 | 12:
100
+ s = f'{LFileTimeSource:%d.%m.%Y %H:%M} {LFileSizeSource:-17,d} {LBaseName:s}'
101
+ case _:
102
+ s = ''
103
+ #endmatch
104
+ __OUTFILE (s, _OutFile)
105
+
106
+ if _FuncFile:
107
+ # s = f'_FuncFile: {_FuncFile.__name__:s}'
108
+ # LULog.LoggerTOOLS_AddLevel (logging.DEBUG, s)
109
+ _FuncFile (LUFile.ExpandFileName (LFile.path), APathDest)
110
+ #endif
111
+ #endif
112
+ #endif
113
+ if LFile.is_dir (): # and (not LFile.name.startswith('.')):
114
+ #------------------------------------------------------------
115
+ # class os.DirEntry - Это каталог
116
+ #------------------------------------------------------------
117
+ LBaseName = os.path.basename (LFile.path)
118
+ LPathTimeSource = LUFile.GetDirDateTime (LFile.path) [2]
119
+
120
+ match _Option:
121
+ case 1 | 11:
122
+ s = f'{LPathTimeSource:%d.%m.%Y %H:%M} {' <DIR>':17s} {LBaseName:s}'
123
+ case 2 | 12:
124
+ s = f'{LPathTimeSource:%d.%m.%Y %H:%M} {' <DIR>':17s} {LBaseName:s}'
125
+ case _:
126
+ s = ''
127
+ #endmatch
128
+ __OUTFILE (s, _OutFile)
129
+
130
+ #------------------------------------------------------------
131
+ #
132
+ #------------------------------------------------------------
133
+ if _FuncDir:
134
+ # s = f'_FuncDir: {_FuncDir.__name__:s}'
135
+ # LULog.LoggerTOOLS_AddLevel (logging.DEBUG, s)
136
+ # _FuncDir (LUFile.ExpandFileName (LFile.path), APathDest)
137
+ pass
138
+ #endif
139
+ #endif
140
+ #endfor
141
+ #endwith
142
+ return LFileCount
143
+ #endfunction
144
+
145
+ #-------------------------------------------------------------------------------
146
+ # __ListDir
147
+ #-------------------------------------------------------------------------------
148
+ def __ListDir (APathSource, AMask, ASubdir, APathDest,
149
+ _OutFile, _Option, _FuncDir, _FuncFile):
150
+ #beginfunction
151
+ global GLevel
152
+ global GFileCount
153
+ global GFileSize
154
+
155
+ #------------------------------------------------------------
156
+ # Dir
157
+ #------------------------------------------------------------
158
+ LBaseName = os.path.basename (APathSource)
159
+ LPathTimeSource = LUFile.GetDirDateTime (APathSource)[2]
160
+
161
+ GFileCount = 0
162
+ GFileSize = 0
163
+
164
+ #------------------------------------------------------------
165
+ # список файлов в каталоге
166
+ #------------------------------------------------------------
167
+ if _Option != 0:
168
+ s = f"\nСодержимое папки {APathSource:s}\n"
169
+ __OUTFILE (s, _OutFile)
170
+ #endif
171
+ match _Option:
172
+ case 1 | 11:
173
+ s = f'{LPathTimeSource:%d.%m.%Y %H:%M} {' <DIR>':17s} {LBaseName:s}'
174
+ case 2 | 12:
175
+ s = f'{LPathTimeSource:%d.%m.%Y %H:%M} {' <DIR>':17s} {LBaseName:s}'
176
+ case _:
177
+ s = ''
178
+ #endmatch
179
+ __OUTFILE (s, _OutFile)
180
+
181
+ # LFileCount = __ListFile (APathSource, AMask, APathDest, _OutFile, _Option, _FuncDir, _FuncFile)
182
+ LFileCount = __ListFile (APathSource, AMask, APathDest, _OutFile, _Option, None, _FuncFile)
183
+
184
+ match _Option:
185
+ case 1 | 11:
186
+ s = f'{GFileCount:16d} файлов {GFileSize:16,d} байт'
187
+ case 2 | 12:
188
+ s = f'{GFileCount:16d} файлов {GFileSize:16,d} байт'
189
+ case _:
190
+ s = ''
191
+ #endmatch
192
+ __OUTFILE (s, _OutFile)
193
+ #------------------------------------------------------------
194
+
195
+ with os.scandir(APathSource) as LFiles:
196
+ for LFile in LFiles:
197
+ if not LFile.is_symlink():
198
+ if LFile.is_dir (): # and (not LFile.name.startswith('.')):
199
+ #------------------------------------------------------------
200
+ #
201
+ #------------------------------------------------------------
202
+ if _FuncDir:
203
+ # s = f'_FuncDir: {_FuncDir.__name__:s}'
204
+ # LULog.LoggerTOOLS_AddLevel (logging.DEBUG, s)
205
+ _FuncDir (LUFile.ExpandFileName (LFile.path), APathDest)
206
+ #endif
207
+
208
+ #------------------------------------------------------------
209
+ # class os.DirEntry - Это каталог
210
+ #------------------------------------------------------------
211
+ # LBaseName = os.path.basename (LFile.path)
212
+ # LPathTimeSource = LUFile.GetFileDateTime (LFile.path)[2]
213
+
214
+ #------------------------------------------------------------
215
+ # на следующий уровень
216
+ #------------------------------------------------------------
217
+ if ASubdir:
218
+ GLevel = GLevel + 1
219
+ if APathDest != '':
220
+ LPathDest = os.path.join (APathDest, LFile.name)
221
+ else:
222
+ LPathDest = ''
223
+ #endif
224
+ __ListDir (LFile.path, AMask, ASubdir, LPathDest, _OutFile, _Option, _FuncDir, _FuncFile)
225
+ #endif
226
+ #endif
227
+ #endif
228
+ #endfor
229
+ GLevel = GLevel - 1
230
+ #endwith
231
+ #endfunction
232
+
233
+ #-------------------------------------------------------------------------------
234
+ # BacFiles
235
+ #-------------------------------------------------------------------------------
236
+ def BacFiles (APathSource, AMask, ASubDir, APathDest,
237
+ _OutFile, _Option, _ASync: bool=False):
238
+
239
+ #-------------------------------------------------------------------------------
240
+ # FuncDir
241
+ #-------------------------------------------------------------------------------
242
+ def FuncDir (_APathSource: str, _APathDest: str):
243
+ #beginfunction
244
+ LPathSource = _APathSource
245
+ LBaseName = os.path.basename (_APathSource)
246
+ LPathDest = os.path.join (_APathDest, LBaseName)
247
+ # LPathTimeSource = LUFile.GetFileDateTime (_APathSource) [2]
248
+ Lattr = LUFile.GetFileAttr (_APathSource)
249
+ if not _ASync:
250
+ if not LUFile.DirectoryExists(LPathDest):
251
+ s = f'Create {LPathDest:s} ...'
252
+ LULog.LoggerAdd (LULog.LoggerTOOLS, logging.DEBUG, s)
253
+ LUFile.ForceDirectories(LPathDest)
254
+ LUFile.SetFileAttr(LPathDest, Lattr, False)
255
+ #endif
256
+ else:
257
+ if not LUFile.DirectoryExists(LPathDest):
258
+ s = f'Delete {LPathSource:s} ...'
259
+ LULog.LoggerAdd (LULog.LoggerTOOLS, logging.DEBUG, s)
260
+ LUFile.DeleteDirectoryTree(LPathSource)
261
+ #endif
262
+ #endif
263
+ #endfunction
264
+
265
+ #-------------------------------------------------------------------------------
266
+ # FuncFile
267
+ #-------------------------------------------------------------------------------
268
+ def FuncFile (AFileName: str, _APathDest: str):
269
+ #beginfunction
270
+ LFileNameSource = AFileName
271
+ LBaseName = os.path.basename (AFileName)
272
+ # LFileTimeSource = LUFile.GetFileDateTime (AFileName) [2]
273
+ LFileSizeSource = LUFile.GetFileSize (AFileName)
274
+ LFileAttrSource = LUFile.GetFileAttr (AFileName)
275
+
276
+ LFileNameDest = os.path.join (_APathDest, LBaseName)
277
+
278
+ #--------------------------------------------------------------------
279
+ LResult = LUFile.COMPAREFILETIMES(LFileNameSource, LFileNameDest)
280
+ #--------------------------------------------------------------------
281
+ # Check Result
282
+ #--------------------------------------------------------------------
283
+ LCopy = False
284
+ LDelete = False
285
+
286
+ match LResult:
287
+ case -3:
288
+ # -3 File2 could not be opened (see @ERROR for more information).
289
+ # LFileSizeDest = 0
290
+ # LFileTimeDest = 0
291
+ LDelete = False
292
+ LCopy = True
293
+ if _ASync:
294
+ LCopy = False
295
+ LDelete = True
296
+ #endif
297
+ case -2:
298
+ # -2 File1 could not be opened (see @ERROR for more information).
299
+ LDelete = False
300
+ LCopy = False
301
+ case -1:
302
+ # -1 File1 is older than file2.
303
+ LDelete = False
304
+ LCopy = False
305
+ case 0:
306
+ # 0 File1 and file2 have the same date and time.
307
+ LDelete = False
308
+ LCopy = False
309
+ # LFileTimeDest = LUFile.GetFileDateTime (LFileNameDest) [2]
310
+ LFileSizeDest = LUFile.GetFileSize (LFileNameDest)
311
+ # LFileAttrDest = LUFile.GetFileAttr (LFileNameDest)
312
+ if LFileSizeSource != LFileSizeDest:
313
+ LCopy = True
314
+ else:
315
+ LUFile.SetFileAttr(LFileNameDest, LFileAttrSource, False)
316
+ # shutil.copystat (LFileNameSource, LFileNameDest)
317
+ #endif
318
+ case 1:
319
+ # 1 File1 is more recent than file2.
320
+ LDelete = False
321
+ LCopy = True
322
+ #endmatch
323
+
324
+ #--------------------------------------------------------------------
325
+ # Copy
326
+ #--------------------------------------------------------------------
327
+ if LCopy == True:
328
+ s = f'Copy {LFileNameSource:s} -> {LFileNameDest:s} ...'
329
+ LULog.LoggerAdd (LULog.LoggerTOOLS, logging.DEBUG, s)
330
+ LUFile.FileCopy (LFileNameSource, LFileNameDest, True)
331
+ #endif
332
+
333
+ #--------------------------------------------------------------------
334
+ # Delete
335
+ #--------------------------------------------------------------------
336
+ if LDelete == True:
337
+ s = f'Delete {LFileNameSource:s} ...'
338
+ LULog.LoggerAdd (LULog.LoggerTOOLS, logging.DEBUG, s)
339
+ LUFile.FileDelete (LFileNameSource)
340
+ #endif
341
+ #endfunction
342
+
343
+ #beginfunction
344
+ if (APathSource != "") and (APathDest != ""):
345
+ # LBaseName = os.path.basename (APathSource)
346
+ LPathDest = APathDest
347
+ Ls = f'BacFiles: {APathSource:s} {AMask:s} => {APathDest:s} ...'
348
+ LULog.LoggerAdd (LULog.LoggerTOOLS, logging.DEBUG, Ls)
349
+ __ListDir (APathSource, AMask, ASubDir, LPathDest, _OutFile, _Option, FuncDir, FuncFile)
350
+ #endif
351
+ #endfunction
352
+
353
+ #-------------------------------------------------------------------------------
354
+ # SyncFiles
355
+ #-------------------------------------------------------------------------------
356
+ def SyncFiles (APathSource, AMask, APathDest, _OutFile, _Option):
357
+ #beginfunction
358
+ s = f'SyncFiles: {APathSource:s} {AMask:s} => {APathDest:s} ...'
359
+ LULog.LoggerAdd (LULog.LoggerTOOLS, LULog.TEXT, s)
360
+
361
+ BacFiles (APathSource, AMask, True, APathDest, _OutFile, _Option, False)
362
+ BacFiles (APathDest, AMask, True, APathSource, _OutFile, _Option, True)
363
+ #endfunction
364
+
365
+ #-------------------------------------------------------------------------------
366
+ # DirFiles
367
+ #-------------------------------------------------------------------------------
368
+ def DirFiles (APathSource, AMask, ASubDir,
369
+ _OutFile, _Option, _FuncDir, _FuncFile):
370
+ #beginfunction
371
+ if APathSource != "":
372
+ s = f'DirFiles: {APathSource:s} {AMask:s} ...'
373
+ LULog.LoggerAdd (LULog.LoggerTOOLS, LULog.TEXT, s)
374
+ __ListDir(APathSource, AMask, ASubDir, '', _OutFile, _Option, _FuncDir, _FuncFile)
375
+ #endif
376
+ #endfunction
377
+
378
+ #-------------------------------------------------------------------------------
379
+ # __FakeFile
380
+ #-------------------------------------------------------------------------------
381
+ def __FakeFile (APathSource,
382
+ _OutFile, _Option, _FuncDir, _FuncFile):
383
+ global GLevel
384
+ #beginfunction
385
+ for LFileCount in range(0, 2):
386
+ s = f'FakeFile_{str(GLevel+1):s}_{str(LFileCount+1):s}.txt'
387
+ LFileName = os.path.join (APathSource, s)
388
+
389
+ LHahdle = LUFile.OpenTextFile(LFileName, '')
390
+ LUFile.WriteTextFile(LHahdle, 'test')
391
+ LUFile.WriteTextFile(LHahdle, 'тест')
392
+ LUFile.CloseTextFile(LHahdle)
393
+
394
+ if _FuncFile:
395
+ # s = f'_FuncFile: {_FuncFile.__name__:s}'
396
+ # LULog.LoggerTOOLS_AddLevel (logging.DEBUG, s)
397
+ _FuncFile (LFileName)
398
+ #endif
399
+ #endfor
400
+ #endfunction
401
+
402
+ #-------------------------------------------------------------------------------
403
+ # __FakeDir
404
+ #-------------------------------------------------------------------------------
405
+ def __FakeDir (APathSource,
406
+ _OutFile, _Option, _FuncDir, _FuncFile):
407
+ #beginfunction
408
+ global GLevel
409
+
410
+ #------------------------------------------------------------
411
+ # Dir
412
+ #------------------------------------------------------------
413
+ # LBaseName = os.path.basename (APathSource)
414
+ s = LUFile.ExpandFileName (APathSource)
415
+ LULog.LoggerAdd (LULog.LoggerTOOLS, LULog.TEXT, s)
416
+
417
+ #------------------------------------------------------------
418
+ #
419
+ #------------------------------------------------------------
420
+ if _FuncDir:
421
+ # s = f'_FuncDir: {_FuncDir.__name__:s}'
422
+ # LULog.LoggerTOOLS_AddLevel (logging.DEBUG, s)
423
+ _FuncDir (LUFile.ExpandFileName (APathSource))
424
+ #endif
425
+
426
+ __FakeFile (APathSource, _OutFile, _Option, _FuncDir, _FuncFile)
427
+
428
+ #------------------------------------------------------------
429
+ # на следующий уровень
430
+ #------------------------------------------------------------
431
+ if GLevel < 3:
432
+ for LDirCount in range (0, 2):
433
+ s = f'FakeDir_{str(GLevel+1):s}_{str(LDirCount+1):s}'
434
+ LPathSource = os.path.join (APathSource, s)
435
+ LUFile.ForceDirectories(LPathSource)
436
+
437
+ GLevel = GLevel + 1
438
+ __FakeDir(LPathSource, _OutFile, _Option, _FuncDir, _FuncFile)
439
+ #endfor
440
+ #endif
441
+ GLevel = GLevel - 1
442
+ #endfunction
443
+
444
+ #-------------------------------------------------------------------------------
445
+ # FakeFiles
446
+ #-------------------------------------------------------------------------------
447
+ def FakeFiles (APathSource,
448
+ _OutFile, _Option, _FuncDir, _FuncFile):
449
+ #beginfunction
450
+ if APathSource != "":
451
+ s = f'FakeFiles: {APathSource:s} ...'
452
+ LULog.LoggerAdd (LULog.LoggerTOOLS, LULog.TEXT, s)
453
+ __FakeDir(APathSource, _OutFile, _Option, _FuncDir, _FuncFile)
454
+ #endif
455
+ #endfunction
456
+
457
+ #-------------------------------------------------------------------------------
458
+ # DelFiles
459
+ #-------------------------------------------------------------------------------
460
+ def DelFiles (APathSource, AMask, ASubDir, _OutFile, _Option, _Older: int):
461
+ #beginfunction
462
+
463
+ #-------------------------------------------------------------------------------
464
+ # DelFile
465
+ #-------------------------------------------------------------------------------
466
+ def DelFile (AFileName: str):
467
+ #beginfunction
468
+ LDay = LUDateTime.Now ()
469
+ # print(LUFile.GetFileDateTime (AFileName))
470
+ LFileTimeSource = LUFile.GetFileDateTime (AFileName) [2]
471
+ # print ((LDay - LFileTimeSource).days)
472
+ if (LDay - LFileTimeSource).days > _Older:
473
+ s = f'Delete {AFileName:s} ...'
474
+ LULog.LoggerAdd (LULog.LoggerTOOLS, logging.DEBUG, s)
475
+ LUFile.FileDelete(AFileName)
476
+ #endif
477
+ #endfunction
478
+
479
+ #beginfunction
480
+ if APathSource != "":
481
+ s = f'DelFiles: {APathSource:s} {AMask:s} ...'
482
+ LULog.LoggerAdd (LULog.LoggerTOOLS, LULog.TEXT, s)
483
+ __ListDir (APathSource, AMask, ASubDir, '', _OutFile, _Option, None, DelFile)
484
+ #endif
485
+ #endfunction
486
+
487
+ #------------------------------------------
488
+ def main ():
489
+ #beginfunction
490
+ print('main LUFileUtils.py ...')
491
+ #endfunction
492
+
493
+ #------------------------------------------
494
+ #
495
+ #------------------------------------------
496
+ #beginmodule
497
+ if __name__ == "__main__":
498
+ main()
499
+ #endif
500
+
501
+ #endmodule