author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 12 Nov 2009 17:15:07 +0100 | |
branch | stable |
changeset 3830 | 3b6bbb3a3c3e |
parent 3539 | f3b14d052798 |
child 4212 | ab6573088b4a |
permissions | -rw-r--r-- |
0 | 1 |
"""google appengine configuration |
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 |
import os |
|
11 |
from os.path import join |
|
12 |
||
13 |
from cubicweb import CW_SOFTWARE_ROOT |
|
14 |
from cubicweb.cwconfig import CubicWebConfiguration |
|
1132 | 15 |
from cubicweb.web.webconfig import WebConfiguration, merge_options |
0 | 16 |
from cubicweb.server.serverconfig import ServerConfiguration |
17 |
from cubicweb.goa.dbmyams import load_schema |
|
18 |
||
19 |
UNSUPPORTED_OPTIONS = set(('connections-pool-size', |
|
3539
f3b14d052798
[pyro] merge pyro-id / pyro-instance-id options, put all pyro options in the same section of the configuration file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
20 |
'pyro-host', 'pyro-instance-id', |
2665
0c6281487f90
[pyro] use lgc.pyro_ext, simplify pyro related options
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
21 |
'pyro-ns-host', 'pyro-ns-group', |
0 | 22 |
'https-url', 'host', 'pid-file', 'uid', 'base-url', 'log-file', |
23 |
'smtp-host', 'smtp-port', |
|
24 |
'embed-allowed', |
|
25 |
)) |
|
26 |
||
27 |
# XXX fix: |
|
28 |
# * default sender-name / sender-addr value |
|
29 |
# * what about *session-time |
|
30 |
# * check auth-mode=http + fix doc (eg require use-google-auth = False) |
|
31 |
||
32 |
class GAEConfiguration(ServerConfiguration, WebConfiguration): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
33 |
"""repository and web instance in Google AppEngine environment""" |
0 | 34 |
name = 'app' |
35 |
repo_method = 'inmemory' |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
36 |
options = merge_options(( |
0 | 37 |
('included-cubes', |
38 |
{'type' : 'csv', |
|
39 |
'default': [], |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
40 |
'help': 'list of db model based cubes used by the instance.', |
0 | 41 |
'group': 'main', 'inputlevel': 1, |
42 |
}), |
|
43 |
('included-yams-cubes', |
|
44 |
{'type' : 'csv', |
|
45 |
'default': [], |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
46 |
'help': 'list of yams based cubes used by the instance.', |
0 | 47 |
'group': 'main', 'inputlevel': 1, |
48 |
}), |
|
49 |
('use-google-auth', |
|
50 |
{'type' : 'yn', |
|
51 |
'default': True, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
52 |
'help': 'does this instance rely on google authentication service or not.', |
0 | 53 |
'group': 'main', 'inputlevel': 1, |
54 |
}), |
|
55 |
('schema-type', |
|
56 |
{'type' : 'choice', 'choices': ('yams', 'dbmodel'), |
|
57 |
'default': 'yams', |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
58 |
'help': 'does this instance is defining its schema using yams or db model.', |
0 | 59 |
'group': 'main', 'inputlevel': 1, |
60 |
}), |
|
61 |
# overriden options |
|
62 |
('query-log-file', |
|
63 |
{'type' : 'string', |
|
64 |
'default': None, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
65 |
'help': 'web instance query log file: DON\'T SET A VALUE HERE WHEN ' |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
66 |
'UPLOADING YOUR INSTANCE. This should only be used to analyse ' |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
67 |
'queries issued by your instance in the development environment.', |
0 | 68 |
'group': 'main', 'inputlevel': 2, |
69 |
}), |
|
70 |
('anonymous-user', |
|
71 |
{'type' : 'string', |
|
72 |
'default': None, |
|
73 |
'help': 'login of the CubicWeb user account to use for anonymous user ' |
|
74 |
'(if you want to allow anonymous). This option will be ignored if ' |
|
75 |
'use-google-auth option is set (in which case you should control ' |
|
76 |
'anonymous access using the app.yaml file)', |
|
77 |
'group': 'main', 'inputlevel': 1, |
|
78 |
}), |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
79 |
|
0 | 80 |
) + WebConfiguration.options + ServerConfiguration.options) |
81 |
options = [(optname, optdict) for optname, optdict in options |
|
82 |
if not optname in UNSUPPORTED_OPTIONS] |
|
83 |
||
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
84 |
cubicweb_appobject_path = WebConfiguration.cubicweb_appobject_path | ServerConfiguration.cubicweb_appobject_path |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
85 |
cubicweb_appobject_path = list(cubicweb_appobject_path) + ['goa/appobjects'] |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
86 |
cube_appobject_path = WebConfiguration.cube_appobject_path | ServerConfiguration.cube_appobject_path |
0 | 87 |
|
88 |
# use file system schema |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
89 |
bootstrap_schema = read_instance_schema = False |
0 | 90 |
# schema is not persistent, don't load schema hooks (unavailable) |
91 |
schema_hooks = False |
|
92 |
# no user workflow for now |
|
93 |
consider_user_state = False |
|
94 |
||
95 |
# deactivate some hooks during [pre|post]create scripts execution |
|
96 |
# (unique values check, owned_by/created_by relations setup) |
|
97 |
free_wheel = True |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
98 |
|
0 | 99 |
if not os.environ.get('APYCOT_ROOT'): |
100 |
CUBES_DIR = join(CW_SOFTWARE_ROOT, '../cubes') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
101 |
|
0 | 102 |
def __init__(self, appid, apphome=None): |
103 |
if apphome is None: |
|
104 |
apphome = 'data' |
|
105 |
self._apphome = apphome |
|
106 |
self._base_url = None |
|
107 |
CubicWebConfiguration.__init__(self, appid) |
|
108 |
||
109 |
def __getitem__(self, key): |
|
110 |
if key == 'connections-pool-size': |
|
111 |
return 4 # > 1 to allow multiple user sessions in tests |
|
112 |
if key == 'base-url': |
|
113 |
return self._base_url |
|
114 |
return super(GAEConfiguration, self).__getitem__(key) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
115 |
|
0 | 116 |
# overriden from cubicweb base configuration |
117 |
||
118 |
@property |
|
119 |
def apphome(self): |
|
120 |
return self._apphome |
|
121 |
||
122 |
def cubes(self): |
|
123 |
"""return the list of top level cubes used by this instance (eg |
|
124 |
without dependencies) |
|
125 |
""" |
|
126 |
if self._cubes is None: |
|
127 |
cubes = self['included-cubes'] + self['included-yams-cubes'] |
|
128 |
cubes = self.expand_cubes(cubes) |
|
129 |
return self.reorder_cubes(cubes) |
|
130 |
return self._cubes |
|
131 |
||
132 |
def vc_config(self): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
133 |
"""return CubicWeb's engine and instance's cube versions number""" |
0 | 134 |
return {} |
135 |
||
136 |
# overriden from cubicweb web configuration |
|
137 |
||
138 |
def instance_md5_version(self): |
|
139 |
return '' |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
140 |
|
0 | 141 |
def _init_base_url(self): |
142 |
pass |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
143 |
|
0 | 144 |
# overriden from cubicweb server configuration |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
145 |
|
0 | 146 |
def sources(self): |
147 |
return {'system': {'adapter': 'gae'}} |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
148 |
|
0 | 149 |
def load_schema(self, schemaclasses=None, extrahook=None): |
150 |
try: |
|
151 |
return self._schema |
|
152 |
except AttributeError: |
|
153 |
self._schema = load_schema(self, schemaclasses, extrahook) |
|
154 |
return self._schema |
|
155 |
||
156 |
# goa specific |
|
157 |
def repo_session(self, sessionid): |
|
158 |
return self.repository()._sessions[sessionid] |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
159 |
|
0 | 160 |
def is_anonymous_user(self, login): |
161 |
if self['use-google-auth']: |
|
162 |
from google.appengine.api import users |
|
163 |
return users.get_current_user() is None |
|
164 |
else: |
|
165 |
return login == self.anonymous_user()[0] |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
166 |