author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 26 Feb 2010 13:24:47 +0100 | |
branch | stable |
changeset 4721 | 8f63691ccb7f |
parent 4212 | ab6573088b4a |
child 5421 | 8167de96c523 |
permissions | -rw-r--r-- |
0 | 1 |
"""goa specific registry |
2 |
||
3 |
:organization: Logilab |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2657
diff
changeset
|
4 |
:copyright: 2008-2010 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 |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
14 |
from cubicweb.cwvreg import CubicWebVRegistry |
0 | 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 |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
22 |
class GAEVRegistry(CubicWebVRegistry): |
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) |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
40 |
self.load_instance(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 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
52 |
def load_instance(self, applroot): |
0 | 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): |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
62 |
vobjpath = self.config.cube_appobject_path |
0 | 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')) |