Debian Codegraph @

lib/dbtexmf/xslt/xslt.py

raw ◀ ▶
2 Debian patches touch this file
1 #
2 # Very simple plugin loader for Xslt classes
3 #
4 import os
•5 import importlib.machinery
6 import importlib.util
•7 import glob
8 import sys
9
10 def load(modname):
•11 spec = importlib.machinery.PathFinder.find_spec(modname, [""])
12 if not spec:
13 spec = importlib.machinery.PathFinder.find_spec(modname,
14 [os.path.dirname(__file__)])
15 if not spec:
16 raise ValueError("Xslt '%s' not found" % modname)
17
18 mod = importlib.util.module_from_spec(spec)
19 spec.loader.exec_module(mod)
20 sys.modules[modname] = mod
21 o = mod.Xslt()
22 return o
23
24 def get_deplists():
25 """
26 Return the dependency list to check for each XSLT plugin. The returned
27 list also gives the available plugins.
28 """
29 ps = glob.glob(os.path.join(os.path.dirname(__file__), "*.py"))
30 selfmod = os.path.splitext(os.path.basename(__file__))[0]
31 ps = [os.path.splitext(os.path.basename(p))[0] for p in ps]
32 if selfmod in ps:
33 ps.remove(selfmod)
34 if "__init__" in ps:
35 ps.remove("__init__")
36
37 deplists = []
38 for p in ps:
39 try:
40 x = load(p)
41 deplists.append((p, x.get_deplist()))
42 except:
43 # The module cannot be loaded, but don't panic yet
44 pass
45
46 return deplists