author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Thu, 16 Jul 2009 16:30:58 +0200 | |
changeset 2384 | 6220783caa4b |
parent 1977 | 606923dff11b |
child 2476 | 1294a6bdf3bf |
permissions | -rw-r--r-- |
0 | 1 |
"""goa specific registry |
2 |
||
3 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
4 |
:copyright: 2008-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
__docformat__ = "restructuredtext en" |
|
9 |
||
10 |
from os import listdir |
|
11 |
from os.path import join, isdir |
|
12 |
||
13 |
from cubicweb import CW_SOFTWARE_ROOT |
|
14 |
from cubicweb.cwvreg import CubicWebRegistry |
|
15 |
||
16 |
||
17 |
def _pkg_name(cube, module): |
|
18 |
if cube is None: |
|
19 |
return module |
|
9
1901fcf55ed4
Add cubes as a prefix for import of cubes.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
0
diff
changeset
|
20 |
return 'cubes.%s.%s' % (cube, module) |
0 | 21 |
|
22 |
class GAERegistry(CubicWebRegistry): |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9
diff
changeset
|
23 |
|
0 | 24 |
def set_schema(self, schema): |
25 |
"""disable reload hooks of cubicweb registry set_schema method""" |
|
26 |
self.schema = schema |
|
27 |
||
28 |
def load(self, applroot): |
|
29 |
from cubicweb.goa import db |
|
30 |
self.load_module(db) # AnyEntity class |
|
31 |
# explicit loading, we don't want to load __init__.py |
|
32 |
self.load_directory(join(CW_SOFTWARE_ROOT, 'entities'), |
|
33 |
'cubicweb.entities', skip=('__init__.py',)) |
|
34 |
self.load_directory(join(CW_SOFTWARE_ROOT, 'web', 'views'), |
|
35 |
'cubicweb.web.views') |
|
36 |
self.load_directory(join(CW_SOFTWARE_ROOT, 'goa', 'appobjects'), |
|
37 |
'cubicweb.goa.appobjects') |
|
38 |
for cube in reversed(self.config.cubes()): |
|
39 |
self.load_cube(cube) |
|
40 |
self.load_application(applroot) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9
diff
changeset
|
41 |
|
0 | 42 |
def load_directory(self, directory, cube, skip=()): |
43 |
for filename in listdir(directory): |
|
44 |
if filename[-3:] == '.py' and not filename in skip: |
|
45 |
self._import('%s.%s' % (cube, filename[:-3])) |
|
46 |
||
47 |
def load_cube(self, cube): |
|
48 |
self._auto_load(self.config.cube_dir(cube), |
|
49 |
cube in self.config['included-cubes'], |
|
50 |
cube) |
|
51 |
||
52 |
def load_application(self, applroot): |
|
53 |
self._auto_load(applroot, self.config['schema-type'] == 'dbmodel') |
|
54 |
||
55 |
def _import(self, modname): |
|
56 |
obj = __import__(modname) |
|
57 |
for attr in modname.split('.')[1:]: |
|
58 |
obj = getattr(obj, attr) |
|
59 |
self.load_module(obj) |
|
60 |
||
61 |
def _auto_load(self, path, loadschema, cube=None): |
|
62 |
vobjpath = self.config.cube_vobject_path |
|
63 |
for filename in listdir(path): |
|
64 |
if filename[-3:] == '.py' and filename[:-3] in vobjpath: |
|
65 |
self._import(_pkg_name(cube, filename[:-3])) |
|
66 |
else: |
|
67 |
abspath = join(path, filename) |
|
68 |
if isdir(abspath) and filename in vobjpath: |
|
69 |
self.load_directory(abspath, _pkg_name(cube, filename)) |
|
70 |
if loadschema: |
|
71 |
# when using db.Model defined schema, the defined class is used as |
|
72 |
# entity class as well and so have to be registered |
|
73 |
self._import(_pkg_name(cube, 'schema')) |