borgapi 0.6.1__py3-none-any.whl → 0.7.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
borgapi/options.py CHANGED
@@ -1,4 +1,4 @@
1
- """Option Dataclasses"""
1
+ """Option Dataclasses."""
2
2
 
3
3
  import logging
4
4
  import re
@@ -23,7 +23,7 @@ __all__ = [
23
23
 
24
24
  @dataclass
25
25
  class _DefaultField:
26
- """Field info in options classes"""
26
+ """Field info in options classes."""
27
27
 
28
28
  name: str
29
29
  type: type
@@ -32,7 +32,7 @@ class _DefaultField:
32
32
 
33
33
  @dataclass
34
34
  class OptionsBase:
35
- """Holds all the shared methods for the subclasses
35
+ """Holds all the shared methods for the subclasses.
36
36
 
37
37
  Every subclass should use this __init__ method becuase it will only set the values that the
38
38
  dataclass supports and ignore the ones not part of it. This way the same options dict can be
@@ -40,6 +40,7 @@ class OptionsBase:
40
40
  """
41
41
 
42
42
  def __init__(self, **kwargs):
43
+ """Set options to be used for the subclasses."""
43
44
  default = self._defaults()
44
45
  for option in kwargs:
45
46
  if option in default:
@@ -47,11 +48,10 @@ class OptionsBase:
47
48
 
48
49
  @staticmethod
49
50
  def convert_name(value: str) -> str:
50
- """Add flag marker and replace underscores with dashes in name"""
51
+ """Add flag marker and replace underscores with dashes in name."""
51
52
  return "--" + value.replace("_", "-")
52
53
 
53
54
  def _field_set(self, field: str) -> bool:
54
- # pylint: disable=no-member
55
55
  default = self.__dataclass_fields__.get(field).default
56
56
  set_value = getattr(self, field)
57
57
  return set_value != default
@@ -67,7 +67,6 @@ class OptionsBase:
67
67
  else:
68
68
  logger.warning("[DEPRECATED] %s, not being replaced", old_field)
69
69
 
70
- # pylint: disable=no-member
71
70
  @classmethod
72
71
  def _defaults(cls) -> Set[str]:
73
72
  defaults = set()
@@ -83,13 +82,13 @@ class OptionsBase:
83
82
  return issubclass(type_.__origin__, list)
84
83
 
85
84
  def parse(self) -> List[Optional[Union[str, int]]]:
86
- """Turn options into list for argv
85
+ """Turn options into list for argv.
87
86
 
88
87
  :return: options for the command line
89
88
  :rtype: List[Optional[Union[str, int]]]
90
89
  """
91
90
  args = []
92
- # pylint: disable=no-member
91
+
93
92
  for key, value in self.__dataclass_fields__.items():
94
93
  attr = getattr(self, key)
95
94
  if attr is not None and value.default != attr:
@@ -107,10 +106,9 @@ class OptionsBase:
107
106
  return args
108
107
 
109
108
 
110
- # pylint: disable=too-many-instance-attributes
111
109
  @dataclass
112
110
  class CommonOptions(OptionsBase):
113
- """Common Options for all Borg commands
111
+ """Common Options for all Borg commands.
114
112
 
115
113
  :param critical: work on log level CRITICAL
116
114
  :type critical: bool
@@ -174,8 +172,8 @@ class CommonOptions(OptionsBase):
174
172
  debug_profile: str = None
175
173
  rsh: str = None
176
174
 
177
- # pylint: disable=useless-super-delegation
178
175
  def __init__(self, **kwargs):
176
+ """Set the common options for all commands."""
179
177
  super().__init__(**kwargs)
180
178
 
181
179
  if isinstance(self.debug_topic, str):
@@ -186,7 +184,7 @@ class CommonOptions(OptionsBase):
186
184
 
187
185
  @dataclass
188
186
  class ExclusionOptions(OptionsBase):
189
- """Options for excluding various files from backup
187
+ """Options for excluding various files from backup.
190
188
 
191
189
  :param exclude: exclude paths matching PATTERN
192
190
  :type exclude: List[str]
@@ -204,8 +202,8 @@ class ExclusionOptions(OptionsBase):
204
202
  pattern: List[str] = None
205
203
  patterns_from: str = None
206
204
 
207
- # pylint: disable=useless-super-delegation
208
205
  def __init__(self, **kwargs):
206
+ """Set the exclusion options for many commands."""
209
207
  super().__init__(**kwargs)
210
208
 
211
209
  if isinstance(self.exclude, str):
@@ -216,7 +214,7 @@ class ExclusionOptions(OptionsBase):
216
214
 
217
215
  @dataclass
218
216
  class ExclusionInput(ExclusionOptions):
219
- """Exclusion Options when inputing data to the archive
217
+ """Exclusion Options when inputing data to the archive.
220
218
 
221
219
  :param exclude_caches: exclude directories that contain a CACHEDIR.TAG file
222
220
  (http://www.bford.info/cachedir/spec.html)
@@ -239,8 +237,8 @@ class ExclusionInput(ExclusionOptions):
239
237
  keep_tag_files: bool = False
240
238
  exclude_nodump: bool = False
241
239
 
242
- # pylint: disable=useless-super-delegation
243
240
  def __init__(self, **kwargs):
241
+ """Set the exclusion options for input for many commands."""
244
242
  super().__init__(**kwargs)
245
243
 
246
244
  if isinstance(self.exclude_if_present, str):
@@ -249,7 +247,7 @@ class ExclusionInput(ExclusionOptions):
249
247
 
250
248
  @dataclass
251
249
  class ExclusionOutput(ExclusionOptions):
252
- """Exclusion Options when outputing data in the archive
250
+ """Exclusion Options when outputing data in the archive.
253
251
 
254
252
  :param strip_componts: Remove the specified number of leading path elements. Paths with fewer
255
253
  elements will be silently skipped
@@ -258,14 +256,14 @@ class ExclusionOutput(ExclusionOptions):
258
256
 
259
257
  strip_componts: int = None
260
258
 
261
- # pylint: disable=useless-super-delegation
262
259
  def __init__(self, **kwargs):
260
+ """Set the exclusion options for output for many commands."""
263
261
  super().__init__(**kwargs)
264
262
 
265
263
 
266
264
  @dataclass
267
265
  class FilesystemOptions(OptionsBase):
268
- """Options for how to handle filesystem attributes
266
+ """Options for how to handle filesystem attributes.
269
267
 
270
268
  :param one_file_system: stay in the same file system and do not store mount points of other
271
269
  file systems. This might behave different from your expectations, see the docs.
@@ -306,23 +304,23 @@ class FilesystemOptions(OptionsBase):
306
304
  files_cache: str = None
307
305
  read_special: bool = False
308
306
 
309
- # pylint: disable=useless-super-delegation
310
307
  def __init__(self, **kwargs):
308
+ """Set the filesystem options for many commands."""
311
309
  super().__init__(**kwargs)
312
310
 
313
311
 
314
312
  @dataclass
315
313
  class ArchiveOptions(OptionsBase):
316
- """Options related to the archive"""
314
+ """Options related to the archive."""
317
315
 
318
- # pylint: disable=useless-super-delegation
319
316
  def __init__(self, **kwargs):
317
+ """Set the archive options for many commands."""
320
318
  super().__init__(**kwargs)
321
319
 
322
320
 
323
321
  @dataclass
324
322
  class ArchiveInput(ArchiveOptions):
325
- """Archive Options when inputing data to the archive
323
+ """Archive Options when inputing data to the archive.
326
324
 
327
325
  :param comment: add a comment text to the archive
328
326
  :type comment: str
@@ -345,14 +343,14 @@ class ArchiveInput(ArchiveOptions):
345
343
  chunker_params: str = None
346
344
  compression: str = None
347
345
 
348
- # pylint: disable=useless-super-delegation
349
346
  def __init__(self, **kwargs):
347
+ """Set the input options for archives for many commands."""
350
348
  super().__init__(**kwargs)
351
349
 
352
350
 
353
351
  @dataclass
354
352
  class ArchivePattern(ArchiveOptions):
355
- """Archive Options when outputing data in the archive
353
+ """Archive Options when outputing data in the archive.
356
354
 
357
355
  :param prefix: only consider archive names starting with this prefix.
358
356
  :type prefix: str
@@ -365,14 +363,14 @@ class ArchivePattern(ArchiveOptions):
365
363
  prefix: str = None
366
364
  glob_archives: str = None
367
365
 
368
- # pylint: disable=useless-super-delegation
369
366
  def __init__(self, **kwargs):
367
+ """Set the output pattern options for archives many commands."""
370
368
  super().__init__(**kwargs)
371
369
 
372
370
 
373
371
  @dataclass
374
372
  class ArchiveOutput(ArchivePattern):
375
- """Archive options when filtering output
373
+ """Archive options when filtering output.
376
374
 
377
375
  :param sort_by: Comma-separated list of sorting keys; valid keys are: timestamp, name, id;
378
376
  default is: timestamp
@@ -387,14 +385,14 @@ class ArchiveOutput(ArchivePattern):
387
385
  first: int = None
388
386
  last: int = None
389
387
 
390
- # pylint: disable=useless-super-delegation
391
388
  def __init__(self, **kwargs):
389
+ """Set the output options for archives many commands."""
392
390
  super().__init__(**kwargs)
393
391
 
394
392
 
395
393
  @dataclass
396
394
  class InitOptional(OptionsBase):
397
- """Init command options
395
+ """Init command options.
398
396
 
399
397
  :param append_only: create an append-only mode repository
400
398
  :type append_only: bool
@@ -410,15 +408,14 @@ class InitOptional(OptionsBase):
410
408
  storage_quota: str = None
411
409
  make_parent_dirs: bool = False
412
410
 
413
- # pylint: disable=useless-super-delegation
414
411
  def __init__(self, **kwargs):
412
+ """Set the options for the `init` command."""
415
413
  super().__init__(**kwargs)
416
414
 
417
415
 
418
- # pylint: disable=too-many-instance-attributes
419
416
  @dataclass
420
417
  class CreateOptional(OptionsBase):
421
- """Create command options
418
+ """Create command options.
422
419
 
423
420
  :param dry_run: do not create a backup archive
424
421
  :type dry_run: bool
@@ -462,14 +459,14 @@ class CreateOptional(OptionsBase):
462
459
  stdin_group: str = None
463
460
  stdin_mode: str = None
464
461
 
465
- # pylint: disable=useless-super-delegation
466
462
  def __init__(self, **kwargs):
463
+ """Set the options for the `create` command."""
467
464
  super().__init__(**kwargs)
468
465
 
469
466
 
470
467
  @dataclass
471
468
  class ExtractOptional(OptionsBase):
472
- """Extract command options
469
+ """Extract command options.
473
470
 
474
471
  :param list: output verbose list of items (files, dirs, …)
475
472
  :type list: bool
@@ -498,14 +495,14 @@ class ExtractOptional(OptionsBase):
498
495
  stdout: bool = False
499
496
  sparse: bool = False
500
497
 
501
- # pylint: disable=useless-super-delegation
502
498
  def __init__(self, **kwargs):
499
+ """Set the options for the `extract` command."""
503
500
  super().__init__(**kwargs)
504
501
 
505
502
 
506
503
  @dataclass
507
504
  class CheckOptional(OptionsBase):
508
- """Check command options
505
+ """Check command options.
509
506
 
510
507
  :param repository_only: only perform repository checks
511
508
  :type repository_only: bool
@@ -526,14 +523,14 @@ class CheckOptional(OptionsBase):
526
523
  repair: bool = False
527
524
  save_space: bool = False
528
525
 
529
- # pylint: disable=useless-super-delegation
530
526
  def __init__(self, **kwargs):
527
+ """Set the options for the `check` command."""
531
528
  super().__init__(**kwargs)
532
529
 
533
530
 
534
531
  @dataclass
535
532
  class ListOptional(OptionsBase):
536
- """List command options
533
+ """List command options.
537
534
 
538
535
  :param short: only print file/directory names, nothing else
539
536
  :type short: bool
@@ -557,14 +554,14 @@ class ListOptional(OptionsBase):
557
554
  json: bool = False
558
555
  json_lines: bool = False
559
556
 
560
- # pylint: disable=useless-super-delegation
561
557
  def __init__(self, **kwargs):
558
+ """Set the options for the `list` command."""
562
559
  super().__init__(**kwargs)
563
560
 
564
561
 
565
562
  @dataclass
566
563
  class DiffOptional(OptionsBase):
567
- """Diff command options
564
+ """Diff command options.
568
565
 
569
566
  :param numeric_owner: only consider numeric user and group identifiers
570
567
  :type numeric_owner: bool
@@ -581,8 +578,8 @@ class DiffOptional(OptionsBase):
581
578
  sort: bool = False
582
579
  json_lines: bool = False
583
580
 
584
- # pylint: disable=useless-super-delegation
585
581
  def __init__(self, **kwargs):
582
+ """Set the options for the `diff` command."""
586
583
  super().__init__(**kwargs)
587
584
 
588
585
  self._log_deprecated("numeric_owner", "numeric_ids")
@@ -590,7 +587,7 @@ class DiffOptional(OptionsBase):
590
587
 
591
588
  @dataclass
592
589
  class DeleteOptional(OptionsBase):
593
- """Delete command options
590
+ """Delete command options.
594
591
 
595
592
  :param dry_run: do not change repository
596
593
  :type dry_run: bool
@@ -605,20 +602,22 @@ class DeleteOptional(OptionsBase):
605
602
  """
606
603
 
607
604
  dry_run: bool = False
605
+ list: bool = False
608
606
  stats: bool = False
609
607
  cache_only: bool = False
610
608
  force: bool = False
609
+ keep_security_info: bool = False
611
610
  save_space: bool = False
611
+ checkpoint_interval: int = 1800
612
612
 
613
- # pylint: disable=useless-super-delegation
614
613
  def __init__(self, **kwargs):
614
+ """Set the options for the `delete` command."""
615
615
  super().__init__(**kwargs)
616
616
 
617
617
 
618
- # pylint: disable=too-many-instance-attributes
619
618
  @dataclass
620
619
  class PruneOptional(OptionsBase):
621
- """Prune command options
620
+ """Prune command options.
622
621
 
623
622
  :param dry_run: do not change repository
624
623
  :type dry_run: bool
@@ -665,14 +664,14 @@ class PruneOptional(OptionsBase):
665
664
  keep_yearly: int = None
666
665
  save_space: bool = False
667
666
 
668
- # pylint: disable=useless-super-delegation
669
667
  def __init__(self, **kwargs):
668
+ """Set the options for the `prune` command."""
670
669
  super().__init__(**kwargs)
671
670
 
672
671
 
673
672
  @dataclass
674
673
  class CompactOptional(OptionsBase):
675
- """Compact command options
674
+ """Compact command options.
676
675
 
677
676
  :param cleanup_commits: cleanup commit-only 17-byte segment files
678
677
  :type cleanup_commits: bool
@@ -683,14 +682,14 @@ class CompactOptional(OptionsBase):
683
682
  cleanup_commits: bool = False
684
683
  threshold: int = 10
685
684
 
686
- # pylint: disable=useless-super-delegation
687
685
  def __init__(self, **kwargs):
686
+ """Set the options for the `compact` command."""
688
687
  super().__init__(**kwargs)
689
688
 
690
689
 
691
690
  @dataclass
692
691
  class InfoOptional(OptionsBase):
693
- """Info command options
692
+ """Info command options.
694
693
 
695
694
  :param json: format output as JSON
696
695
  :type json: bool
@@ -698,15 +697,14 @@ class InfoOptional(OptionsBase):
698
697
 
699
698
  json: bool = False
700
699
 
701
- # pylint: disable=useless-super-delegation
702
700
  def __init__(self, **kwargs):
701
+ """Set the options for the `info` command."""
703
702
  super().__init__(**kwargs)
704
703
 
705
704
 
706
- # pylint: disable=invalid-name
707
705
  @dataclass
708
706
  class MountOptional(OptionsBase):
709
- """Mount command options
707
+ """Mount command options.
710
708
 
711
709
  :param foreground: stay in foreground, do not daemonize
712
710
  :type foreground: bool
@@ -717,14 +715,14 @@ class MountOptional(OptionsBase):
717
715
  foreground: bool = True
718
716
  o: str = None
719
717
 
720
- # pylint: disable=useless-super-delegation
721
718
  def __init__(self, **kwargs):
719
+ """Set the options for the `mount` command."""
722
720
  super().__init__(**kwargs)
723
721
 
724
722
 
725
723
  @dataclass
726
724
  class KeyExportOptional(OptionsBase):
727
- """Key Export command options
725
+ """Key Export command options.
728
726
 
729
727
  :param paper: create an export suitable for printing and later type-in
730
728
  :type paper: bool
@@ -735,14 +733,14 @@ class KeyExportOptional(OptionsBase):
735
733
  paper: bool = False
736
734
  qr_html: bool = False
737
735
 
738
- # pylint: disable=useless-super-delegation
739
736
  def __init__(self, **kwargs):
737
+ """Set the options for the `key export` command."""
740
738
  super().__init__(**kwargs)
741
739
 
742
740
 
743
741
  @dataclass
744
742
  class KeyImportOptional(OptionsBase):
745
- """Key Import command options
743
+ """Key Import command options.
746
744
 
747
745
  :param paper: interactively import from a backup done with `paper`
748
746
  :type paper: bool
@@ -750,14 +748,14 @@ class KeyImportOptional(OptionsBase):
750
748
 
751
749
  paper: bool = False
752
750
 
753
- # pylint: disable=useless-super-delegation
754
751
  def __init__(self, **kwargs):
752
+ """Set the options for the `key import` command."""
755
753
  super().__init__(**kwargs)
756
754
 
757
755
 
758
756
  @dataclass
759
757
  class UpgradeOptional(OptionsBase):
760
- """Upgrade command options
758
+ """Upgrade command options.
761
759
 
762
760
  :param dry_run: do not change repository
763
761
  :type dry_run: bool
@@ -778,14 +776,79 @@ class UpgradeOptional(OptionsBase):
778
776
  tam: bool = False
779
777
  disable_tam: bool = False
780
778
 
781
- # pylint: disable=useless-super-delegation
782
779
  def __init__(self, **kwargs):
780
+ """Set the options for the `upgrade` command."""
781
+ super().__init__(**kwargs)
782
+
783
+
784
+ @dataclass
785
+ class RecreateOptional(OptionsBase):
786
+ """Recreate command options.
787
+
788
+ :param list: output verbose list of items (files, dirs, …)
789
+ :type list: bool
790
+ :param filter: only display items with the given status characters
791
+ (listed in borg create --help)
792
+ :type filter: str
793
+ :param dry_run: do not change anything
794
+ :type dry_run: bool
795
+ :param stats: print statistics at end
796
+ :type stats: bool
797
+ :param target: create a new archive with the name ARCHIVE, do not replace existing archive
798
+ (only applies for a single archive)
799
+ :type target: str
800
+ :param recompress: recompress data chunks according to MODE and --compression. Possible modes
801
+ are `if-different`, `always`, `never`. If no MODE is given, if-different will be used.
802
+ :type recompress: str
803
+ """
804
+
805
+ list: bool = False
806
+ filter: str = None
807
+ dry_run: bool = False
808
+ stats: bool = False
809
+
810
+ # Custom Archive Options
811
+ target: str = None
812
+ recompress: str = None
813
+
814
+ def __init__(self, **kwargs):
815
+ """Set the options for the `recreate` command."""
816
+ super().__init__(**kwargs)
817
+
818
+
819
+ @dataclass
820
+ class ImportTarOptional(OptionsBase):
821
+ """Import Tar command options.
822
+
823
+ :param tar_filter: filter program to pipe data through
824
+ :type tar_filter: str
825
+ :param stats: print statistics for the created archive
826
+ :type stats: bool
827
+ :param list: output verbose list of items (files, dirs, …)
828
+ :type list: bool
829
+ :param filter: only display items with the given status characters
830
+ :type filter: str
831
+ :param json: output stats as JSON. Implies `stats`
832
+ :type json: bool
833
+ :param ignore_zeros: ignore zero-filled blocks in the input tarball
834
+ :type ignore_zeros: bool
835
+ """
836
+
837
+ tar_filter: str = None
838
+ stats: bool = False
839
+ list: bool = False
840
+ filter: str = None
841
+ json: bool = False
842
+ ignore_zeros: bool = False
843
+
844
+ def __init__(self, **kwargs):
845
+ """Set the options for the `import-tar` command."""
783
846
  super().__init__(**kwargs)
784
847
 
785
848
 
786
849
  @dataclass
787
850
  class ExportTarOptional(OptionsBase):
788
- """Export Tar command options
851
+ """Export Tar command options.
789
852
 
790
853
  :param tar_filter: filter program to pipe data through
791
854
  :type tar_filter: str
@@ -796,14 +859,14 @@ class ExportTarOptional(OptionsBase):
796
859
  tar_filter: str = None
797
860
  list: bool = False
798
861
 
799
- # pylint: disable=useless-super-delegation
800
862
  def __init__(self, **kwargs):
863
+ """Set the options for the `export-tar` command."""
801
864
  super().__init__(**kwargs)
802
865
 
803
866
 
804
867
  @dataclass
805
868
  class ServeOptional(OptionsBase):
806
- """Serve command options
869
+ """Serve command options.
807
870
 
808
871
  :param restrict_to_path: restrict repository access to PATH.
809
872
  Can be specified multiple times to allow the client access to several directories.
@@ -831,14 +894,14 @@ class ServeOptional(OptionsBase):
831
894
  append_only: bool = False
832
895
  storage_quota: str = None
833
896
 
834
- # pylint: disable=useless-super-delegation
835
897
  def __init__(self, **kwargs):
898
+ """Set the options for the `serve` command."""
836
899
  super().__init__(**kwargs)
837
900
 
838
901
 
839
902
  @dataclass
840
903
  class ConfigOptional(OptionsBase):
841
- """Config command options
904
+ """Config command options.
842
905
 
843
906
  :param cache: get and set values from the repo cache
844
907
  :type cache: bool
@@ -852,13 +915,13 @@ class ConfigOptional(OptionsBase):
852
915
  delete: bool = False
853
916
  list: bool = False
854
917
 
855
- # pylint: disable=useless-super-delegation
856
918
  def __init__(self, **kwargs):
919
+ """Set the options for the `config` command."""
857
920
  super().__init__(**kwargs)
858
921
 
859
922
 
860
923
  class CommandOptions:
861
- """Optional Arguments for the different commands"""
924
+ """Optional Arguments for the different commands."""
862
925
 
863
926
  optional_classes = {
864
927
  "init": InitOptional,
@@ -875,12 +938,19 @@ class CommandOptions:
875
938
  "key_export": KeyExportOptional,
876
939
  "key_import": KeyImportOptional,
877
940
  "upgrade": UpgradeOptional,
941
+ "recreate": RecreateOptional,
942
+ "import_tar": ImportTarOptional,
878
943
  "export_tar": ExportTarOptional,
879
944
  "serve": ServeOptional,
880
945
  "config": ConfigOptional,
881
946
  }
882
947
 
883
948
  def __init__(self, defaults: dict = None):
949
+ """Set the defaults used for all commands.
950
+
951
+ :param defaults: Specific flags to use for all commands, defaults to None
952
+ :type defaults: dict, optional
953
+ """
884
954
  self.defaults = defaults or {}
885
955
 
886
956
  @classmethod
@@ -893,7 +963,7 @@ class CommandOptions:
893
963
  ) from e
894
964
 
895
965
  def get(self, command: str, values: dict) -> OptionsBase:
896
- """Return OptionsBase with flags set for `command`
966
+ """Return OptionsBase with flags set for `command`.
897
967
 
898
968
  :param command: command being called
899
969
  :type command: str
@@ -902,12 +972,11 @@ class CommandOptions:
902
972
  :return: instance of command dataclass
903
973
  :rtype: OptionsBase
904
974
  """
905
-
906
975
  optionals = {**self.defaults.get(command, {}), **(values or {})}
907
976
  return self._get_optional(command)(**optionals)
908
977
 
909
978
  def to_list(self, command: str, values: dict) -> list:
910
- """Parsed args list for command
979
+ """Parse args list for command.
911
980
 
912
981
  :param command: command name
913
982
  :type command: str