Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
RhetTbull committed Jul 8, 2021
1 parent f87c866 commit 5502716
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 35 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ If you only care about the command line tool, I recommend installing with [pipx]
The command line tool can also be run via `python -m osxmetadata`. Running it with no arguments or with --help option will print a help message:

```
Usage: python -m osxmetadata [OPTIONS] FILE
Usage: osxmetadata [OPTIONS] FILE
Read/write metadata from file(s).
Expand Down Expand Up @@ -141,6 +141,13 @@ downloadeddate kMDItemDownloadedDate,
zone), or 2020-04-14T12:00:00-07:00 (ISO 8601 with timezone
offset). Times without timezone offset are assumed to be in
local timezone.
duedate kMDItemDueDate, com.apple.metadata:kMDItemDueDate; The date
the item is due. A date in ISO 8601 format, time and
timezone offset are optional: e.g. 2020-04-14T12:00:00 (ISO
8601 w/o timezone), 2020-04-14 (ISO 8601 w/o time and time
zone), or 2020-04-14T12:00:00-07:00 (ISO 8601 with timezone
offset). Times without timezone offset are assumed to be in
local timezone.
findercomment kMDItemFinderComment,
com.apple.metadata:kMDItemFinderComment; Finder comments for
this file. A string.
Expand All @@ -159,6 +166,9 @@ keywords kMDItemKeywords, com.apple.metadata:kMDItemKeywords;
(_kMDItemUserTags) which are keywords/tags shown in the
Finder and searchable in Spotlight using "tag:tag_name". A
list of strings.
rating kMDItemStarRating, com.apple.metadata:kMDItemStarRating;
User rating of this item. For example, the stars rating of
an iTunes track. An integer.
tags _kMDItemUserTags, com.apple.metadata:_kMDItemUserTags;
Finder tags; searchable in Spotlight using "tag:tag_name".
If you want tags/keywords visible in the Finder, use this
Expand Down
32 changes: 1 addition & 31 deletions osxmetadata/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


import datetime
import logging
from collections import namedtuple # pylint: disable=syntax-error

from .classes import _AttributeFinderInfo, _AttributeList, _AttributeTagsList
Expand Down Expand Up @@ -268,30 +267,9 @@
False,
False,
"User rating of this item. "
+ "For example, the stars rating of an iTunes track. An int.",
+ "For example, the stars rating of an iTunes track. An integer.",
None,
)
# "test": Attribute(
# "test",
# "com.osxmetadata.test:DontTryThisAtHomeKids",
# "com.osxmetadata.test:DontTryThisAtHomeKids",
# datetime.datetime,
# False,
# False,
# datetime.datetime,
# "Don't try this at home",
# ),
# "test_float": Attribute(
# "test_float",
# "com.osxmetadata.test:DontTryThisAtHomeKids",
# float,
# False,
# False,
# float,
# ),
# "test_str": Attribute(
# "test_str", "com.osxmetadata.test:String", str, False, False, str
# ),
}

# used for formatting output of --list
Expand Down Expand Up @@ -334,14 +312,6 @@ def validate_attribute_value(attribute, value):
except TypeError:
value = [value]

# # check for None and convert to list if needed
# if not isinstance(value, list):
# if value is None:
# return None
# value = [value]
# elif None in value:
# return None

if not attribute.list and len(value) > 1:
# got a list but didn't expect one
raise ValueError(
Expand Down
7 changes: 4 additions & 3 deletions osxmetadata/osxmetadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import os.path
import pathlib
import plistlib
import sys
import base64

# plistlib creates constants at runtime which causes pylint to complain
Expand Down Expand Up @@ -42,6 +41,7 @@
kMDItemUserTags,
kMDItemWhereFroms,
kMDItemDueDate,
kMDItemStarRating,
)
from .datetime_utils import (
datetime_naive_to_utc,
Expand Down Expand Up @@ -120,6 +120,7 @@ class OSXMetaData:
"wherefroms",
"finderinfo",
"duedate",
"rating",
]

def __init__(self, fname, tz_aware=False):
Expand Down Expand Up @@ -222,7 +223,7 @@ def asdict(self, all_=False, encode=True):

def to_json(self, all_=False):
"""Returns a string in JSON format for all attributes in this file
Args:
all_: bool; if True, also restores attributes not known to osxmetadata (generated with asdict(all_=True, encode=True) )
"""
Expand Down Expand Up @@ -553,7 +554,7 @@ def clear_finder_comment(self, path):
pass

def __getattr__(self, name):
"""if attribute name is in ATTRIBUTE dict, return the value """
"""if attribute name is in ATTRIBUTE dict, return the value"""
if name in ATTRIBUTES:
return self.get_attribute(name)
raise AttributeError(f"{name} is not an attribute")
Expand Down

0 comments on commit 5502716

Please sign in to comment.