1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
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
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