-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin_manager.py
executable file
·51 lines (32 loc) · 1.32 KB
/
plugin_manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import logging
input_plugins = []
output_plugins = []
import nitrile.latex.latex
import TextReader
#import LatexReader
#import ParseLatex
import pango_cairo_pdf
import pango_cairo_raster
import magic
def __get_plugin(plugin_list,string,filename):
extension = filename.split('.')[-1].lower()
for plugin in plugin_list:
plugin_exts = plugin.GetExtensions()
logging.debug("plugin {} has extensions: {}".format(plugin.__name__,repr(plugin_exts)))
if extension in plugin_exts:
logging.info("Based on %s file %r extension %r, selected %s plugin %r",
string,filename,extension,string,plugin.__name__)
return plugin
print plugin_list
raise Exception("could not find %s with extension: %r"
%(string,extension))
def get_output_plugin(filename):
return __get_plugin(output_plugins,'output',filename)
def get_input_plugin(filename):
p = __get_plugin(input_plugins,'input',filename)
mime = magic.from_file(filename,mime=True)
if mime in p.GetMimeTypes():
logging.info("%s file %s has mimetype %r, which input plugin %r supports","input",filename, mime,p.__name__)
else:
logging.warn("%s file %s has mimetype %r, which input plugin %r does not support!","input",filename, mime,p.__name__)
return p