1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 """ plugin handling routines """
22
23
24
25 import sys
26 import os.path
27 import glob
28
29 try:
30 import resources
31 except:
32 resources = None
33
35 """find parent/dir/*.py files to be used for plugins
36
37 @rtype: [str,...]
38 @note:
39 1. __init__.py should exist
40 2. files starting with underscore are ignored
41 3. if fnmatch is defined (base name), it matches a single file
42 """
43 good = False
44 res = []
45 pattern = parent + "/" + dir + "/*.py"
46 for x in glob.glob(pattern) if not parent.startswith('resource:') else resources.resource_list[dir]:
47 basex = os.path.basename(x)
48 if basex == "__init__.py": good = True
49 elif basex.startswith('_'):
50
51
52 continue
53 else:
54 base = os.path.splitext(basex)[0]
55 if base and ((not fmatch) or (fmatch == base)): res.append((base,parent))
56 return res if good else []
57
59 """return a sequence of available plugins, using L{available_files()} and L{get_plugin_paths()}
60
61 @rtype: [str,...]
62 """
63 plugin_paths = get_plugin_paths()
64 result = []
65 for path in plugin_paths:
66 result += available_files(path, cat)
67 return result
68
69
70
71
72
73
74
76 """return the plugin search paths
77
78 @rtype: [str,str,..]
79 """
80 result = [ os.path.expanduser("~/.callirhoe"), sys.path[0] if sys.path[0] else "." ]
81 if resources:
82 result.append("resource:")
83 return result
84