Package flumotion :: Package project :: Module project
[hide private]

Source Code for Module flumotion.project.project

 1  # -*- Mode: Python -*- 
 2  # vi:si:et:sw=4:sts=4:ts=4 
 3   
 4  # Flumotion - a streaming media server 
 5  # Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L. 
 6  # Copyright (C) 2010,2011 Flumotion Services, S.A. 
 7  # All rights reserved. 
 8  # 
 9  # This file may be distributed and/or modified under the terms of 
10  # the GNU Lesser General Public License version 2.1 as published by 
11  # the Free Software Foundation. 
12  # This file is distributed without any warranty; without even the implied 
13  # warranty of merchantability or fitness for a particular purpose. 
14  # See "LICENSE.LGPL" in the source distribution for more information. 
15  # 
16  # Headers in this file shall remain intact. 
17   
18  import os 
19  import sys 
20   
21  from flumotion.common import package, errors, log 
22  from flumotion.configure import configure 
23   
24  import flumotion.project 
25   
26  __version__ = "$Rev$" 
27   
28   
29 -def list():
30 """ 31 Returns a list of all add-on projects seen by Flumotion. 32 """ 33 projects = [n for n in sys.modules.keys() 34 if n.startswith('flumotion.project')] 35 paths = flumotion.project.__path__ 36 modules = [] 37 for path in paths: 38 modules.extend(package.findEndModuleCandidates( 39 os.path.abspath(os.path.join(path, '..', '..')), 40 prefix='flumotion.project')) 41 42 modules.remove('flumotion.project.project') 43 44 return [n[len('flumotion.project.'):] for n in modules]
45 46
47 -def get(project, attribute, default=None):
48 """ 49 Get an attribute from a project's module. 50 """ 51 log.debug('project', 'Getting attribute %s from project %s', 52 attribute, project) 53 54 # short-circuit flumotion, the core project 55 if project == 'flumotion': 56 return getattr(configure, attribute, default) 57 58 moduleName = "flumotion.project.%s" % project 59 try: 60 exec("import %s" % moduleName) 61 except ImportError, e: 62 msg = ('Could not load project %s: %s' % 63 (project, log.getExceptionMessage(e))) 64 log.warning('project', msg) 65 raise errors.NoProjectError(project, msg) 66 except SyntaxError, e: 67 msg = ('Syntax error while loading project %s: %s' % 68 (project, log.getExceptionMessage(e))) 69 log.warning('project', msg) 70 raise errors.NoProjectError(project, msg) 71 m = sys.modules[moduleName] 72 return getattr(m, attribute, default)
73