Skip to content

Commit

Permalink
Merge pull request #8422 from ThomasWaldmann/list-more-archive-metadata
Browse files Browse the repository at this point in the history
List more archive metadata
  • Loading branch information
ThomasWaldmann authored Sep 26, 2024
2 parents 8461538 + 9b3a002 commit 3c1f173
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
10 changes: 6 additions & 4 deletions docs/usage/repo-list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ Examples
::

$ borg repo-list
Monday Mon, 2016-02-15 19:15:11
repo Mon, 2016-02-15 19:26:54
root-2016-02-15 Mon, 2016-02-15 19:36:29
newname Mon, 2016-02-15 19:50:19
151b1a57 Mon, 2024-09-23 22:57:11 +0200 docs tw MacBook-Pro this is a comment
3387a079 Thu, 2024-09-26 09:07:07 +0200 scripts tw MacBook-Pro
ca774425 Thu, 2024-09-26 10:05:23 +0200 scripts tw MacBook-Pro
ba56c4a5 Thu, 2024-09-26 10:12:45 +0200 src tw MacBook-Pro
7567b79a Thu, 2024-09-26 10:15:07 +0200 scripts tw MacBook-Pro
21ab3600 Thu, 2024-09-26 10:15:17 +0200 docs tw MacBook-Pro
...

8 changes: 5 additions & 3 deletions src/borg/archiver/repo_list_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ def do_repo_list(self, args, repository, manifest):
if args.format is not None:
format = args.format
elif args.short:
format = "{archive}{NL}"
format = "{id}{NL}"
else:
format = os.environ.get("BORG_RLIST_FORMAT", "{archive:<36} {time} [{id}]{NL}")
format = os.environ.get(
"BORG_RLIST_FORMAT", "{id:.8} {time} {archive:<15} {username:<10} {hostname:<10} {comment:.40}{NL}"
)
formatter = ArchiveFormatter(format, repository, manifest, manifest.key, iec=args.iec)

output_data = []
Expand Down Expand Up @@ -93,7 +95,7 @@ def build_parser_repo_list(self, subparsers, common_parser, mid_common_parser):
)
subparser.set_defaults(func=self.do_repo_list)
subparser.add_argument(
"--short", dest="short", action="store_true", help="only print the archive names, nothing else"
"--short", dest="short", action="store_true", help="only print the archive IDs, nothing else"
)
subparser.add_argument(
"--format",
Expand Down
4 changes: 2 additions & 2 deletions src/borg/testsuite/archiver/create_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_basic_functionality(archivers, request):
with changedir("output"):
cmd(archiver, "extract", "test")

list_output = cmd(archiver, "repo-list", "--short")
list_output = cmd(archiver, "repo-list")
assert "test" in list_output
assert "test.2" in list_output

Expand Down Expand Up @@ -532,7 +532,7 @@ def test_create_archivename_with_placeholder(archivers, request):
name_given = "test-{now}" # placeholder in archive name gets replaced by borg
name_expected = f"test-{ts}" # placeholder in f-string gets replaced by python
cmd(archiver, "create", f"--timestamp={ts}", name_given, "input")
list_output = cmd(archiver, "repo-list", "--short")
list_output = cmd(archiver, "repo-list")
assert name_expected in list_output


Expand Down
17 changes: 11 additions & 6 deletions src/borg/testsuite/archiver/repo_list_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ def test_archives_format(archivers, request):
cmd(archiver, "create", "--comment", "comment 1", "test-1", src_dir)
cmd(archiver, "create", "--comment", "comment 2", "test-2", src_dir)
output_1 = cmd(archiver, "repo-list")
output_2 = cmd(archiver, "repo-list", "--format", "{archive:<36} {time} [{id}]{NL}")
output_2 = cmd(
archiver,
"repo-list",
"--format",
"{id:.8} {time} {archive:<15} {username:<10} {hostname:<10} {comment:.40}{NL}",
)
assert output_1 == output_2
output_1 = cmd(archiver, "repo-list", "--short")
assert output_1 == "test-1" + os.linesep + "test-2" + os.linesep
output_3 = cmd(archiver, "repo-list", "--format", "{name} {comment}{NL}")
assert "test-1 comment 1" + os.linesep in output_3
assert "test-2 comment 2" + os.linesep in output_3
output = cmd(archiver, "repo-list", "--short")
assert len(output) == 2 * 64 + 2 * len(os.linesep)
output = cmd(archiver, "repo-list", "--format", "{name} {comment}{NL}")
assert "test-1 comment 1" + os.linesep in output
assert "test-2 comment 2" + os.linesep in output


def test_size_nfiles(archivers, request):
Expand Down
5 changes: 4 additions & 1 deletion src/borg/testsuite/archiver/transfer_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_transfer(archivers, request):
original_location, input_path = archiver.repository_location, archiver.input_path

def check_repo():
listing = cmd(archiver, "repo-list", "--short")
listing = cmd(archiver, "repo-list")
assert "arch1" in listing
assert "arch2" in listing
listing = cmd(archiver, "list", "--short", "arch1")
Expand Down Expand Up @@ -93,6 +93,9 @@ def convert_tz(local_naive, tzoffset, tzinfo):

for got_archive, expected_archive in zip(got["archives"], expected["archives"]):
del got_archive["id"]
del got_archive["username"] # we didn't have this in the 1.x default format
del got_archive["hostname"] # we didn't have this in the 1.x default format
del got_archive["comment"] # we didn't have this in the 1.x default format
del expected_archive["id"]
del expected_archive["barchive"]
# timestamps:
Expand Down

0 comments on commit 3c1f173

Please sign in to comment.