1 """google appengine configuration |
1 """google appengine configuration |
2 |
2 |
3 :organization: Logilab |
3 :organization: Logilab |
4 :copyright: 2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
4 :copyright: 2008-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 """ |
6 """ |
7 __docformat__ = "restructuredtext en" |
7 __docformat__ = "restructuredtext en" |
8 |
8 |
9 import os |
9 import os |
30 |
30 |
31 class GAEConfiguration(ServerConfiguration, WebConfiguration): |
31 class GAEConfiguration(ServerConfiguration, WebConfiguration): |
32 """repository and web application in the same twisted process""" |
32 """repository and web application in the same twisted process""" |
33 name = 'app' |
33 name = 'app' |
34 repo_method = 'inmemory' |
34 repo_method = 'inmemory' |
35 options = merge_options(( |
35 options = merge_options(( |
36 ('included-cubes', |
36 ('included-cubes', |
37 {'type' : 'csv', |
37 {'type' : 'csv', |
38 'default': [], |
38 'default': [], |
39 'help': 'list of db model based cubes used by the application.', |
39 'help': 'list of db model based cubes used by the application.', |
40 'group': 'main', 'inputlevel': 1, |
40 'group': 'main', 'inputlevel': 1, |
73 '(if you want to allow anonymous). This option will be ignored if ' |
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 ' |
74 'use-google-auth option is set (in which case you should control ' |
75 'anonymous access using the app.yaml file)', |
75 'anonymous access using the app.yaml file)', |
76 'group': 'main', 'inputlevel': 1, |
76 'group': 'main', 'inputlevel': 1, |
77 }), |
77 }), |
78 |
78 |
79 ) + WebConfiguration.options + ServerConfiguration.options) |
79 ) + WebConfiguration.options + ServerConfiguration.options) |
80 options = [(optname, optdict) for optname, optdict in options |
80 options = [(optname, optdict) for optname, optdict in options |
81 if not optname in UNSUPPORTED_OPTIONS] |
81 if not optname in UNSUPPORTED_OPTIONS] |
82 |
82 |
83 cubicweb_vobject_path = WebConfiguration.cubicweb_vobject_path | ServerConfiguration.cubicweb_vobject_path |
83 cubicweb_vobject_path = WebConfiguration.cubicweb_vobject_path | ServerConfiguration.cubicweb_vobject_path |
92 consider_user_state = False |
92 consider_user_state = False |
93 |
93 |
94 # deactivate some hooks during [pre|post]create scripts execution |
94 # deactivate some hooks during [pre|post]create scripts execution |
95 # (unique values check, owned_by/created_by relations setup) |
95 # (unique values check, owned_by/created_by relations setup) |
96 free_wheel = True |
96 free_wheel = True |
97 |
97 |
98 if not os.environ.get('APYCOT_ROOT'): |
98 if not os.environ.get('APYCOT_ROOT'): |
99 CUBES_DIR = join(CW_SOFTWARE_ROOT, '../cubes') |
99 CUBES_DIR = join(CW_SOFTWARE_ROOT, '../cubes') |
100 |
100 |
101 def __init__(self, appid, apphome=None): |
101 def __init__(self, appid, apphome=None): |
102 if apphome is None: |
102 if apphome is None: |
103 apphome = 'data' |
103 apphome = 'data' |
104 self._apphome = apphome |
104 self._apphome = apphome |
105 self._base_url = None |
105 self._base_url = None |
109 if key == 'connections-pool-size': |
109 if key == 'connections-pool-size': |
110 return 4 # > 1 to allow multiple user sessions in tests |
110 return 4 # > 1 to allow multiple user sessions in tests |
111 if key == 'base-url': |
111 if key == 'base-url': |
112 return self._base_url |
112 return self._base_url |
113 return super(GAEConfiguration, self).__getitem__(key) |
113 return super(GAEConfiguration, self).__getitem__(key) |
114 |
114 |
115 # overriden from cubicweb base configuration |
115 # overriden from cubicweb base configuration |
116 |
116 |
117 @property |
117 @property |
118 def apphome(self): |
118 def apphome(self): |
119 return self._apphome |
119 return self._apphome |
134 |
134 |
135 # overriden from cubicweb web configuration |
135 # overriden from cubicweb web configuration |
136 |
136 |
137 def instance_md5_version(self): |
137 def instance_md5_version(self): |
138 return '' |
138 return '' |
139 |
139 |
140 def _init_base_url(self): |
140 def _init_base_url(self): |
141 pass |
141 pass |
142 |
142 |
143 # overriden from cubicweb server configuration |
143 # overriden from cubicweb server configuration |
144 |
144 |
145 def sources(self): |
145 def sources(self): |
146 return {'system': {'adapter': 'gae'}} |
146 return {'system': {'adapter': 'gae'}} |
147 |
147 |
148 def load_schema(self, schemaclasses=None, extrahook=None): |
148 def load_schema(self, schemaclasses=None, extrahook=None): |
149 try: |
149 try: |
150 return self._schema |
150 return self._schema |
151 except AttributeError: |
151 except AttributeError: |
152 self._schema = load_schema(self, schemaclasses, extrahook) |
152 self._schema = load_schema(self, schemaclasses, extrahook) |
153 return self._schema |
153 return self._schema |
154 |
154 |
155 # goa specific |
155 # goa specific |
156 def repo_session(self, sessionid): |
156 def repo_session(self, sessionid): |
157 return self.repository()._sessions[sessionid] |
157 return self.repository()._sessions[sessionid] |
158 |
158 |
159 def is_anonymous_user(self, login): |
159 def is_anonymous_user(self, login): |
160 if self['use-google-auth']: |
160 if self['use-google-auth']: |
161 from google.appengine.api import users |
161 from google.appengine.api import users |
162 return users.get_current_user() is None |
162 return users.get_current_user() is None |
163 else: |
163 else: |
164 return login == self.anonymous_user()[0] |
164 return login == self.anonymous_user()[0] |
|
165 |