Skip to content

Commit

Permalink
clean up before release
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Kundert authored and Ken Kundert committed Apr 29, 2024
1 parent b531541 commit 2de50e9
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 35 deletions.
6 changes: 3 additions & 3 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

# add command line options used to signal missing dependencies to pytest
def pytest_addoption(parser):
#parser.addoption(
# "--borg-version", action="store", default="99.99.99", help="version number of borg"
#)
# parser.addoption(
# "--borg-version", action="store", default="99.99.99", help="version number of borg"
# )
parser.addoption(
"--no-fuse", action="store_true", default=None, help="fuse is not available"
)
Expand Down
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os
# import sys, os

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down
46 changes: 46 additions & 0 deletions doc/configuring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1562,3 +1562,49 @@ be specified using absolute paths (ex: :ref:`default_mount_point`,

If specified, *working_dir* must be specified using an absolute path.
If not specified, *working_dir* defaults to ``/``.


Read Only Settings
------------------

These settings are set by *Emborg* itself. They are useful as place-holders in
other settings.

.. _cmd_name:

cmd_name
~~~~~~~~

The name of the *Emborg* command currently being run.


.. _config_dir:

config_dir
~~~~~~~~~~~

Absolute path to *Emborg*'s configuration directory.


.. _config_name:

config_name
~~~~~~~~~~~

Name of active configuration.


.. _home_dir:

home_dir
~~~~~~~~

Absolute path to user's home directory.


.. _log_dir:

log_dir
~~~~~~~

Absolute path to the *Emborg*'s logging directory.
3 changes: 2 additions & 1 deletion doc/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ Latest development release
| Released: 2024-01-01

1.39 (2024-??-??)
1.39 (2024-04-29)
-----------------
- Add date of last check to output of info command.
- Added :ref:`cmd_name` setting.
- Miscellaneous refinements.


Expand Down
6 changes: 3 additions & 3 deletions emborg/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def run(cls, command, args, settings, options):
repair = ['--repair'] if cmdline['--repair'] else []
if repair:
if 'dry-run' in options:
raise Error(f"--dry-run is not available with check command.")
raise Error("--dry-run is not available with check command.")
os.environ['BORG_CHECK_I_KNOW_WHAT_I_AM_DOING'] = 'YES'

# identify archive or archives to check
Expand Down Expand Up @@ -467,7 +467,7 @@ def run(cls, command, args, settings, options):
if cmdline["--progress"] or settings.show_progress:
borg_opts.append("--progress")
if 'dry-run' in options:
raise Error(f"--dry-run is not available with compact command.")
raise Error("--dry-run is not available with compact command.")

# run borg
borg = settings.run_borg(
Expand Down Expand Up @@ -900,7 +900,7 @@ def run(cls, command, args, settings, options):

try:
# compact the repository if requested
if settings.compact_after_delete and not 'dry-run' in options:
if settings.compact_after_delete and 'dry-run' not in options:
narrate("Compacting repository ...")
compact = CompactCommand()
compact_status = compact.run("compact", [], settings, options)
Expand Down
31 changes: 20 additions & 11 deletions emborg/emborg.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
codicil,
comment,
conjoin,
cull,
dedent,
display,
done,
Expand Down Expand Up @@ -90,7 +91,6 @@
fullhostname = getfullhostname()
username = getusername()


# borg_options_arg_count {{{2
borg_options_arg_count = {
"borg": 1,
Expand Down Expand Up @@ -809,26 +809,35 @@ def run_borg_raw(self, args):
# report_borg_error() {{{2
def report_borg_error(self, e, cmd):
narrate('Borg terminates with exit status:', e.status)
if e.stdout:
log('borg stdout:', indent(e.stdout), sep='\n')
else:
log('borg stdout: ❬empty❭')
if e.stderr:
log('borg stderr:', indent(e.stderr), sep='\n')
else:
log('borg stderr: ❬empty❭')
codicil = None
if e.stderr:
if 'previously located at' in e.stderr:
codicil = dedent(f'''
If repository was intentionally relocated, re-run with --relocated:
emborg --relocated {cmd} ...
''')
''', strip_nl='b')
if 'Failed to create/acquire the lock' in e.stderr:
codicil = [
'If another Emborg or Borg process is using this repository,',
'please wait for it to finish.',
'Perhaps you still have an archive mounted?',
'If so, use ‘emborg umount’ to unmount it.',
'Perhaps a previous run was killed or terminated with an error?',
'If so, use ‘emborg breaklock’ to clear the lock.',
]
codicil = dedent('''
If another Emborg or Borg process is using this repository,
please wait for it to finish.
Perhaps you still have an archive mounted?
If so, use ‘emborg umount’ to unmount it.
Perhaps a previous run was killed or terminated with an error?
If so, use ‘emborg breaklock’ to clear the lock.
''', strip_nl='b')

if 'Mountpoint must be a writable directory' in e.stderr:
codicil = 'Perhaps an archive is already mounted there?'
e.reraise(culprit=cmd, codicil=codicil)

e.reraise(culprit=cull((cmd, self.config_name)), codicil=codicil)

# destination() {{{2
def destination(self, archive=None):
Expand Down
12 changes: 10 additions & 2 deletions emborg/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ def main():
) as inform:

try:
worst_exit_status = 0

# emborg fails if the current working directory does not exist and
# the message returned by OSError does not make the problem obvious.
try:
os.getcwd()
except OSError as e:
raise Error(os_error(e), codicil="Does the current working directory exist?")

# read command line
cmdline = docopt(expanded_synopsis, options_first=True, version=version)
config = cmdline["--config"]
Expand All @@ -94,7 +103,6 @@ def main():
inform.narrate = True

Hooks.provision_hooks()
worst_exit_status = 0

# find the command
cmd, cmd_name = Command.find(command)
Expand Down Expand Up @@ -125,8 +133,8 @@ def main():
worst_exit_status = exit_status

except Error as e:
e.report()
exit_status = 2
e.report()
except OSError as e:
exit_status = 2
error(os_error(e))
Expand Down
2 changes: 1 addition & 1 deletion emborg/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

# Imports {{{1
from os.path import expanduser as expand_user
from inform import Error, error, log
from inform import Error, error
from .shlib import to_path


Expand Down
4 changes: 2 additions & 2 deletions emborg/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@
avendesora_field="name of field in Avendesora that holds the passphrase",
borg_executable="path to borg",
check_after_create="run check as the last step of an archive creation",
cmd_name="name of command being run (read only)",
cmd_name="name of Emborg command being run (read only)",
colorscheme="the color scheme",
config_dir="absolute path to configuration directory (read-only)",
config_name="name of active configuration (set by program)",
config_name="name of active configuration (read only)",
configurations="available Emborg configurations",
default_configuration="default Emborg configuration",
default_mount_point="directory to use as mount point if one is not specified",
Expand Down
12 changes: 12 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,15 @@ changelog = "https://emborg.readthedocs.io/en/latest/releases.html"
[build-system]
requires = ["flit_core >=2,<4"]
build-backend = "flit_core.buildapi"

[tool.ruff]
exclude = [".tox", "doc"]

[tool.ruff.lint]
select = ["F"]
ignore = []

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]
"emborg/overdue.py" = ["F841"]

12 changes: 6 additions & 6 deletions tests/test-cases.nt
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ emborg without configs:
> borg_executable: path to borg
> check_after_create: run check as the last step of an archive
> creation
> cmd_name: name of command being run (read only)
> cmd_name: name of Emborg command being run (read only)
> colorscheme: the color scheme
> compact_after_delete: run compact after deleting an archive or
> pruning a repository
> config_dir: absolute path to configuration directory
> (read-only)
> config_name: name of active configuration (set by program)
> config_name: name of active configuration (read only)
> configurations: available Emborg configurations
> cronhub_url: the cronhub.io URL for back-ups monitor
> cronhub_uuid: the cronhub.io UUID for back-ups monitor
Expand Down Expand Up @@ -212,13 +212,13 @@ emborg with configs:
> borg_executable: path to borg
> check_after_create: run check as the last step of an archive
> creation
> cmd_name: name of command being run (read only)
> cmd_name: name of Emborg command being run (read only)
> colorscheme: the color scheme
> compact_after_delete: run compact after deleting an archive or
> pruning a repository
> config_dir: absolute path to configuration directory
> (read-only)
> config_name: name of active configuration (set by program)
> config_name: name of active configuration (read only)
> configurations: available Emborg configurations
> cronhub_url: the cronhub.io URL for back-ups monitor
> cronhub_uuid: the cronhub.io UUID for back-ups monitor
Expand Down Expand Up @@ -667,7 +667,7 @@ emborg with configs:
> run_before_borg on test0
> run_after_backup on test0
> run_after_last_backup on test0
> emborg error: create:
> emborg error: create, test0:
> Failed to create/acquire the lock /⟪EMBORG⟫/tests/repositories/lock (timeout).
> If another Emborg or Borg process is using this repository,
> please wait for it to finish.
Expand Down Expand Up @@ -1101,7 +1101,7 @@ emborg with configs:
cleanser:
args: --config test7 list
expected:
> emborg error: list:
> emborg error: list, test7:
> Repository /⟪EMBORG⟫/tests/repositories does not exist.
expected_type: error

Expand Down
1 change: 0 additions & 1 deletion tests/test_emborg.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
# Imports {{{1
import arrow
import json
import nestedtext as nt
import os
from parametrize_from_file import parametrize
from functools import partial
Expand Down
8 changes: 4 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ envlist = lint, pytest, mypy
isolated_build = True

[testenv:lint]
deps = pylama
skip_install = true
commands = pylama --ignore C901,E116,E251,E203,E501,E741,E731 emborg/*.py
deps =
setuptools
ruff
commands = ruff check

# Test environment
[testenv]
Expand All @@ -18,7 +19,6 @@ deps =
voluptuous

[testenv:pytest]
# commands = py.test -vv --cov {posargs} --cov-branch --cov-report term-missing
commands = py.test -vv --cov {posargs} --cov-branch --cov-report term

[testenv:mypy]
Expand Down

0 comments on commit 2de50e9

Please sign in to comment.