Browse Source

backup: tweak types for python 3.7 compatibility

master
Jim Paris 2 years ago
parent
commit
643f41d7f7
1 changed files with 11 additions and 9 deletions
  1. +11
    -9
      backup.py

+ 11
- 9
backup.py View File

@@ -29,12 +29,12 @@ def format_size(n: int) -> str:
return humanfriendly.format_size(n, keep_width=True, binary=True)

class Config:
roots: list[bytes]
roots: typing.List[bytes]
max_file_size: typing.Optional[int]
one_file_system: bool
exclude_caches: bool
exclude: list[bytes]
force_include: list[bytes]
exclude: typing.List[bytes]
force_include: typing.List[bytes]
notify_email: typing.Optional[str]

def __init__(self, configfile: str):
@@ -93,8 +93,10 @@ class Config:
self.force_include_re = ([ re.compile(x) for x in a ],
[ re.compile(x) for x in b ])

def match_re(self, re: tuple[list[typing.Pattern],
list[typing.Pattern]], path: bytes):
def match_re(self,
re: typing.Tuple[typing.List[typing.Pattern],
typing.List[typing.Pattern]],
path: bytes):
# Path matches if it matches at least one regex in
# re[0] and no regex in re[1].
for a in re[0]:
@@ -109,10 +111,10 @@ class Backup:
def __init__(self, config: Config, dry_run: bool):
self.config = config
self.dry_run = dry_run
self.root_seen: dict[bytes, bool] = {}
self.root_seen: typing.Dict[bytes, bool] = {}

# Saved log messages
self.logs: list[tuple[str, str]] = []
self.logs: typing.List[typing.Tuple[str, str]] = []

def out(self, path: bytes):
self.outfile.write(path + (b'\n' if self.dry_run else b'\0'))
@@ -227,7 +229,7 @@ class Backup:
self.log('E', f"can't read {pstr(path)}: {str(e)}")
return

def main(argv: list[str]):
def main(argv: typing.List[str]):
import argparse

def humansize(string):
@@ -275,7 +277,7 @@ def main(argv: list[str]):
backup.log('W', f"failed to parse variables from {args.vars}: {str(e)}")

# Run backup
captured_output: list[bytes] = []
captured_output: typing.List[bytes] = []

if args.dry_run:
if args.debug:


Loading…
Cancel
Save