devtools/__init__.py
changeset 9402 2c48c091b6a2
parent 9117 e25c5abc667c
parent 9340 b1e933b0e850
child 9456 a79e88aad555
--- a/devtools/__init__.py	Tue Jul 02 17:09:04 2013 +0200
+++ b/devtools/__init__.py	Mon Jan 13 13:47:47 2014 +0100
@@ -26,6 +26,7 @@
 import pickle
 import glob
 import warnings
+import tempfile
 from hashlib import sha1 # pylint: disable=E0611
 from datetime import timedelta
 from os.path import (abspath, join, exists, split, isabs, isdir)
@@ -37,7 +38,7 @@
 from cubicweb import ExecutionError, BadConnectionId
 from cubicweb import schema, cwconfig
 from cubicweb.server.serverconfig import ServerConfiguration
-from cubicweb.etwist.twconfig import TwistedConfiguration
+from cubicweb.etwist.twconfig import WebConfigurationBase
 
 cwconfig.CubicWebConfiguration.cls_adjust_sys_path()
 
@@ -213,12 +214,12 @@
         return BASE_URL
 
 
-class BaseApptestConfiguration(TestServerConfiguration, TwistedConfiguration):
+class BaseApptestConfiguration(TestServerConfiguration, WebConfigurationBase):
     name = 'all-in-one' # so it search for all-in-one.conf, not repository.conf
     options = cwconfig.merge_options(TestServerConfiguration.options
-                                     + TwistedConfiguration.options)
-    cubicweb_appobject_path = TestServerConfiguration.cubicweb_appobject_path | TwistedConfiguration.cubicweb_appobject_path
-    cube_appobject_path = TestServerConfiguration.cube_appobject_path | TwistedConfiguration.cube_appobject_path
+                                     + WebConfigurationBase.options)
+    cubicweb_appobject_path = TestServerConfiguration.cubicweb_appobject_path | WebConfigurationBase.cubicweb_appobject_path
+    cube_appobject_path = TestServerConfiguration.cube_appobject_path | WebConfigurationBase.cube_appobject_path
 
     def available_languages(self, *args):
         return self.cw_languages()
@@ -287,8 +288,11 @@
 
         The function create it if necessary"""
         backupdir = join(self.config.apphome, 'database')
-        if not isdir(backupdir):
+        try:
             os.makedirs(backupdir)
+        except:
+            if not isdir(backupdir):
+                raise
         return backupdir
 
     def config_path(self, db_id):
@@ -324,8 +328,9 @@
         # XXX we dump a dict of the config
         # This is an experimental to help config dependant setup (like BFSS) to
         # be propertly restored
-        with open(config_path, 'wb') as conf_file:
+        with tempfile.NamedTemporaryFile(dir=os.path.dirname(config_path), delete=False) as conf_file:
             conf_file.write(pickle.dumps(dict(self.config)))
+        os.rename(conf_file.name, config_path)
         self.db_cache[self.db_cache_key(db_id)] = (backup_data, config_path)
 
     def _backup_database(self, db_id):