author | Julien Jehannet <julien.jehannet@logilab.fr> |
Wed, 07 Jul 2010 13:13:13 +0200 | |
branch | stable |
changeset 5925 | a1a334d93439 |
parent 5424 | 8ecbcbff9777 |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
0 | 18 |
"""goa specific registry |
19 |
||
20 |
""" |
|
21 |
__docformat__ = "restructuredtext en" |
|
22 |
||
23 |
from os import listdir |
|
24 |
from os.path import join, isdir |
|
25 |
||
26 |
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
|
27 |
from cubicweb.cwvreg import CubicWebVRegistry |
0 | 28 |
|
29 |
||
30 |
def _pkg_name(cube, module): |
|
31 |
if cube is None: |
|
32 |
return module |
|
9
1901fcf55ed4
Add cubes as a prefix for import of cubes.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
0
diff
changeset
|
33 |
return 'cubes.%s.%s' % (cube, module) |
0 | 34 |
|
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
|
35 |
class GAEVRegistry(CubicWebVRegistry): |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9
diff
changeset
|
36 |
|
0 | 37 |
def set_schema(self, schema): |
38 |
"""disable reload hooks of cubicweb registry set_schema method""" |
|
39 |
self.schema = schema |
|
40 |
||
41 |
def load(self, applroot): |
|
42 |
from cubicweb.goa import db |
|
43 |
self.load_module(db) # AnyEntity class |
|
44 |
# explicit loading, we don't want to load __init__.py |
|
45 |
self.load_directory(join(CW_SOFTWARE_ROOT, 'entities'), |
|
46 |
'cubicweb.entities', skip=('__init__.py',)) |
|
47 |
self.load_directory(join(CW_SOFTWARE_ROOT, 'web', 'views'), |
|
48 |
'cubicweb.web.views') |
|
49 |
self.load_directory(join(CW_SOFTWARE_ROOT, 'goa', 'appobjects'), |
|
50 |
'cubicweb.goa.appobjects') |
|
51 |
for cube in reversed(self.config.cubes()): |
|
52 |
self.load_cube(cube) |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
53 |
self.load_instance(applroot) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9
diff
changeset
|
54 |
|
0 | 55 |
def load_directory(self, directory, cube, skip=()): |
56 |
for filename in listdir(directory): |
|
57 |
if filename[-3:] == '.py' and not filename in skip: |
|
58 |
self._import('%s.%s' % (cube, filename[:-3])) |
|
59 |
||
60 |
def load_cube(self, cube): |
|
61 |
self._auto_load(self.config.cube_dir(cube), |
|
62 |
cube in self.config['included-cubes'], |
|
63 |
cube) |
|
64 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
65 |
def load_instance(self, applroot): |
0 | 66 |
self._auto_load(applroot, self.config['schema-type'] == 'dbmodel') |
67 |
||
68 |
def _import(self, modname): |
|
69 |
obj = __import__(modname) |
|
70 |
for attr in modname.split('.')[1:]: |
|
71 |
obj = getattr(obj, attr) |
|
72 |
self.load_module(obj) |
|
73 |
||
74 |
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
|
75 |
vobjpath = self.config.cube_appobject_path |
0 | 76 |
for filename in listdir(path): |
77 |
if filename[-3:] == '.py' and filename[:-3] in vobjpath: |
|
78 |
self._import(_pkg_name(cube, filename[:-3])) |
|
79 |
else: |
|
80 |
abspath = join(path, filename) |
|
81 |
if isdir(abspath) and filename in vobjpath: |
|
82 |
self.load_directory(abspath, _pkg_name(cube, filename)) |
|
83 |
if loadschema: |
|
84 |
# when using db.Model defined schema, the defined class is used as |
|
85 |
# entity class as well and so have to be registered |
|
86 |
self._import(_pkg_name(cube, 'schema')) |