Apply consistent Python and Django coding standards
This commit is contained in:
1 parent
1d0b5adeee
commit
d7314fa927
61 files changed
+1829
-603
No files matched your search
+37
-12
@@ -81,11 +81,15 @@ class BackupInventory:
|
||||
self.primary_domain = canonical_domain(settings["domain"])
|
||||
self.domain(self.primary_domain)
|
||||
case ("backup", "domains.list"):
|
||||
for line in self.read_metadata(archive, member, parts).splitlines():
|
||||
for line in self.read_metadata(
|
||||
archive, member, parts
|
||||
).splitlines():
|
||||
if line.strip():
|
||||
self.domain(line.strip())
|
||||
case ("backup", filename):
|
||||
if match := re.fullmatch(r"([a-zA-Z0-9_]{1,64})\.sql", filename):
|
||||
if match := re.fullmatch(
|
||||
r"([a-zA-Z0-9_]{1,64})\.sql", filename
|
||||
):
|
||||
self.databases.add(match[1])
|
||||
if filename in HOME_ARCHIVES:
|
||||
self.home_archive = True
|
||||
@@ -100,7 +104,12 @@ class BackupInventory:
|
||||
tail and tail != [".direct_imap_backup"]
|
||||
):
|
||||
self.domain(domain).mail_files += 1
|
||||
case ("domains", domain, "public_html" | "private_html", *tail) if tail:
|
||||
case (
|
||||
"domains",
|
||||
domain,
|
||||
"public_html" | "private_html",
|
||||
*tail,
|
||||
) if tail:
|
||||
self.domain(domain).website_files += 1
|
||||
case ("domains", domain, "domain.conf"):
|
||||
self.domain(domain)
|
||||
@@ -161,7 +170,9 @@ def read_account_settings(text):
|
||||
key, separator, value = line.partition("=")
|
||||
if separator and key in {"username", "domain"}:
|
||||
if key in settings:
|
||||
raise ValueError("The account metadata repeats an identity field.")
|
||||
raise ValueError(
|
||||
"The account metadata repeats an identity field."
|
||||
)
|
||||
settings[key] = value.strip()
|
||||
username = settings.get("username", "")
|
||||
if not re.fullmatch(r"[a-zA-Z0-9][a-zA-Z0-9_-]{0,31}", username):
|
||||
@@ -188,7 +199,9 @@ def archive_stream(path):
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
except FileNotFoundError:
|
||||
raise ValueError("Install zstd to inspect Zstandard backups.") from None
|
||||
raise ValueError(
|
||||
"Install zstd to inspect Zstandard backups."
|
||||
) from None
|
||||
with decoder:
|
||||
try:
|
||||
yield decoder.stdout
|
||||
@@ -196,7 +209,9 @@ def archive_stream(path):
|
||||
decoder.kill()
|
||||
raise
|
||||
if decoder.wait():
|
||||
raise ValueError("The Zstandard backup is damaged or incomplete.")
|
||||
raise ValueError(
|
||||
"The Zstandard backup is damaged or incomplete."
|
||||
)
|
||||
else:
|
||||
yield source
|
||||
|
||||
@@ -205,7 +220,9 @@ def check_tar_padding(archive):
|
||||
size = 0
|
||||
while chunk := archive.fileobj.read(64 * 1024):
|
||||
if chunk.strip(b"\0"):
|
||||
raise ValueError("Unexpected data after the end of the tar archive.")
|
||||
raise ValueError(
|
||||
"Unexpected data after the end of the tar archive."
|
||||
)
|
||||
size += len(chunk)
|
||||
if size < tarfile.BLOCKSIZE:
|
||||
raise ValueError("The tar archive is missing its end marker.")
|
||||
@@ -223,7 +240,9 @@ def open_backup(path):
|
||||
try:
|
||||
with (
|
||||
archive_stream(path) as stream,
|
||||
tarfile.open(fileobj=stream, mode="r|", tarinfo=BackupTarInfo) as archive,
|
||||
tarfile.open(
|
||||
fileobj=stream, mode="r|", tarinfo=BackupTarInfo
|
||||
) as archive,
|
||||
):
|
||||
yield archive
|
||||
except (EOFError, tarfile.TarError, zlib.error, gzip.BadGzipFile):
|
||||
@@ -235,7 +254,7 @@ def open_backup(path):
|
||||
def backup_members(archive):
|
||||
while (member := archive.next()) is not None:
|
||||
yield member
|
||||
# The reader only walks forward and does not need tarfile's member cache.
|
||||
# Forward-only reads do not need tarfile's member cache.
|
||||
archive.members.clear()
|
||||
check_tar_padding(archive)
|
||||
|
||||
@@ -256,19 +275,25 @@ def main(argv=None):
|
||||
)
|
||||
inspect.add_argument("backup", type=Path)
|
||||
stage = commands.add_parser(
|
||||
"stage-website", help="Stage one DirectAdmin website in a new local directory."
|
||||
"stage-website",
|
||||
help="Stage one DirectAdmin website in a new local directory.",
|
||||
)
|
||||
stage.add_argument("backup", type=Path)
|
||||
stage.add_argument("domain")
|
||||
stage.add_argument("destination", type=Path)
|
||||
stage.add_argument("--source-root", choices=DOCUMENT_ROOTS, default="public_html")
|
||||
stage.add_argument(
|
||||
"--source-root", choices=DOCUMENT_ROOTS, default="public_html"
|
||||
)
|
||||
args = parser.parse_args(argv)
|
||||
try:
|
||||
if args.command == "stage-website":
|
||||
from .directadmin_website import stage_website
|
||||
|
||||
report = stage_website(
|
||||
args.backup, args.domain, args.destination, source_root=args.source_root
|
||||
args.backup,
|
||||
args.domain,
|
||||
args.destination,
|
||||
source_root=args.source_root,
|
||||
)
|
||||
else:
|
||||
report = inspect_backup(args.backup)
|
||||
|
||||
Reference in new issue
Block a user