Split command line `--type arg into --type-modify for modify styles and --type-read for read styles

This commit is contained in:
Mizaki 2024-04-27 22:02:34 +01:00
parent 96bbbe51e7
commit 0bbdaa96cf
5 changed files with 50 additions and 40 deletions

View File

@ -134,7 +134,7 @@ class CLI:
def actual_metadata_save(self, ca: ComicArchive, md: GenericMetadata) -> bool:
if not self.config.Runtime_Options__dryrun:
for style in self.config.Runtime_Options__type:
for style in self.config.Runtime_Options__type_modify:
# write out the new data
if not ca.write_metadata(md, style):
logger.error("The tag save seemed to fail for style: %s!", md_styles[style].name())
@ -249,7 +249,7 @@ class CLI:
md.overlay(f_md)
for style in reversed(self.config.Runtime_Options__type):
for style in self.config.Runtime_Options__type_read:
if ca.has_metadata(style):
try:
t_md = ca.read_metadata(style)
@ -263,7 +263,7 @@ class CLI:
return md
def print(self, ca: ComicArchive) -> Result:
if not self.config.Runtime_Options__type:
if not self.config.Runtime_Options__type_read:
page_count = ca.get_number_of_pages()
brief = ""
@ -289,7 +289,7 @@ class CLI:
md = None
for style, style_obj in md_styles.items():
if not self.config.Runtime_Options__type or style in self.config.Runtime_Options__type:
if not self.config.Runtime_Options__type_read or style in self.config.Runtime_Options__type_read:
if ca.has_metadata(style):
self.output(f"--------- {style_obj.name()} tags ---------")
try:
@ -321,7 +321,7 @@ class CLI:
def delete(self, ca: ComicArchive) -> Result:
res = Result(Action.delete, Status.success, ca.path)
for style in self.config.Runtime_Options__type:
for style in self.config.Runtime_Options__type_modify:
status = self.delete_style(ca, style)
if status == Status.success:
res.tags_deleted.append(style)
@ -366,7 +366,9 @@ class CLI:
except Exception as e:
logger.error("Failed to load metadata for %s: %s", ca.path, e)
return res
for style in self.config.Runtime_Options__type:
for style in self.config.Runtime_Options__type_modify:
if style == src_style_name:
continue
status = self.copy_style(ca, res.md, style)
if status == Status.success:
res.tags_written.append(style)
@ -376,7 +378,7 @@ class CLI:
def save(self, ca: ComicArchive, match_results: OnlineMatchResults) -> tuple[Result, OnlineMatchResults]:
if not self.config.Runtime_Options__overwrite:
for style in self.config.Runtime_Options__type:
for style in self.config.Runtime_Options__type_modify:
if ca.has_metadata(style):
self.output(f"{ca.path}: Already has {md_styles[style].name()} tags. Not overwriting.")
return (
@ -384,7 +386,7 @@ class CLI:
Action.save,
original_path=ca.path,
status=Status.existing_tags,
tags_written=self.config.Runtime_Options__type,
tags_written=self.config.Runtime_Options__type_modify,
),
match_results,
)
@ -412,7 +414,7 @@ class CLI:
Action.save,
original_path=ca.path,
status=Status.fetch_data_failure,
tags_written=self.config.Runtime_Options__type,
tags_written=self.config.Runtime_Options__type_modify,
)
match_results.fetch_data_failures.append(res)
return res, match_results
@ -424,7 +426,7 @@ class CLI:
status=Status.match_failure,
original_path=ca.path,
match_status=MatchStatus.no_match,
tags_written=self.config.Runtime_Options__type,
tags_written=self.config.Runtime_Options__type_modify,
)
match_results.no_matches.append(res)
return res, match_results
@ -437,7 +439,7 @@ class CLI:
status=Status.match_failure,
original_path=ca.path,
match_status=MatchStatus.no_match,
tags_written=self.config.Runtime_Options__type,
tags_written=self.config.Runtime_Options__type_modify,
)
match_results.no_matches.append(res)
return res, match_results
@ -480,7 +482,7 @@ class CLI:
original_path=ca.path,
online_results=matches,
match_status=MatchStatus.low_confidence_match,
tags_written=self.config.Runtime_Options__type,
tags_written=self.config.Runtime_Options__type_modify,
)
match_results.low_confidence_matches.append(res)
return res, match_results
@ -492,7 +494,7 @@ class CLI:
original_path=ca.path,
online_results=matches,
match_status=MatchStatus.multiple_match,
tags_written=self.config.Runtime_Options__type,
tags_written=self.config.Runtime_Options__type_modify,
)
match_results.multiple_matches.append(res)
return res, match_results
@ -504,7 +506,7 @@ class CLI:
original_path=ca.path,
online_results=matches,
match_status=MatchStatus.low_confidence_match,
tags_written=self.config.Runtime_Options__type,
tags_written=self.config.Runtime_Options__type_modify,
)
match_results.low_confidence_matches.append(res)
return res, match_results
@ -516,7 +518,7 @@ class CLI:
original_path=ca.path,
online_results=matches,
match_status=MatchStatus.no_match,
tags_written=self.config.Runtime_Options__type,
tags_written=self.config.Runtime_Options__type_modify,
)
match_results.no_matches.append(res)
return res, match_results
@ -532,7 +534,7 @@ class CLI:
original_path=ca.path,
online_results=matches,
match_status=MatchStatus.good_match,
tags_written=self.config.Runtime_Options__type,
tags_written=self.config.Runtime_Options__type_modify,
)
match_results.fetch_data_failures.append(res)
return res, match_results
@ -544,7 +546,7 @@ class CLI:
online_results=matches,
match_status=MatchStatus.good_match,
md=prepare_metadata(md, ct_md, self.config),
tags_written=self.config.Runtime_Options__type,
tags_written=self.config.Runtime_Options__type_modify,
)
assert res.md
# ok, done building our metadata. time to save

View File

@ -160,14 +160,20 @@ def register_runtime(parser: settngs.Manager) -> None:
parser.add_setting(
"--json", "-j", action="store_true", help="Output json on stdout. Ignored in interactive mode.", file=False
)
# TODO Break read and write apart?
parser.add_setting(
"-t",
"--type",
"--type-modify",
metavar=f"{{{','.join(metadata_styles).upper()}}}",
default=[],
type=metadata_type,
help="""Specify TYPE as either CR, CBL or COMET\n(as either ComicRack, ComicBookLover,\nor CoMet style tags, respectively).\nUse commas for multiple types.\nFor searching the metadata will be overlayed in reverse order (hierarchical):\ne.g. '-t cbl,cr' first CR tags are read, then CBL overlayed over the top.\n\n""",
help="""Specify the type of tags to write.\nUse commas for multiple types.\nSee --list-plugins for the available types.\n\n""",
file=False,
)
parser.add_setting(
"--type-read",
metavar=f"{{{','.join(metadata_styles).upper()}}}",
default=[],
type=metadata_type,
help="""Specify the type of tags to read.\nUse commas for multiple types.\nSee --list-plugins for the available types.\nThe tag use will be 'overlayed' in order:\ne.g. '-t cbl,cr' with no CBL tags, CR will be used if they exist and CR will overwrite any shared CBL tags.\n\n""",
file=False,
)
parser.add_setting(
@ -190,7 +196,7 @@ def register_commands(parser: settngs.Manager) -> None:
dest="command",
action="store_const",
const=Action.print,
help="""Print out tag info from file. Specify type\n(via -t) to get only info of that tag type.\n\n""",
help="""Print out tag info from file. Specify type\n(via --type-read) to get only info of that tag type.\n\n""",
file=False,
)
parser.add_setting(
@ -199,7 +205,7 @@ def register_commands(parser: settngs.Manager) -> None:
dest="command",
action="store_const",
const=Action.delete,
help="Deletes the tag block of specified type (via -t).\n",
help="Deletes the tag block of specified type (via --type-modify).\n",
file=False,
)
parser.add_setting(
@ -207,7 +213,7 @@ def register_commands(parser: settngs.Manager) -> None:
"--copy",
type=metadata_type_single,
metavar=f"{{{','.join(metadata_styles).upper()}}}",
help="Copy the specified source tag block to\ndestination style specified via -t\n(potentially lossy operation).\n\n",
help="Copy the specified source tag block to\ndestination style specified via --type-modify\n(potentially lossy operation).\n\n",
file=False,
)
parser.add_setting(
@ -216,7 +222,7 @@ def register_commands(parser: settngs.Manager) -> None:
dest="command",
action="store_const",
const=Action.save,
help="Save out tags as specified type (via -t).\nMust specify also at least -o, -f, or -m.\n\n",
help="Save out tags as specified type (via --type-modify).\nMust specify also at least -o, -f, or -m.\n\n",
file=False,
)
parser.add_setting(
@ -291,16 +297,16 @@ def validate_commandline_settings(config: settngs.Config[ct_ns], parser: settngs
):
parser.exit(message="Command requires at least one filename!\n", status=1)
if config[0].Commands__command == Action.delete and not config[0].Runtime_Options__type:
parser.exit(message="Please specify the type to delete with -t\n", status=1)
if config[0].Commands__command == Action.delete and not config[0].Runtime_Options__type_modify:
parser.exit(message="Please specify the type to delete with --type-modify\n", status=1)
if config[0].Commands__command == Action.save and not config[0].Runtime_Options__type:
parser.exit(message="Please specify the type to save with -t\n", status=1)
if config[0].Commands__command == Action.save and not config[0].Runtime_Options__type_modify:
parser.exit(message="Please specify the type to save with --type-modify\n", status=1)
if config[0].Commands__copy:
config[0].Commands__command = Action.copy
if not config[0].Runtime_Options__type:
parser.exit(message="Please specify the type to copy to with -t\n", status=1)
if not config[0].Runtime_Options__type_modify:
parser.exit(message="Please specify the type to copy to with --type-modify\n", status=1)
if config[0].Runtime_Options__recursive:
config[0].Runtime_Options__files = utils.get_recursive_filelist(config[0].Runtime_Options__files)

View File

@ -34,7 +34,8 @@ class SettngsNS(settngs.TypedNS):
Runtime_Options__glob: bool
Runtime_Options__quiet: bool
Runtime_Options__json: bool
Runtime_Options__type: list[str]
Runtime_Options__type_modify: list[str]
Runtime_Options__type_read: list[str]
Runtime_Options__overwrite: bool
Runtime_Options__no_gui: bool
Runtime_Options__files: list[str]

View File

@ -211,11 +211,11 @@ class TaggerWindow(QtWidgets.QMainWindow):
self.setWindowIcon(QtGui.QIcon(str(graphics_path / "app.png")))
if config[0].Runtime_Options__type and isinstance(config[0].Runtime_Options__type[0], str):
# respect the command line option tag type
config[0].internal__save_data_style = config[0].Runtime_Options__type
# TODO Separate options for read and write
config[0].internal__load_data_style = config[0].Runtime_Options__type
# respect the command line option tag type
if config[0].Runtime_Options__type_modify:
config[0].internal__save_data_style = config[0].Runtime_Options__type_modify
if config[0].Runtime_Options__type_read:
config[0].internal__load_data_style = config[0].Runtime_Options__type_read
for style in config[0].internal__save_data_style:
if style not in metadata_styles:

View File

@ -39,8 +39,9 @@ def test_save(
config[0].Runtime_Options__online = True
# Use the temporary comic we created
config[0].Runtime_Options__files = [tmp_comic.path]
# Save ComicRack tags
config[0].Runtime_Options__type = ["cr"]
# Read and save ComicRack tags
config[0].Runtime_Options__type_read = ["cr"]
config[0].Runtime_Options__type_modify = ["cr"]
# Search using the correct series since we just put the wrong series name in the CBZ
config[0].Runtime_Options__metadata = comicapi.genericmetadata.GenericMetadata(series=md_saved.series)
# Run ComicTagger
@ -89,7 +90,7 @@ def test_delete(
# Use the temporary comic we created
config[0].Runtime_Options__files = [tmp_comic.path]
# Delete ComicRack tags
config[0].Runtime_Options__type = ["cr"]
config[0].Runtime_Options__type_modify = ["cr"]
# Run ComicTagger
CLI(config[0], talkers).run()