refactor(clew): stop managing logs directory
This commit is contained in:
@@ -10,7 +10,7 @@ from pathlib import Path
|
|||||||
from rpycdec.rpa import extract_rpa
|
from rpycdec.rpa import extract_rpa
|
||||||
|
|
||||||
LOGGER = logging.getLogger("clew")
|
LOGGER = logging.getLogger("clew")
|
||||||
MANAGED_DIRS = ("extracted", "logs")
|
MANAGED_DIRS = ("extracted",)
|
||||||
|
|
||||||
|
|
||||||
def parse_args(argv: list[str]) -> argparse.Namespace:
|
def parse_args(argv: list[str]) -> argparse.Namespace:
|
||||||
@@ -54,7 +54,7 @@ def resolve_output_root(output_root: Path) -> Path:
|
|||||||
return output_root.resolve()
|
return output_root.resolve()
|
||||||
|
|
||||||
|
|
||||||
def prepare_output(output_root: Path, overwrite: bool) -> tuple[Path, Path]:
|
def prepare_output(output_root: Path, overwrite: bool) -> Path:
|
||||||
for name in MANAGED_DIRS:
|
for name in MANAGED_DIRS:
|
||||||
path = output_root / name
|
path = output_root / name
|
||||||
if path.exists() and not overwrite:
|
if path.exists() and not overwrite:
|
||||||
@@ -65,11 +65,9 @@ def prepare_output(output_root: Path, overwrite: bool) -> tuple[Path, Path]:
|
|||||||
shutil.rmtree(output_root / name, ignore_errors=True)
|
shutil.rmtree(output_root / name, ignore_errors=True)
|
||||||
|
|
||||||
extracted_dir = output_root / "extracted"
|
extracted_dir = output_root / "extracted"
|
||||||
logs_dir = output_root / "logs"
|
extracted_dir.mkdir(parents=True, exist_ok=True)
|
||||||
for path in (extracted_dir, logs_dir):
|
|
||||||
path.mkdir(parents=True, exist_ok=True)
|
|
||||||
|
|
||||||
return extracted_dir, logs_dir
|
return extracted_dir
|
||||||
|
|
||||||
|
|
||||||
def relative_to(root: Path, path: Path) -> Path:
|
def relative_to(root: Path, path: Path) -> Path:
|
||||||
@@ -114,17 +112,8 @@ def extract_archive(
|
|||||||
LOGGER.info("extracted archive: %s", archive_relative)
|
LOGGER.info("extracted archive: %s", archive_relative)
|
||||||
|
|
||||||
|
|
||||||
def configure_logging(logs_dir: Path) -> None:
|
def configure_logging() -> None:
|
||||||
log_file = logs_dir / "clew.log"
|
logging.basicConfig(level=logging.INFO, format="%(message)s")
|
||||||
formatter = logging.Formatter("%(message)s")
|
|
||||||
|
|
||||||
file_handler = logging.FileHandler(log_file, encoding="utf-8")
|
|
||||||
file_handler.setFormatter(formatter)
|
|
||||||
|
|
||||||
stream_handler = logging.StreamHandler()
|
|
||||||
stream_handler.setFormatter(formatter)
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO, handlers=[file_handler, stream_handler])
|
|
||||||
|
|
||||||
|
|
||||||
def run(args: argparse.Namespace) -> None:
|
def run(args: argparse.Namespace) -> None:
|
||||||
@@ -135,8 +124,8 @@ def run(args: argparse.Namespace) -> None:
|
|||||||
raise SystemExit(f"clew: game root is not a directory: {game_root}")
|
raise SystemExit(f"clew: game root is not a directory: {game_root}")
|
||||||
|
|
||||||
suffixes = normalize_suffixes(args.suffix)
|
suffixes = normalize_suffixes(args.suffix)
|
||||||
extracted_dir, logs_dir = prepare_output(output_root, args.overwrite)
|
configure_logging()
|
||||||
configure_logging(logs_dir)
|
extracted_dir = prepare_output(output_root, args.overwrite)
|
||||||
|
|
||||||
LOGGER.info("copying loose files")
|
LOGGER.info("copying loose files")
|
||||||
for file in sorted(game_root.rglob("*")):
|
for file in sorted(game_root.rglob("*")):
|
||||||
|
|||||||
Reference in New Issue
Block a user