Debian Codegraph @

lib/dbtexmf/xslt/xslt.py

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