author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Thu, 23 Jul 2009 15:28:41 +0200 | |
changeset 2456 | aa25d6b244c8 |
parent 1977 | 606923dff11b |
child 2476 | 1294a6bdf3bf |
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', |
|
20 |
'pyro-port', 'pyro-id', 'pyro-application-id', |
|
21 |
'pyro-ns-host', 'pyro-ns-port', 'pyro-ns-group', |
|
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): |
|
33 |
"""repository and web application in the same twisted process""" |
|
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': [], |
|
40 |
'help': 'list of db model based cubes used by the application.', |
|
41 |
'group': 'main', 'inputlevel': 1, |
|
42 |
}), |
|
43 |
('included-yams-cubes', |
|
44 |
{'type' : 'csv', |
|
45 |
'default': [], |
|
46 |
'help': 'list of yams based cubes used by the application.', |
|
47 |
'group': 'main', 'inputlevel': 1, |
|
48 |
}), |
|
49 |
('use-google-auth', |
|
50 |
{'type' : 'yn', |
|
51 |
'default': True, |
|
52 |
'help': 'does this application rely on google authentication service or not.', |
|
53 |
'group': 'main', 'inputlevel': 1, |
|
54 |
}), |
|
55 |
('schema-type', |
|
56 |
{'type' : 'choice', 'choices': ('yams', 'dbmodel'), |
|
57 |
'default': 'yams', |
|
58 |
'help': 'does this application is defining its schema using yams or db model.', |
|
59 |
'group': 'main', 'inputlevel': 1, |
|
60 |
}), |
|
61 |
# overriden options |
|
62 |
('query-log-file', |
|
63 |
{'type' : 'string', |
|
64 |
'default': None, |
|
65 |
'help': 'web application query log file: DON\'T SET A VALUE HERE WHEN ' |
|
66 |
'UPLOADING YOUR APPLICATION. This should only be used to analyse ' |
|
67 |
'queries issued by your application in the development environment.', |
|
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 |
||
84 |
cubicweb_vobject_path = WebConfiguration.cubicweb_vobject_path | ServerConfiguration.cubicweb_vobject_path |
|
85 |
cubicweb_vobject_path = list(cubicweb_vobject_path) + ['goa/appobjects'] |
|
86 |
cube_vobject_path = WebConfiguration.cube_vobject_path | ServerConfiguration.cube_vobject_path |
|
87 |
||
88 |
# use file system schema |
|
89 |
bootstrap_schema = read_application_schema = False |
|
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): |
|
133 |
"""return CubicWeb's engine and application's cube versions number""" |
|
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 |