From ced90ed2cae1b55ef9574cf128bb4ff16d3ab012 Mon Sep 17 00:00:00 2001 From: user01 Date: Fri, 28 Aug 2026 16:52:21 +0900 Subject: [PATCH] =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EB=A6=AC=EB=B7=B0,=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=ED=8C=8C=EC=9D=BC=20=EC=9D=B4=EB=A6=84?= =?UTF-8?q?=EC=9D=84=20=ED=8C=8C=EC=8B=B1=ED=95=B4=EC=84=9C=20=EA=B0=81=20?= =?UTF-8?q?=ED=95=AD=EB=AA=A9=EC=97=90=20=EC=82=BD=EC=9E=85=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EC=84=A4=EB=AA=85=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- UtilPack.py | 36 ++++++++++-------------------------- main.py | 36 +++++++++++++++++++++++++++--------- requirements.txt | 1 + 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/UtilPack.py b/UtilPack.py index 4162ba8..e9e7cd3 100644 --- a/UtilPack.py +++ b/UtilPack.py @@ -7,6 +7,7 @@ import shutil import difflib import subprocess import hashlib +import glob try: import rarfile @@ -244,36 +245,19 @@ def CreateZIP(output_zip: str, files: list[str]) -> bool: # 파일 리스트에 들어있는 파일만 골라서 압축을 합니다. 상대경로를 제거하는게 기본값. def CreateZIPShell(zipName: str, files: list[str], bRmvRPath: bool = True) -> bool: - command = "zip " - + command = ["zip"] if True == bRmvRPath: - command += "-j " - - command += f"\"{zipName}\" " - - # 이중 리스트인 이유를 모르겠다. - for file in files: - command += f"\"{file}\" " - - result = subprocess.run(command, shell=True, capture_output=True, text=True) - - bRet = False - if 0 == result.returncode: - bRet = True - - return bRet + command.append("-j") + command.extend([zipName, *files]) + result = subprocess.run(command, capture_output=True, text=True) + return result.returncode == 0 # 특정 확장자만 쉘을 이용해서 압축한다 def CreateZIPShExt(zipName: str, TrgExt: str)-> bool: - command = f"zip -j {zipName} *.{TrgExt}" - - result = subprocess.run(command, shell=True, capture_output=True, text=True) - - bRet = False - if 0 == result.returncode: - bRet = True - - return bRet + matching_files = glob.glob(f"*.{TrgExt}") + command = ["zip", "-j", zipName, *matching_files] + result = subprocess.run(command, capture_output=True, text=True) + return result.returncode == 0 # 압축 파일 내의 모든 파일 및 디렉토리 목록 가져오기 def GetZipContentList(path: str) -> list[str]: diff --git a/main.py b/main.py index da1d31c..4d55657 100755 --- a/main.py +++ b/main.py @@ -26,7 +26,17 @@ DEFAULT_VALUES = { # def main(argc, argv): - parser = argparse.ArgumentParser(description="ComicInfo.XML 생성기") + parser = argparse.ArgumentParser( + description="ComicInfo.XML 생성기", + formatter_class=argparse.RawDescriptionHelpFormatter, + epilog=( + "사용 예시:\n" + " 폴더명이 '[작가] 제목'인 경우:\n" + " python3 main.py --in \"/path/[작가] 제목/book.cbz\" " + "--title ':s/^\\[([^\\]]+)\\]\\s*(.+)$/$2/' " + "--author ':s/^\\[([^\\]]+)\\]\\s*(.+)$/$1/'" + ), + ) parser.add_argument('--root', dest='root_dir', required=False, help='입력 폴더 지정') parser.add_argument('--in', dest='arc_file', required=False, help='대상 파일 지정') parser.add_argument('--title', dest='info_title', required=False, help='제목') @@ -198,15 +208,21 @@ def ExpandPathVars(text: str | None, filepath: str) -> str | None: for key, value in var_map.items(): result = result.replace(f"<{key}>", value) - # After variable expansion, check for :s/pattern/replacement/ or s/pattern/replacement/ suffix - m = re.match(r'^(.*):?s(.)(.+?)\2(.*?)(?:\2([ig]*))?$', result, re.DOTALL) + # After variable expansion, check for :s/pattern/replacement/ suffix. + transform_pos = result.find(':s') + if transform_pos >= 0: + source = result[:transform_pos] + transform = result[transform_pos + 1:] + m = re.match(r'^s(?P.)(?P.*?)(?P=delim)(?P.*?)(?P=delim)(?P[ig]*)$', transform, re.DOTALL) + else: + source = '' + m = None + if m: - source = m.group(1) - delim = m.group(2) - pattern = m.group(3) - replacement = m.group(4) - flags_str = m.group(5) or '' - replacement_safe = re.sub(r'\$(\d+)', r'\\\1', replacement) + pattern = m.group('pattern') + replacement = m.group('replacement') + flags_str = m.group('flags') + replacement_safe = re.sub(r'\$(\d+)', lambda match: '\\' + match.group(1), replacement) flags = 0 if 'i' in flags_str: flags |= re.IGNORECASE @@ -311,6 +327,7 @@ def ValidateAndFixComicInfoXML(xml_bytes: bytes) -> tuple[bytes | None, list[str msgs.append("XML is now well-formed.") except ET.ParseError as e2: msgs.append(f"Remaining issues after fix: {e2}") + return (None, msgs) return (fixed_bytes, msgs) msgs.append("No fixable issues found.") @@ -604,6 +621,7 @@ def ProcessMetadataToCBZ(strArcPath: str, bPrint: bool = False, xml_content = output.getvalue().decode('utf-8') except Exception as e: util.DbgOut(f"XML 수정 중 오류: {e}", True) + return False # 출력 옵션이 켜져 있으면 내용 출력 if True == bPrint: diff --git a/requirements.txt b/requirements.txt index f5c5f0a..f7a0182 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ rarfile>=4.0 +comicapi