Skip to content

Commit

Permalink
add si format to manifest command
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Kundert authored and Ken Kundert committed Nov 18, 2022
1 parent 2d9db6c commit ab9b3fc
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
42 changes: 29 additions & 13 deletions doc/configuring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ manifest_default_format
~~~~~~~~~~~~~~~~~~~~~~~

A string that specifies the name of the default format. The name must be a key
in :ref:`manifest_formats`.
in :ref:`manifest_formats`. If not specified, ``short`` is used.


.. _manifest_formats:
Expand All @@ -765,22 +765,24 @@ formatted. The default value for *manifest_formats* is:
name = "{path}",
short = "{path}{Type}",
date = "{mtime} {path}{Type}",
size = "{size} {path}{Type}",
owner = "{user} {path}{Type}",
group = "{group} {path}{Type}",
long = '{mode} {user:6} {group:6} {size:8} {mtime} {path}{extra}',
size = "{size:8} {path}{Type}",
si = "{Size:6.2} {path}{Type}",
owner = "{user:8} {path}{Type}",
group = "{group:8} {path}{Type}",
long = '{mode:10} {user:6} {group:6} {size:8} {mtime} {path}{extra}',
)
manifest_default_format = 'short'
Notice that 7 formats are defined:
Notice that 8 formats are defined:

| *name*: used when ``--name-only`` is specified.
| *short*: used by when ``--short`` is specified and when sorting by name.
| *date*: used by default when sorting by date.
| *size*: used by default when sorting by size.
| *owner*: used by default when sorting by owner.
| *group*: used by default when sorting by group.
| *long*: used when ``--long`` is specified.
:name: used when ``--name-only`` is specified.
:short: used by when ``--short`` is specified and when sorting by name.
:date: used by default when sorting by date.
:size: size in bytes (fixed format).
:si: size in bytes (SI format), used by default when sorting by size.
:owner: used by default when sorting by owner.
:group: used by default when sorting by group.
:long: used when ``--long`` is specified.

Your *manifest_formats* need not define all or even any of these formats.
The above example shows the formats that are predefined in *Emborg*. You do not
Expand Down Expand Up @@ -1358,6 +1360,20 @@ As of Borg 1.2 *prefix* is deprecated and should no longer be used. Use
:ref:`glob_archives` instead. It provides the same basic functionality in a way
that is a little more general. For more information, see :ref:`archive`.

Prior to the deprecation of *prefix* it was common in *Emborg* settings file to
just specify *prefix* and not specify :ref:`archive` with the understanding that
the default value of *archive* is ``{prefix}-{{now}}``. So you might have
something like::

prefix = '{config_name}-'

in your settings file. This can be converted to::

archive = '{config_name}-{{now}}'
glob_archives = '{config_name}-*'

without changing the intent.


.. _remote_path:

Expand Down
3 changes: 2 additions & 1 deletion doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ as where it is located and how large it is.
$ emborg info
The :ref:`help command <help>` shows you information on how to use *Emborg*.
The :ref:`help command <emborg_help>` shows you information on how to use
*Emborg*.

.. code-block:: bash
Expand Down
2 changes: 1 addition & 1 deletion doc/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Latest development release
- Suppress log file generation for
:ref:`configs <configs>`,
:ref:`due <due>`,
:ref:`help <help>`,
:ref:`help <emborg_help>`,
:ref:`log <log>`,
:ref:`settings <settings>` and
:ref:`version <version>` commands.
Expand Down
17 changes: 12 additions & 5 deletions emborg/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -1470,16 +1470,19 @@ def run(cls, command, args, settings, options):
if not archive:
archive = get_name_of_latest_archive(settings)

# define available formats
# predefined formats
formats = dict(
name = "{path}",
short = "{path}{Type}",
date = "{mtime} {path}{Type}",
size = "{size:8} {path}{Type}",
si = "{Size:6.2} {path}{Type}",
owner = "{user:8} {path}{Type}",
group = "{group:8} {path}{Type}",
long = '{mode:10} {user:6} {group:6} {size:8} {mtime} {path}{extra}',
)

# choose format
default_format = settings.manifest_default_format
if not default_format:
default_format = 'short'
Expand All @@ -1506,7 +1509,7 @@ def run(cls, command, args, settings, options):
fmt = "date"
sort_key = 'mtime'
elif cmdline["--sort-by-size"]:
fmt = "size"
fmt = "si"
sort_key = 'size'
elif cmdline["--sort-by-owner"]:
fmt = "owner"
Expand All @@ -1527,11 +1530,15 @@ def run(cls, command, args, settings, options):
if cmdline['--format']:
fmt = cmdline['--format']
if fmt not in formats:
raise Error('unknown format.', culprit=fmt)
raise Error(
'unknown format.',
culprit = fmt,
codicil = f"Choose from: {conjoin(formats)}."
)

# run borg
output("Archive:", archive)
template = formats.get(fmt)
template = formats[fmt]
keys = template.lower()
# lower case it so we get size when user requests Size
if sort_key and '{' + sort_key not in keys:
Expand Down Expand Up @@ -1588,7 +1595,7 @@ def run(cls, command, args, settings, options):
values['Type'] = '/' # directory
elif type == 'l':
values['Type'] = '@' # directory
values['extra'] = ' -> ' + values['source']
values['extra'] = ' > ' + values['source']
elif type == 'h':
values['extra'] = ' links to ' + values['source']
elif type == 'p':
Expand Down

0 comments on commit ab9b3fc

Please sign in to comment.