1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import os
17 from logging import getLogger
18
19 log = getLogger(__name__)
23 """
24 Agent plugins loader.
25 """
26
27 ROOT = '/var/lib/pulp/agent'
28 PLUGINS = 'plugins'
29
30 @classmethod
33
35 path = self.abspath()
36 if os.path.exists(path):
37 return
38 os.makedirs(path)
39 pkg = os.path.join(path, '__init__.py')
40 f = open(pkg, 'w')
41 f.close()
42
44 """
45 Load the plugins.
46 """
47 sys.path.append(self.ROOT)
48 path = self.abspath()
49 for fn in os.listdir(path):
50 if fn.startswith('__'):
51 continue
52 if not fn.endswith('.py'):
53 continue
54 self.__import(fn)
55
57 """
58 Import a module by file name.
59 @param fn: The module file name.
60 @type fn: str
61 """
62 mod = fn.rsplit('.', 1)[0]
63 imp = '%s.%s' % (self.PLUGINS, mod)
64 try:
65 __import__(imp)
66 log.info('plugin "%s", imported', imp)
67 except:
68 log.error('plugin "%s", import failed', imp, exc_info=True)
69