Skip to content

Commit

Permalink
Working on #106
Browse files Browse the repository at this point in the history
  • Loading branch information
RhetTbull committed Jun 28, 2024
1 parent cffb5a4 commit 97b1daf
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion osxmetadata/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ def md_remove_metadata_with_error(
return f"remove is not a valid operation for single-value attribute {attr}"

if attr in _TAGS_NAMES:
val = md_tag_value_from_file(md, val)
val = tag_factory(val)
elif attr in MDITEM_ATTRIBUTE_DATA or attr in MDITEM_ATTRIBUTE_SHORT_NAMES:
val = str_to_mditem_type(attr, val)
Expand All @@ -415,6 +416,24 @@ def md_remove_metadata_with_error(
raise e


def md_tag_value_from_file(md: OSXMetaData, value: str) -> str:
"""Given a tag value, return the tag + color if tag value contains color.
If not, check if file has the same tag and if so, return the tag + color from the file
Returns the new tag value
"""
values = value.split(",")
if len(values) > 2:
raise ValueError(f"More than one value found after comma: {value}")
if len(values) == 2:
return value
if file_tags := md.get(_kMDItemUserTags):
for tag in file_tags:
if tag.name.lower() == value.lower():
return f"{value},{tag.color}"
return value


def md_mirror_metadata_with_error(
md: OSXMetaData, attributes: t.Tuple[t.Tuple[str, str]], verbose: bool
) -> t.Optional[str]:
Expand Down Expand Up @@ -677,7 +696,7 @@ def get_help(self, ctx):
"findercolor; Finder color tag value. "
+ "The value can be either a number or the name of the color as follows: "
+ f"{', '.join([f'{colorid}: {color}' for color, colorid in _COLORNAMES_LOWER.items() if colorid != FINDER_COLOR_NONE])}; "
+"integer or string.",
+ "integer or string.",
)
)
attr_tuples = sorted(attr_tuples)
Expand Down

0 comments on commit 97b1daf

Please sign in to comment.