Skip to content

Commit 82c9e4e

Browse files
committed
Comments on functionality of period grouping functions
Additionally changes name of default func to be more descriptive.
1 parent 3e4570e commit 82c9e4e

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

src/borg/archiver/prune_cmd.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,33 @@
2626
logger = create_logger()
2727

2828

29-
def unique_func():
29+
# The *_period_func group of functions create period grouping keys to group together archives falling within a certain
30+
# period. Among archives in each of these groups, only the latest (by creation timestamp) is kept.
31+
32+
33+
def unique_period_func():
3034
counter = 0
3135

32-
def inner(a):
36+
def inner(_a):
37+
"""Group archives by an incrementing counter, practically making each archive a group of 1"""
3338
nonlocal counter
3439
counter += 1
3540
return counter
3641

3742
return inner
3843

3944

40-
def default_period_func(pattern):
45+
def pattern_period_func(pattern):
4146
def inner(a):
47+
"""Group archives by extracting given strftime-pattern from their creation timestamp"""
4248
# compute in local timezone
4349
return a.ts.astimezone().strftime(pattern)
4450

4551
return inner
4652

4753

4854
def quarterly_13weekly_period_func(a):
55+
"""Group archives by extracting from their creation timestamp their ISO-8601 week numbers"""
4956
(year, week, _) = a.ts.astimezone().isocalendar() # local time
5057
if week <= 13:
5158
# Weeks containing Jan 4th to Mar 28th (leap year) or 29th- 91 (13*7)
@@ -67,6 +74,7 @@ def quarterly_13weekly_period_func(a):
6774

6875

6976
def quarterly_3monthly_period_func(a):
77+
"""Group archives by extracting month number from their creation timestamp"""
7078
lt = a.ts.astimezone() # local time
7179
if lt.month <= 3:
7280
# 1-1 to 3-31
@@ -84,18 +92,18 @@ def quarterly_3monthly_period_func(a):
8492

8593
PRUNING_PATTERNS = OrderedDict(
8694
[
87-
("within", unique_func()),
88-
("last", unique_func()),
89-
("keep", unique_func()),
90-
("secondly", default_period_func("%Y-%m-%d %H:%M:%S")),
91-
("minutely", default_period_func("%Y-%m-%d %H:%M")),
92-
("hourly", default_period_func("%Y-%m-%d %H")),
93-
("daily", default_period_func("%Y-%m-%d")),
94-
("weekly", default_period_func("%G-%V")),
95-
("monthly", default_period_func("%Y-%m")),
95+
("within", unique_period_func()),
96+
("last", unique_period_func()),
97+
("keep", unique_period_func()),
98+
("secondly", pattern_period_func("%Y-%m-%d %H:%M:%S")),
99+
("minutely", pattern_period_func("%Y-%m-%d %H:%M")),
100+
("hourly", pattern_period_func("%Y-%m-%d %H")),
101+
("daily", pattern_period_func("%Y-%m-%d")),
102+
("weekly", pattern_period_func("%G-%V")),
103+
("monthly", pattern_period_func("%Y-%m")),
96104
("quarterly_13weekly", quarterly_13weekly_period_func),
97105
("quarterly_3monthly", quarterly_3monthly_period_func),
98-
("yearly", default_period_func("%Y")),
106+
("yearly", pattern_period_func("%Y")),
99107
]
100108
)
101109

0 commit comments

Comments
 (0)