Package pulp :: Package client :: Package agent :: Module plugin
[hide private]
[frames] | no frames]

Source Code for Module pulp.client.agent.plugin

 1  # 
 2  # Copyright (c) 2010 Red Hat, Inc. 
 3  # 
 4  # This software is licensed to you under the GNU General Public License, 
 5  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
 6  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
 7  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
 8  # along with this software; if not, see 
 9  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
10  # 
11  # Red Hat trademarks are not licensed under GPLv2. No permission is 
12  # granted to use or replicate Red Hat trademarks that are incorporated 
13  # in this software or its documentation. 
14  # 
15   
16  import os 
17  from logging import getLogger 
18   
19  log = getLogger(__name__) 
20 21 22 -class PluginLoader:
23 """ 24 Agent plugins loader. 25 """ 26 27 ROOT = '/var/lib/pulp/agent' 28 PLUGINS = 'plugins' 29 30 @classmethod
31 - def abspath(cls):
32 return os.path.join(cls.ROOT, cls.PLUGINS)
33
34 - def __init__(self):
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
43 - def load(self):
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
56 - def __import(self, fn):
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