Skip to content

Commit

Permalink
fix issue with --date implementation and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Kundert authored and Ken Kundert committed Aug 26, 2021
1 parent 53729de commit 81371f8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 deletions.
14 changes: 7 additions & 7 deletions doc/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ explicitly specify a particular archive. For example:
$ emborg extract --archive continuum-2020-12-05T12:54:26 home/shaunte/bin
Alternatively you can specify a date or date and time. If only the date is
given the time is taken to be midnight. The youngest archive that is older than
the specified date and time is used. For example:
given the time is taken to be midnight. The oldest archive that is
younger than specified date and time is used. For example:

.. code-block:: bash
Expand Down Expand Up @@ -449,8 +449,8 @@ You can explicitly specify an archive:
$ emborg manifest --archive continuum-2021-04-01T12:19:58
Or you choose an archive based on a date and time. The youngest archive that is
older than specified date and time is used.
Or you choose an archive based on a date and time. The oldest archive that is
younger than specified date and time is used.

.. code-block:: bash
Expand Down Expand Up @@ -555,7 +555,7 @@ You can also specify the date in relative terms:
where s, m, h, d, w, M, and y represents seconds, minutes, hours, days, weeks,
months, and years.

When a date is given, the youngest archive that is older than the specified date
When a date is given, the oldest archive that is younger than the specified date
or time is used.

Finally, you can mount all the available archives:
Expand Down Expand Up @@ -609,8 +609,8 @@ explicitly specify a particular archive. For example:

$ emborg restore --archive continuum-2020-12-05T12:54:26 resume.doc

Or you choose an archive based on a date and time. The youngest archive that is
older than specified date and time is used.
Or you choose an archive based on a date and time. The oldest archive that is
younger than specified date and time is used.

$ emborg restore --date 2021-04-01 resume.doc
$ emborg restore --date 2021-04-01T18:30 resume.doc
Expand Down
32 changes: 21 additions & 11 deletions emborg/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,25 @@ def get_name_of_nearest_archive(settings, date):
culprit=date, codicil=codicil, wrap=True
)

# find youngest archive that is older than specified target
prev_archive = None
# find oldest archive that is younger than specified target
archive = prev_archive = None
for archive in reversed(archives):
archive_time = arrow.get(archive["time"], tzinfo='local')
if archive_time <= target:
if prev_archive:
return prev_archive["name"]
break
warn(
f'archive younger than {date} ({target.humanize()}) was not found.',
codicil='Using youngest that is older than given date and time.'
)
return archive["name"]
prev_archive = archive
if archive:
warn(
f'archive older than {date} ({target.humanize()}) was not found.',
codicil='Using oldest available.'
)
return archive["name"]
raise Error(
f"no archive available is older than {date} ({target.humanize()})."
)
Expand Down Expand Up @@ -986,8 +996,8 @@ class ExtractCommand(Command):
$ emborg extract --archive continuum-2020-12-05T12:54:26 home/shaunte/bin
Alternatively you can specify a date or date and time. If only the date
is given the time is taken to be midnight. The youngest archive that is
older than specified date and time is used.
is given the time is taken to be midnight. The oldest archive that is
younger than specified date and time is used.
$ emborg extract --date 2021-04-01 home/shaunte/bin
$ emborg extract --date 2021-04-01T15:30 home/shaunte/bin
Expand Down Expand Up @@ -1284,8 +1294,8 @@ class ManifestCommand(Command):
emborg manifest --archive kundert-2018-12-05T12:54:26
Or you choose an archive based on a date and time. The youngest archive
that is older than specified date and time is used.
Or you choose an archive based on a date and time. The oldest archive
that is younger than specified date and time is used.
emborg manifest --date 2021/04/01
emborg manifest --date 2021-04-01
Expand Down Expand Up @@ -1505,8 +1515,8 @@ class MountCommand(Command):
If you do not specify an archive or date, the most recently created
archive is mounted.
Or you choose an archive based on a date and time. The youngest archive
that is older than specified date and time is used.
Or you choose an archive based on a date and time. The oldest archive
that is younger than specified date and time is used.
emborg mount --date 2021-04-01 backups
emborg mount --date 2021-04-01T18:30 backups
Expand Down Expand Up @@ -1654,8 +1664,8 @@ class RestoreCommand(Command):
$ emborg restore --archive continuum-2020-12-05T12:54:26 resume.doc
Or you choose an archive based on a date and time. The youngest archive
that is older than specified date and time is used.
Or you choose an archive based on a date and time. The oldest archive
that is younger than specified date and time is used.
$ emborg restore --date 2021-04-01 resume.doc
$ emborg restore --date 2021-04-01T18:30 resume.doc
Expand Down
16 changes: 11 additions & 5 deletions tests/test-cases.nt
Original file line number Diff line number Diff line change
Expand Up @@ -791,14 +791,20 @@ emborg with configs:
expected_type: regex

-
args: --quiet --config test8 files --date 1h
expected: bu error: no archive available is older than 1h (an hour ago).
expected_type: error
args: --quiet --config test8 files --date 1h --sort-by-name
expected:
> Archive: test8-\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d
> configs.symlink/subdir/
> configs.symlink/subdir/file
expected_type: regex

-
args: --quiet --config test8 files --date «DATE» --sort-by-name
expected: bu error: no archive available is older than «DATE» \(.* ago\)\.
expected_type: error regex
expected:
> Archive: test8-\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d
> configs.symlink/subdir/
> configs.symlink/subdir/file
expected_type: regex

-
args: --quiet --config test8 files -O
Expand Down

0 comments on commit 81371f8

Please sign in to comment.