mirror of
https://github.com/borgbackup/borg.git
synced 2025-01-01 12:45:34 +00:00
subclass MakePathSafeAction from Highlander
This commit is contained in:
parent
438cf2e7ef
commit
db96c0c487
4 changed files with 18 additions and 17 deletions
|
@ -9,6 +9,7 @@
|
|||
from ..cache import Cache, assert_secure
|
||||
from ..helpers import Error
|
||||
from ..helpers import SortBySpec, positive_int_validator, location_validator, Location, relative_time_marker_validator
|
||||
from ..helpers import Highlander
|
||||
from ..helpers.nanorst import rst_to_terminal
|
||||
from ..manifest import Manifest, AI_HUMAN_SORT_KEYS
|
||||
from ..patterns import PatternMatcher
|
||||
|
@ -246,20 +247,6 @@ def wrapper(self, args, repository, manifest, **kwargs):
|
|||
return wrapper
|
||||
|
||||
|
||||
class Highlander(argparse.Action):
|
||||
"""make sure some option is only given once"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.__called = False
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def __call__(self, parser, namespace, values, option_string=None):
|
||||
if self.__called:
|
||||
raise argparse.ArgumentError(self, "There can be only one.")
|
||||
self.__called = True
|
||||
setattr(namespace, self.dest, values)
|
||||
|
||||
|
||||
# You can use :ref:`xyz` in the following usage pages. However, for plain-text view,
|
||||
# e.g. through "borg ... --help", define a substitution for the reference here.
|
||||
# It will replace the entire :ref:`foo` verbatim.
|
||||
|
|
|
@ -767,7 +767,7 @@ def build_parser_create(self, subparsers, common_parser, mid_common_parser):
|
|||
metavar="NAME",
|
||||
dest="stdin_name",
|
||||
default="stdin",
|
||||
action=MakePathSafeAction, # MakePathSafeAction maybe should subclass from Highlander.
|
||||
action=MakePathSafeAction,
|
||||
help="use NAME in archive for stdin data (default: %(default)r)",
|
||||
)
|
||||
subparser.add_argument(
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
from .parseformat import BaseFormatter, ArchiveFormatter, ItemFormatter, file_status
|
||||
from .parseformat import swidth_slice, ellipsis_truncate
|
||||
from .parseformat import BorgJsonEncoder, basic_json_data, json_print, json_dump, prepare_dump_dict
|
||||
from .parseformat import MakePathSafeAction
|
||||
from .parseformat import Highlander, MakePathSafeAction
|
||||
from .process import daemonize, daemonizing
|
||||
from .process import signal_handler, raising_signal_handler, sig_int, ignore_sigint, SigHup, SigTerm
|
||||
from .process import popen_with_error_handling, is_terminal, prepare_subprocess_env, create_filter_process
|
||||
|
|
|
@ -1149,7 +1149,21 @@ def decode(d):
|
|||
return decode(d)
|
||||
|
||||
|
||||
class MakePathSafeAction(argparse.Action):
|
||||
class Highlander(argparse.Action):
|
||||
"""make sure some option is only given once"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.__called = False
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def __call__(self, parser, namespace, values, option_string=None):
|
||||
if self.__called:
|
||||
raise argparse.ArgumentError(self, "There can be only one.")
|
||||
self.__called = True
|
||||
setattr(namespace, self.dest, values)
|
||||
|
||||
|
||||
class MakePathSafeAction(Highlander):
|
||||
def __call__(self, parser, namespace, path, option_string=None):
|
||||
try:
|
||||
sanitized_path = make_path_safe(path)
|
||||
|
|
Loading…
Reference in a new issue