Update broken/incomplete code to match type interfaces

This commit is contained in:
Kevin Baensch 2024-11-23 23:32:57 +01:00
parent dd4c963667
commit 06b282e7cd
Signed by: derped
GPG key ID: C0F1D326C7626543

View file

@ -1,5 +1,6 @@
from typing import Generator, List, Tuple
from os import listdir, path
from typing import Generator, List
from .file import FILE
@ -37,32 +38,47 @@ def search(pathlist: List[str]) -> Generator[str, None, None]:
print(f"[WARN]: No such file or directory: {fpath}")
def sfv_read(filename: str) -> Generator[FILE, None, None]:
def sfv_read(filename: str) -> Generator[str, None, None]:
"""
Read sfv file.
"""
try:
with open(filename, 'r') as file:
yield from (FILE(' '.join(x.split()[:-1]), x.split()[-1])
for x in file.read().split('\n')
if len(x) != 0 and x[0] != ';')
with open(filename, "r") as file:
yield from (
" ".join(x.split()[:-1])
for x in file.read().split("\n")
if len(x) != 0 and x[0] != ";"
)
except UnicodeDecodeError:
print(f"[ERR]: {filename} is not a text file.")
except FileNotFoundError:
print(f"[WARN]: No such file or directory: {filename}")
def sfv_write(checked_files: List[Tuple[str, str, bool]], filename: str) -> None:
def file_write(outpath: str, files: List[FILE]) -> bool:
try:
with open(outpath, "w") as file:
files.sort()
# add csum checks here
[file.write(x.mkFileStr()) for x in files]
except FileExistsError:
return False
return True
def sfv_write(checked_files: List[FILE], filename: str) -> None:
"""
Write sfv file.
"""
try:
with open(filename, 'w') as file:
with open(filename, "w") as cfile:
checked_files.sort()
if any([not x[2] for x in checked_files]):
print(f"[WARN]: {filename} will contain unverified checksums.")
# [file.write(f"{str(x[0])}\t{str(x[1])}") for x in checked_files]
for file in checked_files:
if repr(file.csum) == file.csum.NULL:
print(f"Skipping: {file!r} because no checksum was generated")
else:
cfile.write(f"{file!r}\t{file.csum!r}")
file.write('\n'.join([x for x in ["hello" "world"]]))
# file.write('\n'.join([x for x in ["hello" "world"]]))
except FileExistsError:
pass