Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
improve error reporting.
add support for 3monthly and 13weekly prune intervals
  • Loading branch information
Ken Kundert authored and Ken Kundert committed Jan 9, 2025
1 parent af4f9b9 commit e56b5c3
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 35 deletions.
14 changes: 6 additions & 8 deletions assimilate/assimilate.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
get_available_configs,
get_config_dir,
read_settings,
report_setting_error
)
from .hooks import Hooks
from .patterns import (
Expand Down Expand Up @@ -160,16 +161,13 @@ def initialize(self, name, settings):
sub_configs = composite_configs[name].split()
unknown_configs = set(sub_configs) - known_configs
if unknown_configs:
raise Error(
report_setting_error(
"composite_configs",
f"unknown {plural(unknown_configs):config/s}:",
f"{', '.join(sorted(unknown_configs))}.",
culprit=(name, "composite_configs")
)
if name in sub_configs:
raise Error(
"recursion is not allowed.",
culprit=(name, "composite_configs")
)
report_setting_error("composite_configs", "recursion is not allowed.")
else:
sub_configs = [name]

Expand Down Expand Up @@ -366,9 +364,9 @@ def check(self):

self.working_dir = to_path(self.settings.get("working_dir", "/"))
if not self.working_dir.exists():
raise Error(f"{self.working_dir!s} not found.", culprit="working_dir")
report_setting_error("working_dir", f"{self.working_dir!s} not found.")
if not self.working_dir.is_absolute():
raise Error("must be an absolute path.", culprit="working_dir")
report_setting_error("working_dir", "must be an absolute path.")

# handle errors {{{2
def fail(self, *msg, cmd='❬unknown❭'):
Expand Down
14 changes: 8 additions & 6 deletions assimilate/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
set_shlib_prefs(use_inform=True, log_cmd=True)
Quantity.set_prefs(ignore_sf=True, spacer='')

prune_intervals = """
within last minutely hourly daily weekly monthly 3monthly 13weekly yearly
""".split()

# Utilities {{{1
# title() {{{2
def title(text):
Expand Down Expand Up @@ -902,7 +906,7 @@ def run(cls, command, args, settings, options):
for path in must_exist:
if not path.exists():
raise Error(
"does not exist, perform setup and restart.",
"does not exist; perform setup and restart.",
culprit = ("must_exist", path),
)

Expand Down Expand Up @@ -1346,8 +1350,7 @@ def save_message(cmd):
squeeze_cmd = 'compact'

# disable squeeze check if there are no prune settings
intervals = "within last minutely hourly daily weekly monthly yearly"
prune_settings = [("keep_" + s) for s in intervals.split()]
prune_settings = [("keep_" + s) for s in prune_intervals]
if not any(settings.value(s) for s in prune_settings):
last_run['squeeze'] = None

Expand Down Expand Up @@ -2138,12 +2141,11 @@ def run(cls, command, args, settings, options):
fast = cmdline["--fast"]

# checking the settings
intervals = "within last minutely hourly daily weekly monthly yearly"
prune_settings = [("keep_" + s) for s in intervals.split()]
prune_settings = [("keep_" + s) for s in prune_intervals]
if not any(settings.value(s) for s in prune_settings):
prune_settings = conjoin(prune_settings, ", or ")
raise Error(
"No prune settings available.",
"no prune settings available.",
codicil = f"At least one of {prune_settings} must be specified.",
wrap = True,
)
Expand Down
36 changes: 31 additions & 5 deletions assimilate/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,18 @@ def add_setting(name, desc, validator):
desc = "number of monthly archives to keep",
validator = as_integer,
),
keep_3monthly = dict(
cmds = ["prune"],
arg = "NUM",
desc = "number of 3 month quarter archives to keep",
validator = as_integer,
),
keep_13weekly = dict(
cmds = ["prune"],
arg = "NUM",
desc = "number of 13 week quarter archives to keep",
validator = as_integer,
),
keep_yearly = dict(
cmds = ["prune"],
arg = "NUM",
Expand Down Expand Up @@ -697,14 +709,28 @@ def get_available_configs(keep_shared=False):

# report_setting_error() {{{2
keymaps = defaultdict(dict)
def report_setting_error(keys, error, codicil=None):
paths = reversed(keymaps.keys())
for path in paths:
def report_setting_error(keys, *args, **kwargs):
if is_str(keys):
keys = tuple(keys.split())
if 'codicil' in kwargs:
codicil = kwargs.pop('codicil')
if is_str(codicil):
codicil = tuple(codicil.split())
else:
codicil = ()

for path in reversed(keymaps.keys()):
keymap = keymaps[path]
loc = keymap.get(keys)
if loc:
raise Error(error, culprit=(path,)+keys, codicil=(codicil, loc.as_line()))
raise AssertionError # this should not happen with a user specified value
culprit = (path,) + keys
raise Error(
*args,
culprit=(path,)+keys,
codicil=codicil + (loc.as_line(),),
**kwargs
)
raise Error(*args, culprit=keys, codicil=codicil **kwargs)


# read_config() {{{2
Expand Down
18 changes: 6 additions & 12 deletions doc/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Releases
*Assimilate* is suitable for use with *BorgBackup* version 2.0 or later. For
earlier versions of *Borg* you should use Emborg_.

.. important:
.. important::

*Assimilate* is designed to work with *Borg Backup v2.0*. *Borg 2.0* is
currently in beta release, so neither *Borg* nor *Assimilate* should be used
Expand All @@ -23,22 +23,16 @@ earlier versions of *Borg* you should use Emborg_.
2. Normally *Assimilate* saves the size of the repository to the *latest.nt*
file. However the repository size is not yet available in *Borg 2*.

3. Currently the resolution of ``--newer``, ``--older``, ``--newest``,
``--oldest`` is constrained to one day by *Borg*. That should be fixed in
the next release.


Latest development release
--------------------------
| Version: 0.0a0
| Released: 2024-12-08
0.0.0 (2025-01-01)
0.0.0 (2025-??-??)
------------------
- Initial release


Known Issues
------------

- The :ref:`repo-create command <repo-create>` does not create parent directory
for repository.

- The size of the repository is not currently being saved in the
*❬config❭.latest.nt* file.
10 changes: 6 additions & 4 deletions tests/assimilate.nt
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,10 @@ assimilate:
checks:
stderr:
matches text:
> assimilate error: No prune settings available.
> assimilate error: no prune settings available.
> At least one of keep_within, keep_last, keep_minutely, keep_hourly,
> keep_daily, keep_weekly, keep_monthly, or keep_yearly must be
> specified.
> keep_daily, keep_weekly, keep_monthly, keep_3monthly, keep_13weekly,
> or keep_yearly must be specified.
status: 2

felony — compact {{{2:
Expand Down Expand Up @@ -698,6 +698,8 @@ assimilate:
> containing a filesystem object with the given
> NAME
> exclude_nodump: exclude files flagged NODUMP
> keep_13weekly: number of 13 week quarter archives to keep
> keep_3monthly: number of 3 month quarter archives to keep
> keep_daily: number of daily archives to keep
> keep_hourly: number of hourly archives to keep
> keep_last: number of the most recent archives to keep
Expand Down Expand Up @@ -4971,7 +4973,7 @@ assimilate:
stderr:
matches regex:
> assimilate error: must_exist, /{run_dir}/u:
> does not exist, perform setup and restart.
> does not exist; perform setup and restart.
status: 2

windpipe — create -ctest1 {{{2:
Expand Down

0 comments on commit e56b5c3

Please sign in to comment.