Bläddra i källkod

cli: use --repo option instead of positional repo parameter

currently still with ::archive appended.
Thomas Waldmann 3 år sedan
förälder
incheckning
1c707b7da2
3 ändrade filer med 245 tillägg och 322 borttagningar
  1. 36 113
      src/borg/archiver.py
  2. 1 1
      src/borg/testsuite/__init__.py
  3. 208 208
      src/borg/testsuite/archiver.py

+ 36 - 113
src/borg/archiver.py

@@ -664,34 +664,37 @@ class Archiver:
     def do_benchmark_crud(self, args):
     def do_benchmark_crud(self, args):
         """Benchmark Create, Read, Update, Delete for archives."""
         """Benchmark Create, Read, Update, Delete for archives."""
         def measurement_run(repo, path):
         def measurement_run(repo, path):
-            archive = repo + '::borg-benchmark-crud'
             compression = '--compression=none'
             compression = '--compression=none'
             # measure create perf (without files cache to always have it chunking)
             # measure create perf (without files cache to always have it chunking)
             t_start = time.monotonic()
             t_start = time.monotonic()
-            rc = self.do_create(self.parse_args(['create', compression, '--files-cache=disabled', archive + '1', path]))
+            rc = self.do_create(self.parse_args([f'--repo={repo}::borg-benchmark-crud1', 'create',
+                                                 compression, '--files-cache=disabled', path]))
             t_end = time.monotonic()
             t_end = time.monotonic()
             dt_create = t_end - t_start
             dt_create = t_end - t_start
             assert rc == 0
             assert rc == 0
             # now build files cache
             # now build files cache
-            rc1 = self.do_create(self.parse_args(['create', compression, archive + '2', path]))
-            rc2 = self.do_delete(self.parse_args(['delete', archive + '2']))
+            rc1 = self.do_create(self.parse_args([f'--repo={repo}::borg-benchmark-crud2', 'create',
+                                                  compression, path]))
+            rc2 = self.do_delete(self.parse_args([f'--repo={repo}::borg-benchmark-crud2', 'delete']))
             assert rc1 == rc2 == 0
             assert rc1 == rc2 == 0
             # measure a no-change update (archive1 is still present)
             # measure a no-change update (archive1 is still present)
             t_start = time.monotonic()
             t_start = time.monotonic()
-            rc1 = self.do_create(self.parse_args(['create', compression, archive + '3', path]))
+            rc1 = self.do_create(self.parse_args([f'--repo={repo}::borg-benchmark-crud3', 'create',
+                                                  compression, path]))
             t_end = time.monotonic()
             t_end = time.monotonic()
             dt_update = t_end - t_start
             dt_update = t_end - t_start
-            rc2 = self.do_delete(self.parse_args(['delete', archive + '3']))
+            rc2 = self.do_delete(self.parse_args([f'--repo={repo}::borg-benchmark-crud3', 'delete']))
             assert rc1 == rc2 == 0
             assert rc1 == rc2 == 0
             # measure extraction (dry-run: without writing result to disk)
             # measure extraction (dry-run: without writing result to disk)
             t_start = time.monotonic()
             t_start = time.monotonic()
-            rc = self.do_extract(self.parse_args(['extract', '--dry-run', archive + '1']))
+            rc = self.do_extract(self.parse_args([f'--repo={repo}::borg-benchmark-crud1', 'extract',
+                                                  '--dry-run']))
             t_end = time.monotonic()
             t_end = time.monotonic()
             dt_extract = t_end - t_start
             dt_extract = t_end - t_start
             assert rc == 0
             assert rc == 0
             # measure archive deletion (of LAST present archive with the data)
             # measure archive deletion (of LAST present archive with the data)
             t_start = time.monotonic()
             t_start = time.monotonic()
-            rc = self.do_delete(self.parse_args(['delete', archive + '1']))
+            rc = self.do_delete(self.parse_args([f'--repo={repo}::borg-benchmark-crud1', 'delete']))
             t_end = time.monotonic()
             t_end = time.monotonic()
             dt_delete = t_end - t_start
             dt_delete = t_end - t_start
             assert rc == 0
             assert rc == 0
@@ -3200,6 +3203,8 @@ class Archiver:
                                    'compatible file can be generated by suffixing FILE with ".pyprof".')
                                    'compatible file can be generated by suffixing FILE with ".pyprof".')
             add_common_option('--rsh', metavar='RSH', dest='rsh',
             add_common_option('--rsh', metavar='RSH', dest='rsh',
                               help="Use this command to connect to the 'borg serve' process (default: 'ssh')")
                               help="Use this command to connect to the 'borg serve' process (default: 'ssh')")
+            add_common_option('--repo', metavar='REPO', dest='location', type=location_validator(),
+                              help="repository to use")  # XXXYYY
 
 
         def define_exclude_and_patterns(add_option, *, tag_files=False, strip_components=False):
         def define_exclude_and_patterns(add_option, *, tag_files=False, strip_components=False):
             add_option('-e', '--exclude', metavar='PATTERN', dest='patterns',
             add_option('-e', '--exclude', metavar='PATTERN', dest='patterns',
@@ -3263,8 +3268,7 @@ class Archiver:
 
 
         def define_borg_mount(parser):
         def define_borg_mount(parser):
             parser.set_defaults(func=self.do_mount)
             parser.set_defaults(func=self.do_mount)
-            parser.add_argument('location', metavar='REPOSITORY_OR_ARCHIVE', type=location_validator(),
-                                help='repository or archive to mount')
+            # archive name
             parser.add_argument('--consider-checkpoints', action='store_true', dest='consider_checkpoints',
             parser.add_argument('--consider-checkpoints', action='store_true', dest='consider_checkpoints',
                                 help='Show checkpoint archives in the repository contents list (default: hidden).')
                                 help='Show checkpoint archives in the repository contents list (default: hidden).')
             parser.add_argument('mountpoint', metavar='MOUNTPOINT', type=str,
             parser.add_argument('mountpoint', metavar='MOUNTPOINT', type=str,
@@ -3427,10 +3431,6 @@ class Archiver:
                                                  help='benchmarks borg CRUD (create, extract, update, delete).')
                                                  help='benchmarks borg CRUD (create, extract, update, delete).')
         subparser.set_defaults(func=self.do_benchmark_crud)
         subparser.set_defaults(func=self.do_benchmark_crud)
 
 
-        subparser.add_argument('location', metavar='REPOSITORY',
-                               type=location_validator(archive=False),
-                               help='repository to use for benchmark (must exist)')
-
         subparser.add_argument('path', metavar='PATH', help='path were to create benchmark input data')
         subparser.add_argument('path', metavar='PATH', help='path were to create benchmark input data')
 
 
         bench_cpu_epilog = process_epilog("""
         bench_cpu_epilog = process_epilog("""
@@ -3460,9 +3460,6 @@ class Archiver:
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           help='break repository and cache locks')
                                           help='break repository and cache locks')
         subparser.set_defaults(func=self.do_break_lock)
         subparser.set_defaults(func=self.do_break_lock)
-        subparser.add_argument('location', metavar='REPOSITORY', nargs='?', default='',
-                               type=location_validator(archive=False),
-                               help='repository for which to break the locks')
 
 
         # borg check
         # borg check
         check_epilog = process_epilog("""
         check_epilog = process_epilog("""
@@ -3545,9 +3542,7 @@ class Archiver:
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           help='verify repository')
                                           help='verify repository')
         subparser.set_defaults(func=self.do_check)
         subparser.set_defaults(func=self.do_check)
-        subparser.add_argument('location', metavar='REPOSITORY_OR_ARCHIVE', nargs='?', default='',
-                               type=location_validator(),
-                               help='repository or archive to check consistency of')
+        # archive name
         subparser.add_argument('--repository-only', dest='repo_only', action='store_true',
         subparser.add_argument('--repository-only', dest='repo_only', action='store_true',
                                help='only perform repository checks')
                                help='only perform repository checks')
         subparser.add_argument('--archives-only', dest='archives_only', action='store_true',
         subparser.add_argument('--archives-only', dest='archives_only', action='store_true',
@@ -3595,9 +3590,6 @@ class Archiver:
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           help='compact segment files / free space in repo')
                                           help='compact segment files / free space in repo')
         subparser.set_defaults(func=self.do_compact)
         subparser.set_defaults(func=self.do_compact)
-        subparser.add_argument('location', metavar='REPOSITORY', nargs='?', default='',
-                               type=location_validator(archive=False),
-                               help='repository to compact')
         subparser.add_argument('--cleanup-commits', dest='cleanup_commits', action='store_true',
         subparser.add_argument('--cleanup-commits', dest='cleanup_commits', action='store_true',
                                help='cleanup commit-only 17-byte segment files')
                                help='cleanup commit-only 17-byte segment files')
         subparser.add_argument('--threshold', metavar='PERCENT', dest='threshold',
         subparser.add_argument('--threshold', metavar='PERCENT', dest='threshold',
@@ -3635,9 +3627,6 @@ class Archiver:
         group.add_argument('-l', '--list', dest='list', action='store_true',
         group.add_argument('-l', '--list', dest='list', action='store_true',
                                help='list the configuration of the repo')
                                help='list the configuration of the repo')
 
 
-        subparser.add_argument('location', metavar='REPOSITORY', nargs='?', default='',
-                               type=location_validator(archive=False, proto='file'),
-                               help='repository to configure')
         subparser.add_argument('name', metavar='NAME', nargs='?',
         subparser.add_argument('name', metavar='NAME', nargs='?',
                                help='name of config key')
                                help='name of config key')
         subparser.add_argument('value', metavar='VALUE', nargs='?',
         subparser.add_argument('value', metavar='VALUE', nargs='?',
@@ -3921,9 +3910,7 @@ class Archiver:
                                    help='select compression algorithm, see the output of the '
                                    help='select compression algorithm, see the output of the '
                                         '"borg help compression" command for details.')
                                         '"borg help compression" command for details.')
 
 
-        subparser.add_argument('location', metavar='ARCHIVE',
-                               type=location_validator(archive=True),
-                               help='name of archive to create (must be also a valid directory name)')
+        # archive name
         subparser.add_argument('paths', metavar='PATH', nargs='*', type=str,
         subparser.add_argument('paths', metavar='PATH', nargs='*', type=str,
                                help='paths to archive')
                                help='paths to archive')
 
 
@@ -3966,9 +3953,7 @@ class Archiver:
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           help='dump archive items (metadata) (debug)')
                                           help='dump archive items (metadata) (debug)')
         subparser.set_defaults(func=self.do_debug_dump_archive_items)
         subparser.set_defaults(func=self.do_debug_dump_archive_items)
-        subparser.add_argument('location', metavar='ARCHIVE',
-                               type=location_validator(archive=True),
-                               help='archive to dump')
+        # archive name
 
 
         debug_dump_archive_epilog = process_epilog("""
         debug_dump_archive_epilog = process_epilog("""
         This command dumps all metadata of an archive in a decoded form to a file.
         This command dumps all metadata of an archive in a decoded form to a file.
@@ -3979,9 +3964,7 @@ class Archiver:
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           help='dump decoded archive metadata (debug)')
                                           help='dump decoded archive metadata (debug)')
         subparser.set_defaults(func=self.do_debug_dump_archive)
         subparser.set_defaults(func=self.do_debug_dump_archive)
-        subparser.add_argument('location', metavar='ARCHIVE',
-                               type=location_validator(archive=True),
-                               help='archive to dump')
+        # archive name
         subparser.add_argument('path', metavar='PATH', type=str,
         subparser.add_argument('path', metavar='PATH', type=str,
                                help='file to dump data into')
                                help='file to dump data into')
 
 
@@ -3994,9 +3977,6 @@ class Archiver:
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           help='dump decoded repository metadata (debug)')
                                           help='dump decoded repository metadata (debug)')
         subparser.set_defaults(func=self.do_debug_dump_manifest)
         subparser.set_defaults(func=self.do_debug_dump_manifest)
-        subparser.add_argument('location', metavar='REPOSITORY',
-                               type=location_validator(archive=False),
-                               help='repository to dump')
         subparser.add_argument('path', metavar='PATH', type=str,
         subparser.add_argument('path', metavar='PATH', type=str,
                                help='file to dump data into')
                                help='file to dump data into')
 
 
@@ -4009,9 +3989,6 @@ class Archiver:
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           help='dump repo objects (debug)')
                                           help='dump repo objects (debug)')
         subparser.set_defaults(func=self.do_debug_dump_repo_objs)
         subparser.set_defaults(func=self.do_debug_dump_repo_objs)
-        subparser.add_argument('location', metavar='REPOSITORY',
-                               type=location_validator(archive=False),
-                               help='repository to dump')
         subparser.add_argument('--ghost', dest='ghost', action='store_true',
         subparser.add_argument('--ghost', dest='ghost', action='store_true',
                                help='dump all segment file contents, including deleted/uncommitted objects and commits.')
                                help='dump all segment file contents, including deleted/uncommitted objects and commits.')
 
 
@@ -4024,9 +4001,6 @@ class Archiver:
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           help='search repo objects (debug)')
                                           help='search repo objects (debug)')
         subparser.set_defaults(func=self.do_debug_search_repo_objs)
         subparser.set_defaults(func=self.do_debug_search_repo_objs)
-        subparser.add_argument('location', metavar='REPOSITORY',
-                               type=location_validator(archive=False),
-                               help='repository to search')
         subparser.add_argument('wanted', metavar='WANTED', type=str,
         subparser.add_argument('wanted', metavar='WANTED', type=str,
                                help='term to search the repo for, either 0x1234abcd hex term or a string')
                                help='term to search the repo for, either 0x1234abcd hex term or a string')
 
 
@@ -4039,9 +4013,6 @@ class Archiver:
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           help='get object from repository (debug)')
                                           help='get object from repository (debug)')
         subparser.set_defaults(func=self.do_debug_get_obj)
         subparser.set_defaults(func=self.do_debug_get_obj)
-        subparser.add_argument('location', metavar='REPOSITORY',
-                               type=location_validator(archive=False),
-                               help='repository to use')
         subparser.add_argument('id', metavar='ID', type=str,
         subparser.add_argument('id', metavar='ID', type=str,
                                help='hex object ID to get from the repo')
                                help='hex object ID to get from the repo')
         subparser.add_argument('path', metavar='PATH', type=str,
         subparser.add_argument('path', metavar='PATH', type=str,
@@ -4056,9 +4027,6 @@ class Archiver:
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           help='put object to repository (debug)')
                                           help='put object to repository (debug)')
         subparser.set_defaults(func=self.do_debug_put_obj)
         subparser.set_defaults(func=self.do_debug_put_obj)
-        subparser.add_argument('location', metavar='REPOSITORY',
-                               type=location_validator(archive=False),
-                               help='repository to use')
         subparser.add_argument('paths', metavar='PATH', nargs='+', type=str,
         subparser.add_argument('paths', metavar='PATH', nargs='+', type=str,
                                help='file(s) to read and create object(s) from')
                                help='file(s) to read and create object(s) from')
 
 
@@ -4071,9 +4039,6 @@ class Archiver:
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           help='delete object from repository (debug)')
                                           help='delete object from repository (debug)')
         subparser.set_defaults(func=self.do_debug_delete_obj)
         subparser.set_defaults(func=self.do_debug_delete_obj)
-        subparser.add_argument('location', metavar='REPOSITORY',
-                               type=location_validator(archive=False),
-                               help='repository to use')
         subparser.add_argument('ids', metavar='IDs', nargs='+', type=str,
         subparser.add_argument('ids', metavar='IDs', nargs='+', type=str,
                                help='hex object ID(s) to delete from the repo')
                                help='hex object ID(s) to delete from the repo')
 
 
@@ -4086,9 +4051,6 @@ class Archiver:
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           help='show refcount for object from repository (debug)')
                                           help='show refcount for object from repository (debug)')
         subparser.set_defaults(func=self.do_debug_refcount_obj)
         subparser.set_defaults(func=self.do_debug_refcount_obj)
-        subparser.add_argument('location', metavar='REPOSITORY',
-                               type=location_validator(archive=False),
-                               help='repository to use')
         subparser.add_argument('ids', metavar='IDs', nargs='+', type=str,
         subparser.add_argument('ids', metavar='IDs', nargs='+', type=str,
                                help='hex object ID(s) to show refcounts for')
                                help='hex object ID(s) to show refcounts for')
 
 
@@ -4101,9 +4063,6 @@ class Archiver:
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           help='dump repo hints (debug)')
                                           help='dump repo hints (debug)')
         subparser.set_defaults(func=self.do_debug_dump_hints)
         subparser.set_defaults(func=self.do_debug_dump_hints)
-        subparser.add_argument('location', metavar='REPOSITORY',
-                               type=location_validator(archive=False),
-                               help='repository to dump')
         subparser.add_argument('path', metavar='PATH', type=str,
         subparser.add_argument('path', metavar='PATH', type=str,
                                help='file to dump data into')
                                help='file to dump data into')
 
 
@@ -4171,9 +4130,7 @@ class Archiver:
                                help='keep the local security info when deleting a repository')
                                help='keep the local security info when deleting a repository')
         subparser.add_argument('--save-space', dest='save_space', action='store_true',
         subparser.add_argument('--save-space', dest='save_space', action='store_true',
                                help='work slower, but using less space')
                                help='work slower, but using less space')
-        subparser.add_argument('location', metavar='REPOSITORY_OR_ARCHIVE', nargs='?', default='',
-                               type=location_validator(),
-                               help='repository or archive to delete')
+        # archive name
         subparser.add_argument('archives', metavar='ARCHIVE', nargs='*',
         subparser.add_argument('archives', metavar='ARCHIVE', nargs='*',
                                help='archives to delete')
                                help='archives to delete')
         define_archive_filters_group(subparser)
         define_archive_filters_group(subparser)
@@ -4210,9 +4167,9 @@ class Archiver:
         subparser.add_argument('other_location', metavar='SRC_REPOSITORY',
         subparser.add_argument('other_location', metavar='SRC_REPOSITORY',
                                type=location_validator(archive=False, other=True),
                                type=location_validator(archive=False, other=True),
                                help='source repository')
                                help='source repository')
-        subparser.add_argument('location', metavar='DST_REPOSITORY',
-                               type=location_validator(archive=False, other=False),
-                               help='destination repository')
+        # subparser.add_argument('-r', '--repo', dest='location', metavar='DST_REPOSITORY',
+        #                        type=location_validator(archive=False, other=False),
+        #                        help='destination repository')
         define_archive_filters_group(subparser)
         define_archive_filters_group(subparser)
 
 
         # borg diff
         # borg diff
@@ -4250,12 +4207,12 @@ class Archiver:
                                help='Sort the output lines by file path.')
                                help='Sort the output lines by file path.')
         subparser.add_argument('--json-lines', action='store_true',
         subparser.add_argument('--json-lines', action='store_true',
                                help='Format output as JSON Lines. ')
                                help='Format output as JSON Lines. ')
-        subparser.add_argument('location', metavar='REPO::ARCHIVE1',
-                               type=location_validator(archive=True),
-                               help='repository location and ARCHIVE1 name')
+        subparser.add_argument('archive1', metavar='ARCHIVE1',
+                               type=archivename_validator(),
+                               help='ARCHIVE1 name')
         subparser.add_argument('archive2', metavar='ARCHIVE2',
         subparser.add_argument('archive2', metavar='ARCHIVE2',
                                type=archivename_validator(),
                                type=archivename_validator(),
-                               help='ARCHIVE2 name (no repository location allowed)')
+                               help='ARCHIVE2 name')
         subparser.add_argument('paths', metavar='PATH', nargs='*', type=str,
         subparser.add_argument('paths', metavar='PATH', nargs='*', type=str,
                                help='paths of items inside the archives to compare; patterns are supported')
                                help='paths of items inside the archives to compare; patterns are supported')
         define_exclusion_group(subparser)
         define_exclusion_group(subparser)
@@ -4317,9 +4274,7 @@ class Archiver:
         subparser.add_argument('--tar-format', metavar='FMT', dest='tar_format', default='GNU',
         subparser.add_argument('--tar-format', metavar='FMT', dest='tar_format', default='GNU',
                                choices=('BORG', 'PAX', 'GNU'),
                                choices=('BORG', 'PAX', 'GNU'),
                                help='select tar format: BORG, PAX or GNU')
                                help='select tar format: BORG, PAX or GNU')
-        subparser.add_argument('location', metavar='ARCHIVE',
-                               type=location_validator(archive=True),
-                               help='archive to export')
+        # archive name
         subparser.add_argument('tarfile', metavar='FILE',
         subparser.add_argument('tarfile', metavar='FILE',
                                help='output tar file. "-" to write to stdout instead.')
                                help='output tar file. "-" to write to stdout instead.')
         subparser.add_argument('paths', metavar='PATH', nargs='*', type=str,
         subparser.add_argument('paths', metavar='PATH', nargs='*', type=str,
@@ -4377,9 +4332,7 @@ class Archiver:
                                help='write all extracted data to stdout')
                                help='write all extracted data to stdout')
         subparser.add_argument('--sparse', dest='sparse', action='store_true',
         subparser.add_argument('--sparse', dest='sparse', action='store_true',
                                help='create holes in output sparse file from all-zero chunks')
                                help='create holes in output sparse file from all-zero chunks')
-        subparser.add_argument('location', metavar='ARCHIVE',
-                               type=location_validator(archive=True),
-                               help='archive to extract')
+        # archive name
         subparser.add_argument('paths', metavar='PATH', nargs='*', type=str,
         subparser.add_argument('paths', metavar='PATH', nargs='*', type=str,
                                help='paths to extract; patterns are supported')
                                help='paths to extract; patterns are supported')
         define_exclusion_group(subparser, strip_components=True)
         define_exclusion_group(subparser, strip_components=True)
@@ -4417,9 +4370,7 @@ class Archiver:
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           help='show repository or archive information')
                                           help='show repository or archive information')
         subparser.set_defaults(func=self.do_info)
         subparser.set_defaults(func=self.do_info)
-        subparser.add_argument('location', metavar='REPOSITORY_OR_ARCHIVE', nargs='?', default='',
-                               type=location_validator(),
-                               help='repository or archive to display information about')
+        # archive name
         subparser.add_argument('--json', action='store_true',
         subparser.add_argument('--json', action='store_true',
                                help='format output as JSON')
                                help='format output as JSON')
         define_archive_filters_group(subparser)
         define_archive_filters_group(subparser)
@@ -4553,9 +4504,6 @@ class Archiver:
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           help='initialize empty repository')
                                           help='initialize empty repository')
         subparser.set_defaults(func=self.do_init)
         subparser.set_defaults(func=self.do_init)
-        subparser.add_argument('location', metavar='REPOSITORY', nargs='?', default='',
-                               type=location_validator(archive=False),
-                               help='repository to create')
         subparser.add_argument('--other-location', metavar='OTHER_REPOSITORY', dest='other_location',
         subparser.add_argument('--other-location', metavar='OTHER_REPOSITORY', dest='other_location',
                                type=location_validator(archive=False, other=True),
                                type=location_validator(archive=False, other=True),
                                help='reuse the key material from the other repository')
                                help='reuse the key material from the other repository')
@@ -4626,8 +4574,6 @@ class Archiver:
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           help='export repository key for backup')
                                           help='export repository key for backup')
         subparser.set_defaults(func=self.do_key_export)
         subparser.set_defaults(func=self.do_key_export)
-        subparser.add_argument('location', metavar='REPOSITORY', nargs='?', default='',
-                               type=location_validator(archive=False))
         subparser.add_argument('path', metavar='PATH', nargs='?', type=str,
         subparser.add_argument('path', metavar='PATH', nargs='?', type=str,
                                help='where to store the backup')
                                help='where to store the backup')
         subparser.add_argument('--paper', dest='paper', action='store_true',
         subparser.add_argument('--paper', dest='paper', action='store_true',
@@ -4657,8 +4603,6 @@ class Archiver:
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           help='import repository key from backup')
                                           help='import repository key from backup')
         subparser.set_defaults(func=self.do_key_import)
         subparser.set_defaults(func=self.do_key_import)
-        subparser.add_argument('location', metavar='REPOSITORY', nargs='?', default='',
-                               type=location_validator(archive=False))
         subparser.add_argument('path', metavar='PATH', nargs='?', type=str,
         subparser.add_argument('path', metavar='PATH', nargs='?', type=str,
                                help='path to the backup (\'-\' to read from stdin)')
                                help='path to the backup (\'-\' to read from stdin)')
         subparser.add_argument('--paper', dest='paper', action='store_true',
         subparser.add_argument('--paper', dest='paper', action='store_true',
@@ -4679,8 +4623,6 @@ class Archiver:
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           help='change repository passphrase')
                                           help='change repository passphrase')
         subparser.set_defaults(func=self.do_change_passphrase)
         subparser.set_defaults(func=self.do_change_passphrase)
-        subparser.add_argument('location', metavar='REPOSITORY', nargs='?', default='',
-                               type=location_validator(archive=False))
 
 
         change_location_epilog = process_epilog("""
         change_location_epilog = process_epilog("""
         Change the location of a borg key. The key can be stored at different locations:
         Change the location of a borg key. The key can be stored at different locations:
@@ -4697,8 +4639,6 @@ class Archiver:
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           help='change key location')
                                           help='change key location')
         subparser.set_defaults(func=self.do_change_location)
         subparser.set_defaults(func=self.do_change_location)
-        subparser.add_argument('location', metavar='REPOSITORY', nargs='?', default='',
-                               type=location_validator(archive=False))
         subparser.add_argument('key_mode', metavar='KEY_LOCATION', choices=('repokey', 'keyfile'),
         subparser.add_argument('key_mode', metavar='KEY_LOCATION', choices=('repokey', 'keyfile'),
                                help='select key location')
                                help='select key location')
         subparser.add_argument('--keep', dest='keep', action='store_true',
         subparser.add_argument('--keep', dest='keep', action='store_true',
@@ -4741,8 +4681,6 @@ class Archiver:
                                            formatter_class=argparse.RawDescriptionHelpFormatter,
                                            formatter_class=argparse.RawDescriptionHelpFormatter,
                                            help='change key algorithm')
                                            help='change key algorithm')
         subparser.set_defaults(func=self.do_change_algorithm)
         subparser.set_defaults(func=self.do_change_algorithm)
-        subparser.add_argument('location', metavar='REPOSITORY', nargs='?', default='',
-                               type=location_validator(archive=False))
         subparser.add_argument('algorithm', metavar='ALGORITHM', choices=list(KEY_ALGORITHMS),
         subparser.add_argument('algorithm', metavar='ALGORITHM', choices=list(KEY_ALGORITHMS),
                                help='select key algorithm')
                                help='select key algorithm')
 
 
@@ -4821,9 +4759,7 @@ class Archiver:
                                     'but keys used in it are added to the JSON output. '
                                     'but keys used in it are added to the JSON output. '
                                     'Some keys are always present. Note: JSON can only represent text. '
                                     'Some keys are always present. Note: JSON can only represent text. '
                                     'A "bpath" key is therefore not available.')
                                     'A "bpath" key is therefore not available.')
-        subparser.add_argument('location', metavar='REPOSITORY_OR_ARCHIVE', nargs='?', default='',
-                               type=location_validator(),
-                               help='repository or archive to list contents of')
+        # archive name
         subparser.add_argument('paths', metavar='PATH', nargs='*', type=str,
         subparser.add_argument('paths', metavar='PATH', nargs='*', type=str,
                                help='paths to list; patterns are supported')
                                help='paths to list; patterns are supported')
         define_archive_filters_group(subparser)
         define_archive_filters_group(subparser)
@@ -4926,9 +4862,6 @@ class Archiver:
         define_archive_filters_group(subparser, sort_by=False, first_last=False)
         define_archive_filters_group(subparser, sort_by=False, first_last=False)
         subparser.add_argument('--save-space', dest='save_space', action='store_true',
         subparser.add_argument('--save-space', dest='save_space', action='store_true',
                                help='work slower, but using less space')
                                help='work slower, but using less space')
-        subparser.add_argument('location', metavar='REPOSITORY', nargs='?', default='',
-                               type=location_validator(archive=False),
-                               help='repository to prune')
 
 
         # borg recreate
         # borg recreate
         recreate_epilog = process_epilog("""
         recreate_epilog = process_epilog("""
@@ -5036,9 +4969,7 @@ class Archiver:
                                         'HASH_MASK_BITS, HASH_WINDOW_SIZE) or `default` to use the current defaults. '
                                         'HASH_MASK_BITS, HASH_WINDOW_SIZE) or `default` to use the current defaults. '
                                         'default: %s,%d,%d,%d,%d' % CHUNKER_PARAMS)
                                         'default: %s,%d,%d,%d,%d' % CHUNKER_PARAMS)
 
 
-        subparser.add_argument('location', metavar='REPOSITORY_OR_ARCHIVE', nargs='?', default='',
-                               type=location_validator(),
-                               help='repository or archive to recreate')
+        # archive name
         subparser.add_argument('paths', metavar='PATH', nargs='*', type=str,
         subparser.add_argument('paths', metavar='PATH', nargs='*', type=str,
                                help='paths to recreate; patterns are supported')
                                help='paths to recreate; patterns are supported')
 
 
@@ -5054,12 +4985,12 @@ class Archiver:
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           help='rename archive')
                                           help='rename archive')
         subparser.set_defaults(func=self.do_rename)
         subparser.set_defaults(func=self.do_rename)
-        subparser.add_argument('location', metavar='ARCHIVE',
-                               type=location_validator(archive=True),
-                               help='archive to rename')
+        subparser.add_argument('name_current', metavar='OLDNAME',
+                               type=archivename_validator(),
+                               help='the current archive name')
         subparser.add_argument('name', metavar='NEWNAME',
         subparser.add_argument('name', metavar='NEWNAME',
                                type=archivename_validator(),
                                type=archivename_validator(),
-                               help='the new archive name to use')
+                               help='the new archive name')
 
 
         # borg serve
         # borg serve
         serve_epilog = process_epilog("""
         serve_epilog = process_epilog("""
@@ -5176,9 +5107,6 @@ class Archiver:
                                help='Enable manifest authentication (in key and cache) (Borg 1.0.9 and later).')
                                help='Enable manifest authentication (in key and cache) (Borg 1.0.9 and later).')
         subparser.add_argument('--disable-tam', dest='disable_tam', action='store_true',
         subparser.add_argument('--disable-tam', dest='disable_tam', action='store_true',
                                help='Disable manifest authentication (in key and cache).')
                                help='Disable manifest authentication (in key and cache).')
-        subparser.add_argument('location', metavar='REPOSITORY', nargs='?', default='',
-                               type=location_validator(archive=False),
-                               help='path to the repository to be upgraded')
 
 
         # borg with-lock
         # borg with-lock
         with_lock_epilog = process_epilog("""
         with_lock_epilog = process_epilog("""
@@ -5202,9 +5130,6 @@ class Archiver:
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           help='run user command with lock held')
                                           help='run user command with lock held')
         subparser.set_defaults(func=self.do_with_lock)
         subparser.set_defaults(func=self.do_with_lock)
-        subparser.add_argument('location', metavar='REPOSITORY',
-                               type=location_validator(archive=False),
-                               help='repository to lock')
         subparser.add_argument('command', metavar='COMMAND',
         subparser.add_argument('command', metavar='COMMAND',
                                help='command to run')
                                help='command to run')
         subparser.add_argument('args', metavar='ARGS', nargs=argparse.REMAINDER,
         subparser.add_argument('args', metavar='ARGS', nargs=argparse.REMAINDER,
@@ -5286,9 +5211,7 @@ class Archiver:
                                    help='select compression algorithm, see the output of the '
                                    help='select compression algorithm, see the output of the '
                                         '"borg help compression" command for details.')
                                         '"borg help compression" command for details.')
 
 
-        subparser.add_argument('location', metavar='ARCHIVE',
-                               type=location_validator(archive=True),
-                               help='name of archive to create (must be also a valid directory name)')
+        # archive name
         subparser.add_argument('tarfile', metavar='TARFILE',
         subparser.add_argument('tarfile', metavar='TARFILE',
                                help='input tar file. "-" to read from stdin instead.')
                                help='input tar file. "-" to read from stdin instead.')
         return parser
         return parser

+ 1 - 1
src/borg/testsuite/__init__.py

@@ -248,7 +248,7 @@ class BaseTestCase(unittest.TestCase):
             mountpoint = tempfile.mkdtemp()
             mountpoint = tempfile.mkdtemp()
         else:
         else:
             os.mkdir(mountpoint)
             os.mkdir(mountpoint)
-        args = ['mount', location, mountpoint] + list(options)
+        args = [f'--repo={location}', 'mount', mountpoint] + list(options)
         if os_fork:
         if os_fork:
             # Do not spawn, but actually (OS) fork.
             # Do not spawn, but actually (OS) fork.
             if os.fork() == 0:
             if os.fork() == 0:

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 208 - 208
src/borg/testsuite/archiver.py


Vissa filer visades inte eftersom för många filer har ändrats