file_manager: use "run_with_response" to extract metadata
Enable logging to stderr so that it is not necessary to extract logged data from the command. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
9e41d9d84b
commit
7ff54d8f2f
|
@ -619,7 +619,6 @@ class MetadataStorage:
|
||||||
self.metadata = {}
|
self.metadata = {}
|
||||||
self.pending_requests = {}
|
self.pending_requests = {}
|
||||||
self.events = {}
|
self.events = {}
|
||||||
self.script_response = None
|
|
||||||
self.busy = False
|
self.busy = False
|
||||||
self.gc_path = os.path.expanduser("~")
|
self.gc_path = os.path.expanduser("~")
|
||||||
self.prune_cb = PeriodicCallback(
|
self.prune_cb = PeriodicCallback(
|
||||||
|
@ -644,19 +643,6 @@ class MetadataStorage:
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
return dict(self.metadata[key])
|
return dict(self.metadata[key])
|
||||||
|
|
||||||
def _handle_script_response(self, result):
|
|
||||||
try:
|
|
||||||
proc_resp = json.loads(result.strip())
|
|
||||||
except Exception:
|
|
||||||
logging.exception("file_manager: unable to load metadata")
|
|
||||||
logging.debug(result)
|
|
||||||
return
|
|
||||||
proc_log = proc_resp.get('log', [])
|
|
||||||
for log_msg in proc_log:
|
|
||||||
logging.info(log_msg)
|
|
||||||
if 'file' in proc_resp:
|
|
||||||
self.script_response = proc_resp
|
|
||||||
|
|
||||||
def prune_metadata(self):
|
def prune_metadata(self):
|
||||||
for fname in list(self.metadata.keys()):
|
for fname in list(self.metadata.keys()):
|
||||||
fpath = os.path.join(self.gc_path, fname)
|
fpath = os.path.join(self.gc_path, fname)
|
||||||
|
@ -716,14 +702,17 @@ class MetadataStorage:
|
||||||
cmd = " ".join([sys.executable, METADATA_SCRIPT, "-p",
|
cmd = " ".join([sys.executable, METADATA_SCRIPT, "-p",
|
||||||
self.gc_path, "-f", f"\"{filename}\""])
|
self.gc_path, "-f", f"\"{filename}\""])
|
||||||
shell_command = self.server.lookup_plugin('shell_command')
|
shell_command = self.server.lookup_plugin('shell_command')
|
||||||
scmd = shell_command.build_shell_command(
|
scmd = shell_command.build_shell_command(cmd, log_stderr=True)
|
||||||
cmd, self._handle_script_response)
|
result = await scmd.run_with_response(timeout=10.)
|
||||||
self.script_response = None
|
if result is None:
|
||||||
await scmd.run(timeout=10.)
|
raise self.server.error(f"Metadata extraction error")
|
||||||
if self.script_response is None:
|
try:
|
||||||
raise self.server.error("Unable to extract metadata")
|
decoded_resp = json.loads(result.strip())
|
||||||
path = self.script_response['file']
|
except Exception:
|
||||||
metadata = self.script_response['metadata']
|
logging.debug(f"Invalid metadata response:\n{result}")
|
||||||
|
raise
|
||||||
|
path = decoded_resp['file']
|
||||||
|
metadata = decoded_resp['metadata']
|
||||||
if not metadata:
|
if not metadata:
|
||||||
# This indicates an error, do not add metadata for this
|
# This indicates an error, do not add metadata for this
|
||||||
raise self.server.error("Unable to extract metadata")
|
raise self.server.error("Unable to extract metadata")
|
||||||
|
|
Loading…
Reference in New Issue