rclconfig.py, rclexecm.py: implement part of mimetype identification for rclexecm test mode
This commit is contained in:
parent
8339559536
commit
af42fe8f5e
@ -386,6 +386,7 @@ def main(proto, extract):
|
|||||||
|
|
||||||
if len(args) != 1:
|
if len(args) != 1:
|
||||||
usage()
|
usage()
|
||||||
|
path = args[0]
|
||||||
|
|
||||||
def mimetype_with_file(f):
|
def mimetype_with_file(f):
|
||||||
cmd = 'file -i "' + f + '"'
|
cmd = 'file -i "' + f + '"'
|
||||||
@ -403,10 +404,15 @@ def main(proto, extract):
|
|||||||
if not actAsSingle:
|
if not actAsSingle:
|
||||||
proto.breakwrite(out, makebytes(s+'\n'))
|
proto.breakwrite(out, makebytes(s+'\n'))
|
||||||
|
|
||||||
params = {'filename:': makebytes(args[0])}
|
params = {'filename:': makebytes(path)}
|
||||||
# Some filters (e.g. rclaudio) need/get a MIME type from the indexer
|
|
||||||
mimetype = mimetype_with_file(args[0])
|
# Some filters (e.g. rclaudio) need/get a MIME type from the indexer.
|
||||||
params['mimetype:'] = mimetype
|
# We make a half-assed attempt to emulate:
|
||||||
|
mimetype = my_config.mimeType(path)
|
||||||
|
if not mimetype and not _mswindows:
|
||||||
|
mimetype = mimetype_with_file(path)
|
||||||
|
if mimetype:
|
||||||
|
params['mimetype:'] = mimetype
|
||||||
|
|
||||||
if not extract.openfile(params):
|
if not extract.openfile(params):
|
||||||
print("Open error", file=sys.stderr)
|
print("Open error", file=sys.stderr)
|
||||||
|
|||||||
@ -28,6 +28,7 @@ class RclDynConf:
|
|||||||
class RclConfig:
|
class RclConfig:
|
||||||
def __init__(self, argcnf = None):
|
def __init__(self, argcnf = None):
|
||||||
self.config = None
|
self.config = None
|
||||||
|
self.mimemap = None
|
||||||
platsys = platform.system()
|
platsys = platform.system()
|
||||||
# Find configuration directory
|
# Find configuration directory
|
||||||
if argcnf is not None:
|
if argcnf is not None:
|
||||||
@ -89,6 +90,28 @@ class RclConfig:
|
|||||||
self.config = conftree.ConfStack("recoll.conf", self.cdirs, "tree")
|
self.config = conftree.ConfStack("recoll.conf", self.cdirs, "tree")
|
||||||
return self.config.get(nm, self.keydir)
|
return self.config.get(nm, self.keydir)
|
||||||
|
|
||||||
|
# This is a simplified version of the c++ code, intended mostly for the
|
||||||
|
# test mode of rclexecm.py. We don't attempt to check the data, so this
|
||||||
|
# will not work on extension-less paths (e.g. mbox/mail/etc.)
|
||||||
|
def mimeType(self, path):
|
||||||
|
if not self.mimemap:
|
||||||
|
self.mimemap = conftree.ConfStack("mimemap", self.cdirs, "tree")
|
||||||
|
if os.path.exists(path):
|
||||||
|
if os.path.isdir(path):
|
||||||
|
return "inode/directory"
|
||||||
|
if os.path.islink(path):
|
||||||
|
return "inode/symlink"
|
||||||
|
if not os.path.isfile(path):
|
||||||
|
return "inode/x-fsspecial"
|
||||||
|
try:
|
||||||
|
size = os.path.getsize(path)
|
||||||
|
if size == 0:
|
||||||
|
return "inode/x-empty"
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
ext = os.path.splitext(path)[1]
|
||||||
|
return self.mimemap.get(ext, self.keydir)
|
||||||
|
|
||||||
class RclExtraDbs:
|
class RclExtraDbs:
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user