implement 'keywords-eval' option (#5621)
to allow evaluating 'keywords' values as format strings
This commit is contained in:
@@ -692,6 +692,17 @@ Description
|
|||||||
Additional name-value pairs to be added to each metadata dictionary.
|
Additional name-value pairs to be added to each metadata dictionary.
|
||||||
|
|
||||||
|
|
||||||
|
extractor.*.keywords-eval
|
||||||
|
-------------------------
|
||||||
|
Type
|
||||||
|
``bool``
|
||||||
|
Default
|
||||||
|
``false``
|
||||||
|
Description
|
||||||
|
Evaluate each `keywords <extractor.*.keywords_>`__ ``string`` value
|
||||||
|
as a `format string`_.
|
||||||
|
|
||||||
|
|
||||||
extractor.*.keywords-default
|
extractor.*.keywords-default
|
||||||
----------------------------
|
----------------------------
|
||||||
Type
|
Type
|
||||||
|
|||||||
@@ -42,8 +42,9 @@ class Job():
|
|||||||
|
|
||||||
self.extractor = extr
|
self.extractor = extr
|
||||||
self.pathfmt = None
|
self.pathfmt = None
|
||||||
self.kwdict = {}
|
|
||||||
self.status = 0
|
self.status = 0
|
||||||
|
self.kwdict = {}
|
||||||
|
self.kwdict_eval = False
|
||||||
|
|
||||||
cfgpath = []
|
cfgpath = []
|
||||||
if parent:
|
if parent:
|
||||||
@@ -120,7 +121,16 @@ class Job():
|
|||||||
# user-supplied metadata
|
# user-supplied metadata
|
||||||
kwdict = extr.config("keywords")
|
kwdict = extr.config("keywords")
|
||||||
if kwdict:
|
if kwdict:
|
||||||
self.kwdict.update(kwdict)
|
if extr.config("keywords-eval"):
|
||||||
|
self.kwdict_eval = []
|
||||||
|
for key, value in kwdict.items():
|
||||||
|
if isinstance(value, str):
|
||||||
|
fmt = formatter.parse(value, None, util.identity)
|
||||||
|
self.kwdict_eval.append((key, fmt.format_map))
|
||||||
|
else:
|
||||||
|
self.kwdict[key] = value
|
||||||
|
else:
|
||||||
|
self.kwdict.update(kwdict)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Execute or run the job"""
|
"""Execute or run the job"""
|
||||||
@@ -215,6 +225,9 @@ class Job():
|
|||||||
kwdict.pop(self.metadata_http, None)
|
kwdict.pop(self.metadata_http, None)
|
||||||
if self.kwdict:
|
if self.kwdict:
|
||||||
kwdict.update(self.kwdict)
|
kwdict.update(self.kwdict)
|
||||||
|
if self.kwdict_eval:
|
||||||
|
for key, valuegen in self.kwdict_eval:
|
||||||
|
kwdict[key] = valuegen(kwdict)
|
||||||
|
|
||||||
def _init(self):
|
def _init(self):
|
||||||
self.extractor.initialize()
|
self.extractor.initialize()
|
||||||
|
|||||||
Reference in New Issue
Block a user