encommon 0.10.0__py3-none-any.whl → 0.11.1__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.
Files changed (45) hide show
  1. encommon/config/__init__.py +3 -3
  2. encommon/config/config.py +19 -7
  3. encommon/config/files.py +3 -3
  4. encommon/config/logger.py +39 -7
  5. encommon/config/params.py +21 -1
  6. encommon/config/paths.py +2 -2
  7. encommon/config/test/test_logger.py +4 -1
  8. encommon/config/test/{test_common.py → test_utils.py} +3 -3
  9. encommon/config/{common.py → utils.py} +1 -10
  10. encommon/conftest.py +2 -1
  11. encommon/crypts/crypts.py +68 -18
  12. encommon/crypts/params.py +14 -1
  13. encommon/crypts/test/test_crypts.py +56 -13
  14. encommon/times/__init__.py +14 -2
  15. encommon/times/common.py +0 -127
  16. encommon/times/params.py +155 -0
  17. encommon/times/parse.py +5 -5
  18. encommon/times/test/test_params.py +64 -0
  19. encommon/times/test/test_parse.py +1 -1
  20. encommon/times/test/test_timer.py +86 -0
  21. encommon/times/test/test_timers.py +81 -41
  22. encommon/times/test/{test_common.py → test_utils.py} +3 -3
  23. encommon/times/test/test_window.py +101 -51
  24. encommon/times/test/test_windows.py +250 -0
  25. encommon/times/timer.py +147 -0
  26. encommon/times/timers.py +217 -130
  27. encommon/times/times.py +6 -6
  28. encommon/times/utils.py +148 -0
  29. encommon/times/window.py +124 -85
  30. encommon/times/windows.py +472 -0
  31. encommon/types/notate.py +0 -2
  32. encommon/utils/__init__.py +2 -2
  33. encommon/utils/common.py +0 -39
  34. encommon/utils/files.py +71 -0
  35. encommon/utils/paths.py +1 -1
  36. encommon/utils/sample.py +2 -2
  37. encommon/utils/test/{test_common.py → test_files.py} +2 -2
  38. encommon/utils/test/test_paths.py +2 -1
  39. encommon/version.txt +1 -1
  40. {encommon-0.10.0.dist-info → encommon-0.11.1.dist-info}/METADATA +1 -1
  41. encommon-0.11.1.dist-info/RECORD +73 -0
  42. encommon-0.10.0.dist-info/RECORD +0 -65
  43. {encommon-0.10.0.dist-info → encommon-0.11.1.dist-info}/LICENSE +0 -0
  44. {encommon-0.10.0.dist-info → encommon-0.11.1.dist-info}/WHEEL +0 -0
  45. {encommon-0.10.0.dist-info → encommon-0.11.1.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.walk() for _ in range(6)]
36
- [True, True, True, True, True, False]
34
+ >>> [window.ready() for _ in range(5)]
35
+ [True, True, True, True, False]
37
36
 
38
- :param schedule: Parameters for defining scheduled time.
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
- __schedule: SCHEDULE
44
+ __window: SCHEDULE
46
45
  __start: Times
47
46
  __stop: Times
48
47
  __anchor: Times
49
48
  __delay: float
50
49
 
51
- __wilast: Times
52
- __winext: Times
53
- __walked: bool
50
+ __wlast: Times
51
+ __wnext: Times
54
52
 
55
53
 
56
54
  def __init__(
57
55
  self,
58
- schedule: SCHEDULE,
59
- start: PARSABLE = 'now',
60
- stop: PARSABLE = '3000-01-01',
56
+ window: SCHEDULE,
57
+ start: Optional[PARSABLE] = None,
58
+ stop: Optional[PARSABLE] = None,
59
+ *,
61
60
  anchor: Optional[PARSABLE] = None,
62
- delay: NUMERIC = 0,
61
+ delay: float = 0,
63
62
  ) -> None:
64
63
  """
65
64
  Initialize instance for class using provided parameters.
66
65
  """
67
66
 
68
- if anchor is None:
69
- anchor = start
67
+ anchor = anchor or start
70
68
 
71
- schedule = copy(schedule)
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.__schedule = schedule
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
- wilast, winext = (
88
- self.__wifunc(anchor))
85
+ wlast, wnext = (
86
+ self.__helper(anchor))
89
87
 
90
- while winext > start:
91
- wilast, winext = (
92
- self.__wifunc(wilast, True))
88
+ while wnext > start:
89
+ wlast, wnext = (
90
+ self.__helper(wlast, True))
93
91
 
94
- while winext < start:
95
- wilast, winext = (
96
- self.__wifunc(winext, False))
92
+ while wnext < start:
93
+ wlast, wnext = (
94
+ self.__helper(wnext, False))
97
95
 
98
- self.__wilast = wilast
99
- self.__winext = winext
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 schedule(
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.__schedule)
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.__wilast)
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.__winext)
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.__walked
226
+ return self.next >= self.latest
209
227
 
210
228
 
211
- def __wifunc(
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
- if isinstance(self.__schedule, str):
242
+ window = self.__window
243
+
244
+ if isinstance(window, str):
225
245
  return window_croniter(
226
- self.__schedule,
227
- anchor, backward)
246
+ window, anchor, backward)
228
247
 
229
- if isinstance(self.__schedule, dict):
248
+ if isinstance(window, dict):
230
249
  return window_interval(
231
- self.__schedule,
232
- anchor, backward)
250
+ window, anchor, backward)
251
+
252
+ raise NotImplementedError
233
253
 
234
254
 
235
- def walk( # noqa: CFQ004
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: Update internal scheduling for operation.
262
+ :param update: Determines whether or not time is updated.
243
263
  :returns: Boolean indicating outcome from the operation.
244
264
  """
245
265
 
246
- stop = self.__stop
247
- delay = self.__delay
248
- winext = self.__winext
249
- walked = self.__walked
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
- soonest = Times() - delay
259
- latest = stop - delay
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 update is False:
286
+ if wnext > soonest:
287
+ return False
263
288
 
264
- if _winext > latest:
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
- elif _winext > latest:
272
- self.__wilast = _wilast
273
- self.__walked = True
274
- return False
299
+ :param value: Override the time updated for window value.
300
+ """
275
301
 
276
- elif self.__winext < soonest:
277
- self.__wilast = _wilast
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
- return False
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 windows for cronjob schedule.
319
+ Determine next and previous times for cronjob schedule.
293
320
 
294
- :param schedule: Parameters for defining scheduled time.
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 _winext(
330
+ def _wnext(
304
331
  source: datetime,
305
332
  ) -> datetime:
306
- return parse_time(
333
+
334
+ source = (
307
335
  _operator(source)
308
336
  .get_next())
309
337
 
338
+ return parse_time(source)
310
339
 
311
- def _wilast(
340
+
341
+ def _wlast(
312
342
  source: datetime,
313
343
  ) -> datetime:
314
- return parse_time(
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(schedule, source)
355
+ return croniter(
356
+ schedule, source)
323
357
 
324
358
 
325
- winext = _winext(anchor)
359
+ wnext = _wnext(anchor)
326
360
 
327
361
  if backward is True:
328
- winext = _wilast(winext)
362
+ wnext = _wlast(wnext)
329
363
 
330
- wilast = _wilast(winext)
364
+ wlast = _wlast(wnext)
331
365
 
332
366
 
333
- return (Times(wilast), Times(winext))
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 windows for interval schedule.
379
+ Determine next and previous times for interval schedule.
344
380
 
345
- :param schedule: Parameters for defining scheduled time.
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
- winext = anpoch
362
- wilast = anpoch - seconds
397
+ wnext = anpoch
398
+ wlast = anpoch - seconds
399
+
363
400
  else:
364
- winext = anpoch + seconds
365
- wilast = anpoch
401
+ wnext = anpoch + seconds
402
+ wlast = anpoch
366
403
 
367
404
 
368
- return (Times(wilast), Times(winext))
405
+ return (
406
+ Times(wlast),
407
+ Times(wnext))