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