add --fix-xml

압축파일 내의 경로를 제거하도록 util.py 수정
This commit is contained in:
2026-08-02 19:54:11 +09:00
parent 178776d307
commit a4e0ae0b08
2 changed files with 22 additions and 16 deletions

View File

@@ -232,10 +232,9 @@ def ExtractZIP(zip_file: str, extract_to: str):
# #
def CreateZIP(output_zip: str, files: list[str]) -> bool: def CreateZIP(output_zip: str, files: list[str]) -> bool:
with zipfile.ZipFile(output_zip, 'w') as zf: with zipfile.ZipFile(output_zip, 'w', compression=zipfile.ZIP_DEFLATED) as zf:
for file in files: for file in files:
pathTemp = os.path.join('root', os.path.basename(file)) zf.write(file, os.path.basename(file))
zf.write(file, pathTemp)
bRet = False bRet = False
if os.path.exists(output_zip): if os.path.exists(output_zip):

33
main.py
View File

@@ -93,10 +93,13 @@ def process_archive_file(archive_path: str, args: argparse.Namespace):
arc_number = ExpandPathVars(args.info_number, archive_path) arc_number = ExpandPathVars(args.info_number, archive_path)
arc_tags = args.info_tags.split(',') if args.info_tags else [] arc_tags = args.info_tags.split(',') if args.info_tags else []
# info_count를 int로 변환 (argparse에서 str로 파싱됨)
arc_count = int(args.info_count) if args.info_count is not None else None
# .metadata 옵션이 활성화된 경우 # .metadata 옵션이 활성화된 경우
if args.bMetadata: if args.bMetadata:
ProcessMetadataToCBZ(archive_path, args.bPrint, ProcessMetadataToCBZ(archive_path, args.bPrint,
arc_volume, arc_number, args.info_count, arc_volume, arc_number, arc_count,
arc_title, arc_writer, arc_series, arc_title, arc_writer, arc_series,
arc_tags if arc_tags else None) arc_tags if arc_tags else None)
return return
@@ -124,7 +127,7 @@ def process_archive_file(archive_path: str, args: argparse.Namespace):
comicinfo_xml_bytes = fixed_xml comicinfo_xml_bytes = fixed_xml
has_mods = any([arc_title, arc_writer, arc_series, arc_tags, has_mods = any([arc_title, arc_writer, arc_series, arc_tags,
arc_number, arc_volume, args.info_count]) arc_number, arc_volume, arc_count])
if not has_mods: if not has_mods:
if fixed_xml is not None: if fixed_xml is not None:
@@ -135,7 +138,7 @@ def process_archive_file(archive_path: str, args: argparse.Namespace):
return return
modified = ModComicInfoXML(comicinfo_xml_bytes, arc_title, arc_writer, arc_series, arc_tags, modified = ModComicInfoXML(comicinfo_xml_bytes, arc_title, arc_writer, arc_series, arc_tags,
info_number=arc_number, info_volume=arc_volume, info_count=args.info_count) info_number=arc_number, info_volume=arc_volume, info_count=arc_count)
if args.bPrint: if args.bPrint:
output = modified.decode('utf-8') if modified else comicinfo_xml_bytes.decode('utf-8') output = modified.decode('utf-8') if modified else comicinfo_xml_bytes.decode('utf-8')
@@ -148,7 +151,7 @@ def process_archive_file(archive_path: str, args: argparse.Namespace):
util.DbgOut(f"ComicInfo.xml 특수문자 수정 완료: {archive_path}", True) util.DbgOut(f"ComicInfo.xml 특수문자 수정 완료: {archive_path}", True)
else: else:
util.DbgOut(f"comicinfo.xml 없음: {archive_path}", True) util.DbgOut(f"comicinfo.xml 없음: {archive_path}", True)
if arc_volume or arc_number or arc_title or arc_writer or arc_series or arc_tags or args.info_count: if arc_volume or arc_number or arc_title or arc_writer or arc_series or arc_tags or arc_count is not None:
new_xml = CreateComicInfoXML( new_xml = CreateComicInfoXML(
info_title=arc_title or "", info_title=arc_title or "",
info_writer=arc_writer or "", info_writer=arc_writer or "",
@@ -157,7 +160,7 @@ def process_archive_file(archive_path: str, args: argparse.Namespace):
pages=[], pages=[],
volume=arc_volume or "", volume=arc_volume or "",
number=arc_number or "", number=arc_number or "",
count=int(args.info_count) if args.info_count is not None else -1 count=arc_count if arc_count is not None else -1
) )
if new_xml: if new_xml:
if args.bPrint: if args.bPrint:
@@ -173,7 +176,9 @@ def ExpandPathVars(text: str | None, filepath: str) -> str | None:
""" """
if not text: if not text:
return text return text
dirpath = os.path.dirname(filepath) # 경로 정규화: ./ 또는 ../ 등 상대 경로 표현을 제거하여 정확한 폴더명 추출
normpath = os.path.normpath(filepath)
dirpath = os.path.dirname(normpath)
cur_folder = os.path.basename(dirpath) if dirpath else "" cur_folder = os.path.basename(dirpath) if dirpath else ""
par_folder = os.path.basename(os.path.dirname(dirpath)) if dirpath and os.path.dirname(dirpath) else "" par_folder = os.path.basename(os.path.dirname(dirpath)) if dirpath and os.path.dirname(dirpath) else ""
filename_no_ext = os.path.splitext(os.path.basename(filepath))[0] filename_no_ext = os.path.splitext(os.path.basename(filepath))[0]
@@ -193,8 +198,8 @@ def ExpandPathVars(text: str | None, filepath: str) -> str | None:
for key, value in var_map.items(): for key, value in var_map.items():
result = result.replace(f"<{key}>", value) result = result.replace(f"<{key}>", value)
# After variable expansion, check for :s/pattern/replacement/ suffix # After variable expansion, check for :s/pattern/replacement/ or s/pattern/replacement/ suffix
m = re.match(r'^(.*):s(.)(.+?)\2(.*?)(?:\2([ig]*))?$', result, re.DOTALL) m = re.match(r'^(.*):?s(.)(.+?)\2(.*?)(?:\2([ig]*))?$', result, re.DOTALL)
if m: if m:
source = m.group(1) source = m.group(1)
delim = m.group(2) delim = m.group(2)
@@ -206,10 +211,12 @@ def ExpandPathVars(text: str | None, filepath: str) -> str | None:
if 'i' in flags_str: if 'i' in flags_str:
flags |= re.IGNORECASE flags |= re.IGNORECASE
count = 0 if 'g' in flags_str else 1 count = 0 if 'g' in flags_str else 1
try: # source가 비어있으면 정규식 미적용 (ResolveRegexTransform에서 처리)
result = re.sub(pattern, replacement_safe, source, count=count, flags=flags) if source:
except re.error: try:
pass result = re.sub(pattern, replacement_safe, source, count=count, flags=flags)
except re.error:
pass
return result return result
@@ -495,7 +502,7 @@ def ConvertLanguageToISO(lang_name: str) -> str:
# #
def ProcessMetadataToCBZ(strArcPath: str, bPrint: bool = False, def ProcessMetadataToCBZ(strArcPath: str, bPrint: bool = False,
volume: str = "-1", number: str = "", count: int = -1, volume: str = "-1", number: str = "", count: int | None = None,
info_title: str = None, info_writer: str = None, info_title: str = None, info_writer: str = None,
info_series: str = None, tags: list[str] = None) -> bool: info_series: str = None, tags: list[str] = None) -> bool:
""" """