Major cleanup and fixage for new metadata stuff and heckformat
- Clean up a ton of documentation.
- Make the modules import nicely.
- Add a cool logo to the command line tool
- Make the command-line tool use tqdm
- Make the command line tool load the metadata before processing the
files in a separate loop.
- Fix error handling in the command-line tool processing loops so they
work correctly (and jinja errors are more useful)
- Make command-line tool exit non-zero if there were errors.
- Fix load metadata to handle formats and errors better (and return {}
if it fails)
This commit is contained in:
@ -108,26 +108,28 @@ class MetaTree:
|
||||
|
||||
def _load_metadata(self, cachekey: str) -> Dict:
|
||||
meta = {}
|
||||
with open(cachekey, "r") as inf:
|
||||
if cachekey.endswith(".heck"):
|
||||
# raise NotImplemented("We don't yet support HECKformat")
|
||||
with open(cachekey) as cachefile:
|
||||
h = heckformat.parse.load(cachefile)
|
||||
meta = h.flatten_replace()
|
||||
else:
|
||||
try:
|
||||
# try json load
|
||||
meta = jstyleson.load(inf)
|
||||
except jstyleson.JSONDecodeError as exc:
|
||||
# try yaml load
|
||||
try:
|
||||
with open(cachekey, "r") as inf:
|
||||
if cachekey.endswith(".heck"):
|
||||
with open(cachekey) as cachefile:
|
||||
h = heckformat.parse.load(cachefile)
|
||||
meta = h.flatten_replace()
|
||||
else:
|
||||
try:
|
||||
meta = yaml.load(inf)
|
||||
except yaml.parser.ParserError as exc2:
|
||||
# else either the yaml or json has an error
|
||||
me = MetaLoadError()
|
||||
exc2.__context__ = exc
|
||||
raise me from exc2
|
||||
return meta
|
||||
# try json load
|
||||
meta = jstyleson.load(inf)
|
||||
except jstyleson.JSONDecodeError as exc:
|
||||
# try yaml load
|
||||
try:
|
||||
meta = yaml.load(inf)
|
||||
except yaml.parser.ParserError as exc2:
|
||||
# else either the yaml or json has an error
|
||||
me = MetaLoadError()
|
||||
exc2.__context__ = exc
|
||||
except BaseException as inst:
|
||||
logger.error(f"Can't load any metadata for key {cachekey}: {inst}")
|
||||
|
||||
return meta
|
||||
|
||||
def get_metadata(self, rel_path: str) -> Dict:
|
||||
"""Retrieve the metadata for a given path
|
||||
|
||||
Reference in New Issue
Block a user