Skip to content

Commit

Permalink
Remove the listing of borg options that affect a command in the help …
Browse files Browse the repository at this point in the history
…message.

Default *archive* and *prefix* settings.
  • Loading branch information
Ken Kundert authored and Ken Kundert committed Sep 23, 2019
1 parent 49c243f commit e5ce17f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 30 deletions.
22 changes: 22 additions & 0 deletions doc/configuring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,25 @@ or Emborg's program name ('prog_name'). An example of this is shown in both
*repository* and *archive* above. Doubling up the braces acts to escape them.
In this way you gain access to *Borg* settings. *archive* shows and example of
that.

It is generally better to specify *prefix* rather than *archive*, though you can
specify both if you wish. If *archive* is not specified and *prefix* is, then
*archive* is created by adding '{{now}}' to *prefix*. For example, if *prefix*
is '{host_name}-' and *archive* is not given then *archive* becomes
'{config_name}-{{now}}'. If neither *archive* or *prefix* is specified, then
'{config_name}-{{now}}' is used for *archive* and '{config_name}-' is used for
*prefix*.


Includes
--------

Any setting may include the contents of another file by using an *include*. You
may either specify a single include file as a string or a collection as a list
of strings::

include = 'file-to-include'

or::

include = ['first-file-to-include', 'second-file-to-include']
3 changes: 0 additions & 3 deletions doc/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ Here is the contents of the settings file: /root/.config/emborg/settings::

# repository settings
repository = 'backups:/mnt/backups/{host_name}-{user_name}-{config_name}'
archive = '{host_name}-{{now}}'
compression = 'lz4'

# shared filter settings
Expand Down Expand Up @@ -126,7 +125,6 @@ Home
Here is the contents of the *home* configuration file: ~/.config/emborg/home::

repository = 'backups:/mnt/borg-backups/repositories/{host_name}-{user_name}-{config_name}'
archive = '{host_name}-{{now}}'
encryption = 'keyfile'
avendesora_account = 'laptop-borg'
needs_ssh_agent = True
Expand Down Expand Up @@ -195,7 +193,6 @@ And finally, here is the contents of the *cache* configuration file:
~/.config/emborg/cache::

repository = '/home/ken/.cache/backups/{user_name}'
archive = '{config_name}-{{now}}'
encryption = 'none'

src_dirs = '~'.split() # absolute path to directory to be backed up
Expand Down
1 change: 1 addition & 0 deletions doc/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Releases
**Latest development release**:
| Version: 1.4.1
| Released: 2019-04-24
- Added documentation.
- Moved log files to ~/.local/share/emborg (run 'mv
~/.config/emborg/*.{log,lastbackup}* ~/.local/share/emborg' before using
Expand Down
14 changes: 2 additions & 12 deletions emborg/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
PROGRAM_NAME,
)
from .settings import Settings
from .utilities import two_columns, render_paths, gethostname, render_cmdline_opts
from .utilities import two_columns, render_paths, gethostname
hostname = gethostname()
from inform import (
Color, Error,
Expand Down Expand Up @@ -127,21 +127,11 @@ def get_name(cls):

@classmethod
def help(cls):
borg_opts = Settings.borg_option_descriptions(cls.NAMES[0])
if borg_opts:
extra = dedent("""
The following Borg options are accepted by this command:
{}
""").rstrip().format(render_cmdline_opts(borg_opts))
else:
extra = ''

text = dedent("""
{title}
{usage}
""").strip() + extra
""").strip()

return text.format(
title=title(cls.DESCRIPTION), usage=cls.USAGE,
Expand Down
18 changes: 8 additions & 10 deletions emborg/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,16 @@ def read(self, name=None, path=None):
path = to_path(parent, include)
self.read(path=path)

# default src_dirs if not given
if not self.settings.get('src_dirs'):
self.settings['src_dirs'] = []

# default archive if not given
if 'archive' not in self.settings:
if not 'prefix' in self.settings:
self.settings['prefix'] = '{config_name}-'
self.settings['archive'] = self.settings['prefix'] + '{{now}}'

# check() {{{2
def check(self):
# gather the string valued settings together (can be used by resolve)
Expand Down Expand Up @@ -293,23 +300,14 @@ def borg_options(self, cmd, options):
for name, attrs in BORG_SETTINGS.items():
if cmd in attrs['cmds'] or 'all' in attrs['cmds']:
opt = convert_name_to_option(name)
val = self.settings.get(name)
val = self.value(name)
if val:
if 'arg' in attrs and attrs['arg']:
args.extend([opt, str(val)])
else:
args.extend([opt])
return args

# borg_option_descriptions() {{{2
@staticmethod
def borg_option_descriptions(cmd):
for name, attrs in BORG_SETTINGS.items():
if cmd in attrs['cmds'] or 'all' in attrs['cmds']:
opt = convert_name_to_option(name)
desc = attrs['desc']
yield opt, desc

# publish_passcode() {{{2
def publish_passcode(self):
passcommand = self.passcommand
Expand Down
5 changes: 0 additions & 5 deletions emborg/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,3 @@ def render_path(path):
def render_paths(path_list):
return [render_path(path) for path in path_list]

# render_cmdline_opts() {{{1
def render_cmdline_opts(opts):
opts = list(opts)
w = max(len(opt[0]) for opt in opts)
return '\n'.join(' {:<{}} {}'.format(n,w,d) for n, d in opts)

0 comments on commit e5ce17f

Please sign in to comment.