commit ca78e2ef2ab956963ca03cd05b8e7624dd667848
parent 76fb890920353a77b875099749192b228a9811b4
Author: lash <dev@holbrook.no>
Date: Mon, 7 Sep 2026 06:49:24 -0600
Revert file stem search
Diffstat:
2 files changed, 15 insertions(+), 22 deletions(-)
diff --git a/adesse/util/xmp.py b/adesse/util/xmp.py
@@ -25,16 +25,15 @@ def _parse_xmp(xmp_file, resource_file, search_dir=None):
for d in search_dir:
if not cont:
break
- for p in resource_file:
- fp = os.path.join(d, p)
- logg.debug('trying file {}'.format(fp))
- try:
- f = open(fp, 'rb')
- cont = False
- logg.info('match on file {}'.format(fp))
- break
- except FileNotFoundError:
- pass
+ fp = os.path.join(d, resource_file)
+ logg.debug('trying file {}'.format(fp))
+ try:
+ f = open(fp, 'rb')
+ cont = False
+ logg.info('match on file {}'.format(fp))
+ break
+ except FileNotFoundError:
+ pass
if f == None:
raise FileNotFoundError()
@@ -49,6 +48,7 @@ def _parse_xmp(xmp_file, resource_file, search_dir=None):
for v in r.findall('rdf:Description', namespaces={'rdf': str(RDF)}):
v.set('{{{}}}about'.format(str(RDF)), uu)
+ logg.debug('fp {}'.format(fp))
mime = mimetypes.guess_type(fp)
s = lxml.etree.tostring(r)
@@ -116,7 +116,7 @@ def get_tags(sbj, o):
#return _get_bag(sbj, PDF.Keywords, o)
v = o.value(sbj, PDF.Keywords)
r = []
- for s in v.split(','):
+ for s in v.replace("\n", ",").replace(" ", "").split(','):
r.append(s.strip())
return r
@@ -124,20 +124,14 @@ def get_tags(sbj, o):
def attachment_from_xmp(xml_file, resource_file=None, search_dir=None, uuidns=None):
if search_dir == None:
search_dir = ['.']
- if resource_file == None:
- v = os.path.splitext(xml_file)[0]
- resource_file = []
- resource_file.append(v + '.xmp')
- resource_file.append(v + '.xml')
- logg.debug('default to xmp files {}'.format(resource_file))
- elif isinstance(resource_file, str):
- resource_file = [resource_file]
+
r = _parse_xmp(xml_file, resource_file=resource_file, search_dir=search_dir)
- o = Graph()
z = r[0]
sbj = URIRef(z)
mime = r[1]
resource_file = r[3]
+
+ o = Graph()
o.parse(r[2], format='xml')
(default_lang, langs) = scan_lang(sbj, o)
title = parse_title(sbj, o, lang=default_lang)
diff --git a/test/test_xmp.py b/test/test_xmp.py
@@ -24,8 +24,7 @@ class TestXmpLoad(unittest.TestCase):
def test_parse(self):
fp = os.path.join(thisdir, 'import.xmp')
- #r = xmp.attachment_from_xmp(fp, 'import.pdf', search_dir=[thisdir], uuidns=self.uubase)
- r = xmp.attachment_from_xmp(fp, search_dir=[thisdir], uuidns=self.uubase)
+ r = xmp.attachment_from_xmp(fp, resource_file='import.pdf', search_dir=[thisdir], uuidns=self.uubase)
z = Serializer()
r.apply(z)
print(z)