encommon 0.10.0__py3-none-any.whl → 0.11.0__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.
- encommon/config/__init__.py +3 -3
- encommon/config/config.py +17 -1
- encommon/config/files.py +3 -3
- encommon/config/logger.py +37 -6
- encommon/config/params.py +21 -1
- encommon/config/paths.py +2 -2
- encommon/config/test/test_logger.py +3 -0
- encommon/config/test/{test_common.py → test_utils.py} +3 -3
- encommon/config/{common.py → utils.py} +1 -10
- encommon/conftest.py +2 -1
- encommon/crypts/crypts.py +23 -22
- encommon/crypts/params.py +14 -1
- encommon/crypts/test/test_crypts.py +8 -20
- encommon/times/__init__.py +14 -2
- encommon/times/common.py +0 -127
- encommon/times/params.py +155 -0
- encommon/times/parse.py +5 -5
- encommon/times/test/test_params.py +64 -0
- encommon/times/test/test_parse.py +1 -1
- encommon/times/test/test_timer.py +86 -0
- encommon/times/test/test_timers.py +87 -36
- encommon/times/test/{test_common.py → test_utils.py} +3 -3
- encommon/times/test/test_window.py +101 -51
- encommon/times/test/test_windows.py +264 -0
- encommon/times/timer.py +147 -0
- encommon/times/timers.py +207 -133
- encommon/times/times.py +6 -6
- encommon/times/utils.py +148 -0
- encommon/times/window.py +124 -85
- encommon/times/windows.py +459 -0
- encommon/types/notate.py +0 -2
- encommon/utils/__init__.py +2 -2
- encommon/utils/common.py +0 -39
- encommon/utils/files.py +71 -0
- encommon/utils/paths.py +1 -1
- encommon/utils/sample.py +2 -2
- encommon/utils/test/{test_common.py → test_files.py} +2 -2
- encommon/utils/test/test_paths.py +2 -1
- encommon/version.txt +1 -1
- {encommon-0.10.0.dist-info → encommon-0.11.0.dist-info}/METADATA +1 -1
- encommon-0.11.0.dist-info/RECORD +73 -0
- encommon-0.10.0.dist-info/RECORD +0 -65
- {encommon-0.10.0.dist-info → encommon-0.11.0.dist-info}/LICENSE +0 -0
- {encommon-0.10.0.dist-info → encommon-0.11.0.dist-info}/WHEEL +0 -0
- {encommon-0.10.0.dist-info → encommon-0.11.0.dist-info}/top_level.txt +0 -0
encommon/times/window.py
CHANGED
@@ -14,7 +14,6 @@ from typing import Optional
|
|
14
14
|
|
15
15
|
from croniter import croniter
|
16
16
|
|
17
|
-
from .common import NUMERIC
|
18
17
|
from .common import PARSABLE
|
19
18
|
from .common import SCHEDULE
|
20
19
|
from .parse import parse_time
|
@@ -32,43 +31,42 @@ class Window:
|
|
32
31
|
Example
|
33
32
|
-------
|
34
33
|
>>> window = Window('* * * * *', '-4m@m')
|
35
|
-
>>> [window.
|
36
|
-
[True, True, True, True,
|
34
|
+
>>> [window.ready() for _ in range(5)]
|
35
|
+
[True, True, True, True, False]
|
37
36
|
|
38
|
-
:param
|
37
|
+
:param window: Parameters for defining scheduled time.
|
39
38
|
:param start: Determine the start for scheduling window.
|
40
39
|
:param stop: Determine the ending for scheduling window.
|
41
40
|
:param anchor: Optionally define time anchor for window.
|
42
41
|
:param delay: Period of time schedulng will be delayed.
|
43
42
|
"""
|
44
43
|
|
45
|
-
|
44
|
+
__window: SCHEDULE
|
46
45
|
__start: Times
|
47
46
|
__stop: Times
|
48
47
|
__anchor: Times
|
49
48
|
__delay: float
|
50
49
|
|
51
|
-
|
52
|
-
|
53
|
-
__walked: bool
|
50
|
+
__wlast: Times
|
51
|
+
__wnext: Times
|
54
52
|
|
55
53
|
|
56
54
|
def __init__(
|
57
55
|
self,
|
58
|
-
|
59
|
-
start: PARSABLE =
|
60
|
-
stop: PARSABLE =
|
56
|
+
window: SCHEDULE,
|
57
|
+
start: Optional[PARSABLE] = None,
|
58
|
+
stop: Optional[PARSABLE] = None,
|
59
|
+
*,
|
61
60
|
anchor: Optional[PARSABLE] = None,
|
62
|
-
delay:
|
61
|
+
delay: float = 0,
|
63
62
|
) -> None:
|
64
63
|
"""
|
65
64
|
Initialize instance for class using provided parameters.
|
66
65
|
"""
|
67
66
|
|
68
|
-
|
69
|
-
anchor = start
|
67
|
+
anchor = anchor or start
|
70
68
|
|
71
|
-
|
69
|
+
window = copy(window)
|
72
70
|
start = Times(start)
|
73
71
|
stop = Times(stop)
|
74
72
|
anchor = Times(anchor)
|
@@ -77,35 +75,31 @@ class Window:
|
|
77
75
|
assert stop > start
|
78
76
|
|
79
77
|
|
80
|
-
self.
|
78
|
+
self.__window = window
|
81
79
|
self.__start = start
|
82
80
|
self.__stop = stop
|
83
81
|
self.__anchor = anchor
|
84
82
|
self.__delay = delay
|
85
83
|
|
86
84
|
|
87
|
-
|
88
|
-
self.
|
85
|
+
wlast, wnext = (
|
86
|
+
self.__helper(anchor))
|
89
87
|
|
90
|
-
while
|
91
|
-
|
92
|
-
self.
|
88
|
+
while wnext > start:
|
89
|
+
wlast, wnext = (
|
90
|
+
self.__helper(wlast, True))
|
93
91
|
|
94
|
-
while
|
95
|
-
|
96
|
-
self.
|
92
|
+
while wnext < start:
|
93
|
+
wlast, wnext = (
|
94
|
+
self.__helper(wnext, False))
|
97
95
|
|
98
|
-
self.
|
99
|
-
self.
|
96
|
+
self.__wlast = wlast
|
97
|
+
self.__wnext = wnext
|
100
98
|
|
101
99
|
|
102
|
-
latest = stop - delay
|
103
|
-
|
104
|
-
self.__walked = winext > latest
|
105
|
-
|
106
100
|
|
107
101
|
@property
|
108
|
-
def
|
102
|
+
def window(
|
109
103
|
self,
|
110
104
|
) -> SCHEDULE:
|
111
105
|
"""
|
@@ -114,7 +108,7 @@ class Window:
|
|
114
108
|
:returns: Value for the attribute from class instance.
|
115
109
|
"""
|
116
110
|
|
117
|
-
return copy(self.
|
111
|
+
return copy(self.__window)
|
118
112
|
|
119
113
|
|
120
114
|
@property
|
@@ -166,7 +160,7 @@ class Window:
|
|
166
160
|
:returns: Value for the attribute from class instance.
|
167
161
|
"""
|
168
162
|
|
169
|
-
return self.__delay
|
163
|
+
return float(self.__delay)
|
170
164
|
|
171
165
|
|
172
166
|
@property
|
@@ -179,7 +173,7 @@ class Window:
|
|
179
173
|
:returns: Value for the attribute from class instance.
|
180
174
|
"""
|
181
175
|
|
182
|
-
return Times(self.
|
176
|
+
return Times(self.__wlast)
|
183
177
|
|
184
178
|
|
185
179
|
@property
|
@@ -192,7 +186,31 @@ class Window:
|
|
192
186
|
:returns: Value for the attribute from class instance.
|
193
187
|
"""
|
194
188
|
|
195
|
-
return Times(self.
|
189
|
+
return Times(self.__wnext)
|
190
|
+
|
191
|
+
|
192
|
+
@property
|
193
|
+
def soonest(
|
194
|
+
self,
|
195
|
+
) -> Times:
|
196
|
+
"""
|
197
|
+
Return the value for the attribute from class instance.
|
198
|
+
|
199
|
+
:returns: Value for the attribute from class instance.
|
200
|
+
"""
|
201
|
+
return Times(Times() - self.delay)
|
202
|
+
|
203
|
+
|
204
|
+
@property
|
205
|
+
def latest(
|
206
|
+
self,
|
207
|
+
) -> Times:
|
208
|
+
"""
|
209
|
+
Return the value for the attribute from class instance.
|
210
|
+
|
211
|
+
:returns: Value for the attribute from class instance.
|
212
|
+
"""
|
213
|
+
return Times(self.stop - self.delay)
|
196
214
|
|
197
215
|
|
198
216
|
@property
|
@@ -205,10 +223,10 @@ class Window:
|
|
205
223
|
:returns: Value for the attribute from class instance.
|
206
224
|
"""
|
207
225
|
|
208
|
-
return self.
|
226
|
+
return self.next >= self.latest
|
209
227
|
|
210
228
|
|
211
|
-
def
|
229
|
+
def __helper(
|
212
230
|
self,
|
213
231
|
anchor: PARSABLE,
|
214
232
|
backward: bool = False,
|
@@ -221,65 +239,74 @@ class Window:
|
|
221
239
|
:returns: Next and previous windows for schedule window.
|
222
240
|
"""
|
223
241
|
|
224
|
-
|
242
|
+
window = self.__window
|
243
|
+
|
244
|
+
if isinstance(window, str):
|
225
245
|
return window_croniter(
|
226
|
-
|
227
|
-
anchor, backward)
|
246
|
+
window, anchor, backward)
|
228
247
|
|
229
|
-
if isinstance(
|
248
|
+
if isinstance(window, dict):
|
230
249
|
return window_interval(
|
231
|
-
|
232
|
-
|
250
|
+
window, anchor, backward)
|
251
|
+
|
252
|
+
raise NotImplementedError
|
233
253
|
|
234
254
|
|
235
|
-
def
|
255
|
+
def ready( # noqa: CFQ004
|
236
256
|
self,
|
237
257
|
update: bool = True,
|
238
258
|
) -> bool:
|
239
259
|
"""
|
240
260
|
Walk the internal time using current position in schedule.
|
241
261
|
|
242
|
-
:param update:
|
262
|
+
:param update: Determines whether or not time is updated.
|
243
263
|
:returns: Boolean indicating outcome from the operation.
|
244
264
|
"""
|
245
265
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
266
|
+
wnext = self.__wnext
|
267
|
+
|
268
|
+
walked = self.walked
|
269
|
+
soonest = self.soonest
|
270
|
+
|
250
271
|
|
251
272
|
if walked is True:
|
252
273
|
return False
|
253
274
|
|
275
|
+
if wnext > soonest:
|
276
|
+
return False
|
254
277
|
|
255
|
-
_wilast, _winext = (
|
256
|
-
self.__wifunc(winext))
|
257
278
|
|
258
|
-
|
259
|
-
|
279
|
+
wlast, wnext = (
|
280
|
+
self.__helper(wnext))
|
260
281
|
|
282
|
+
if update is True:
|
283
|
+
self.__wlast = wlast
|
284
|
+
self.__wnext = wnext
|
261
285
|
|
262
|
-
if
|
286
|
+
if wnext > soonest:
|
287
|
+
return False
|
263
288
|
|
264
|
-
|
265
|
-
return not walked
|
289
|
+
return True
|
266
290
|
|
267
|
-
if winext < soonest:
|
268
|
-
return True
|
269
291
|
|
292
|
+
def update(
|
293
|
+
self,
|
294
|
+
value: Optional[PARSABLE] = None,
|
295
|
+
) -> None:
|
296
|
+
"""
|
297
|
+
Update the window from the provided parasable time value.
|
270
298
|
|
271
|
-
|
272
|
-
|
273
|
-
self.__walked = True
|
274
|
-
return False
|
299
|
+
:param value: Override the time updated for window value.
|
300
|
+
"""
|
275
301
|
|
276
|
-
|
277
|
-
|
278
|
-
self.__winext = _winext
|
279
|
-
return True
|
302
|
+
value = Times(
|
303
|
+
value or 'now')
|
280
304
|
|
305
|
+
wlast, wnext = (
|
306
|
+
self.__helper(value))
|
281
307
|
|
282
|
-
|
308
|
+
self.__wlast = wlast
|
309
|
+
self.__wnext = wnext
|
283
310
|
|
284
311
|
|
285
312
|
|
@@ -289,9 +316,9 @@ def window_croniter( # noqa: CFQ004
|
|
289
316
|
backward: bool = False,
|
290
317
|
) -> tuple[Times, Times]:
|
291
318
|
"""
|
292
|
-
Determine next and previous
|
319
|
+
Determine next and previous times for cronjob schedule.
|
293
320
|
|
294
|
-
:param
|
321
|
+
:param window: Parameters for defining scheduled time.
|
295
322
|
:param anchor: Optionally define time anchor for window.
|
296
323
|
:param backward: Optionally operate the window backward.
|
297
324
|
:returns: Next and previous windows for schedule window.
|
@@ -300,37 +327,46 @@ def window_croniter( # noqa: CFQ004
|
|
300
327
|
anchor = parse_time(anchor)
|
301
328
|
|
302
329
|
|
303
|
-
def
|
330
|
+
def _wnext(
|
304
331
|
source: datetime,
|
305
332
|
) -> datetime:
|
306
|
-
|
333
|
+
|
334
|
+
source = (
|
307
335
|
_operator(source)
|
308
336
|
.get_next())
|
309
337
|
|
338
|
+
return parse_time(source)
|
310
339
|
|
311
|
-
|
340
|
+
|
341
|
+
def _wlast(
|
312
342
|
source: datetime,
|
313
343
|
) -> datetime:
|
314
|
-
|
344
|
+
|
345
|
+
source = (
|
315
346
|
_operator(source)
|
316
347
|
.get_prev())
|
317
348
|
|
349
|
+
return parse_time(source)
|
350
|
+
|
318
351
|
|
319
352
|
def _operator(
|
320
353
|
source: datetime,
|
321
354
|
) -> croniter:
|
322
|
-
return croniter(
|
355
|
+
return croniter(
|
356
|
+
schedule, source)
|
323
357
|
|
324
358
|
|
325
|
-
|
359
|
+
wnext = _wnext(anchor)
|
326
360
|
|
327
361
|
if backward is True:
|
328
|
-
|
362
|
+
wnext = _wlast(wnext)
|
329
363
|
|
330
|
-
|
364
|
+
wlast = _wlast(wnext)
|
331
365
|
|
332
366
|
|
333
|
-
return (
|
367
|
+
return (
|
368
|
+
Times(wlast),
|
369
|
+
Times(wnext))
|
334
370
|
|
335
371
|
|
336
372
|
|
@@ -340,9 +376,9 @@ def window_interval(
|
|
340
376
|
backward: bool = False,
|
341
377
|
) -> tuple[Times, Times]:
|
342
378
|
"""
|
343
|
-
Determine next and previous
|
379
|
+
Determine next and previous times for interval schedule.
|
344
380
|
|
345
|
-
:param
|
381
|
+
:param window: Parameters for defining scheduled time.
|
346
382
|
:param anchor: Optionally define time anchor for window.
|
347
383
|
:param backward: Optionally operate the window backward.
|
348
384
|
:returns: Next and previous windows for schedule window.
|
@@ -358,11 +394,14 @@ def window_interval(
|
|
358
394
|
|
359
395
|
|
360
396
|
if backward is True:
|
361
|
-
|
362
|
-
|
397
|
+
wnext = anpoch
|
398
|
+
wlast = anpoch - seconds
|
399
|
+
|
363
400
|
else:
|
364
|
-
|
365
|
-
|
401
|
+
wnext = anpoch + seconds
|
402
|
+
wlast = anpoch
|
366
403
|
|
367
404
|
|
368
|
-
return (
|
405
|
+
return (
|
406
|
+
Times(wlast),
|
407
|
+
Times(wnext))
|