equal
deleted
inserted
replaced
24 import logging |
24 import logging |
25 import shutil |
25 import shutil |
26 import pickle |
26 import pickle |
27 import glob |
27 import glob |
28 import warnings |
28 import warnings |
|
29 import tempfile |
29 from hashlib import sha1 # pylint: disable=E0611 |
30 from hashlib import sha1 # pylint: disable=E0611 |
30 from datetime import timedelta |
31 from datetime import timedelta |
31 from os.path import (abspath, join, exists, split, isabs, isdir) |
32 from os.path import (abspath, join, exists, split, isabs, isdir) |
32 from functools import partial |
33 from functools import partial |
33 |
34 |
35 from logilab.common.decorators import cached, clear_cache |
36 from logilab.common.decorators import cached, clear_cache |
36 |
37 |
37 from cubicweb import ExecutionError, BadConnectionId |
38 from cubicweb import ExecutionError, BadConnectionId |
38 from cubicweb import schema, cwconfig |
39 from cubicweb import schema, cwconfig |
39 from cubicweb.server.serverconfig import ServerConfiguration |
40 from cubicweb.server.serverconfig import ServerConfiguration |
40 from cubicweb.etwist.twconfig import TwistedConfiguration |
41 from cubicweb.etwist.twconfig import WebConfigurationBase |
41 |
42 |
42 cwconfig.CubicWebConfiguration.cls_adjust_sys_path() |
43 cwconfig.CubicWebConfiguration.cls_adjust_sys_path() |
43 |
44 |
44 # db auto-population configuration ############################################# |
45 # db auto-population configuration ############################################# |
45 |
46 |
211 |
212 |
212 def default_base_url(self): |
213 def default_base_url(self): |
213 return BASE_URL |
214 return BASE_URL |
214 |
215 |
215 |
216 |
216 class BaseApptestConfiguration(TestServerConfiguration, TwistedConfiguration): |
217 class BaseApptestConfiguration(TestServerConfiguration, WebConfigurationBase): |
217 name = 'all-in-one' # so it search for all-in-one.conf, not repository.conf |
218 name = 'all-in-one' # so it search for all-in-one.conf, not repository.conf |
218 options = cwconfig.merge_options(TestServerConfiguration.options |
219 options = cwconfig.merge_options(TestServerConfiguration.options |
219 + TwistedConfiguration.options) |
220 + WebConfigurationBase.options) |
220 cubicweb_appobject_path = TestServerConfiguration.cubicweb_appobject_path | TwistedConfiguration.cubicweb_appobject_path |
221 cubicweb_appobject_path = TestServerConfiguration.cubicweb_appobject_path | WebConfigurationBase.cubicweb_appobject_path |
221 cube_appobject_path = TestServerConfiguration.cube_appobject_path | TwistedConfiguration.cube_appobject_path |
222 cube_appobject_path = TestServerConfiguration.cube_appobject_path | WebConfigurationBase.cube_appobject_path |
222 |
223 |
223 def available_languages(self, *args): |
224 def available_languages(self, *args): |
224 return self.cw_languages() |
225 return self.cw_languages() |
225 |
226 |
226 def pyro_enabled(self): |
227 def pyro_enabled(self): |
285 def _ensure_test_backup_db_dir(self): |
286 def _ensure_test_backup_db_dir(self): |
286 """Return path of directory for database backup. |
287 """Return path of directory for database backup. |
287 |
288 |
288 The function create it if necessary""" |
289 The function create it if necessary""" |
289 backupdir = join(self.config.apphome, 'database') |
290 backupdir = join(self.config.apphome, 'database') |
290 if not isdir(backupdir): |
291 try: |
291 os.makedirs(backupdir) |
292 os.makedirs(backupdir) |
|
293 except: |
|
294 if not isdir(backupdir): |
|
295 raise |
292 return backupdir |
296 return backupdir |
293 |
297 |
294 def config_path(self, db_id): |
298 def config_path(self, db_id): |
295 """Path for config backup of a given database id""" |
299 """Path for config backup of a given database id""" |
296 return self.absolute_backup_file(db_id, 'config') |
300 return self.absolute_backup_file(db_id, 'config') |
322 backup_data = self._backup_database(db_id) |
326 backup_data = self._backup_database(db_id) |
323 config_path = self.config_path(db_id) |
327 config_path = self.config_path(db_id) |
324 # XXX we dump a dict of the config |
328 # XXX we dump a dict of the config |
325 # This is an experimental to help config dependant setup (like BFSS) to |
329 # This is an experimental to help config dependant setup (like BFSS) to |
326 # be propertly restored |
330 # be propertly restored |
327 with open(config_path, 'wb') as conf_file: |
331 with tempfile.NamedTemporaryFile(dir=os.path.dirname(config_path), delete=False) as conf_file: |
328 conf_file.write(pickle.dumps(dict(self.config))) |
332 conf_file.write(pickle.dumps(dict(self.config))) |
|
333 os.rename(conf_file.name, config_path) |
329 self.db_cache[self.db_cache_key(db_id)] = (backup_data, config_path) |
334 self.db_cache[self.db_cache_key(db_id)] = (backup_data, config_path) |
330 |
335 |
331 def _backup_database(self, db_id): |
336 def _backup_database(self, db_id): |
332 """Actual backup the current database. |
337 """Actual backup the current database. |
333 |
338 |