[sqlite] quick hacks to fix #1251873 and #1251874 stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 22 Sep 2010 12:29:20 +0200
branchstable
changeset 6299 51a9494b5efb
parent 6298 f4347f796908
child 6300 6794e3067f70
[sqlite] quick hacks to fix #1251873 and #1251874
server/serverconfig.py
server/serverctl.py
--- a/server/serverconfig.py	Wed Sep 22 12:14:54 2010 +0200
+++ b/server/serverconfig.py	Wed Sep 22 12:29:20 2010 +0200
@@ -45,15 +45,27 @@
     )
 
 class SourceConfiguration(Configuration):
-    def __init__(self, appid, options):
-        self.appid = appid # has to be done before super call
+    def __init__(self, appconfig, options):
+        self.appconfig = appconfig # has to be done before super call
         super(SourceConfiguration, self).__init__(options=options)
 
     # make Method('default_instance_id') usable in db option defs (in native.py)
     def default_instance_id(self):
-        return self.appid
+        return self.appconfig.appid
 
-def generate_sources_file(appid, sourcesfile, sourcescfg, keys=None):
+    def input_option(self, option, optdict, inputlevel):
+        if self['db-driver'] == 'sqlite':
+            if option in ('db-user', 'db-password'):
+                return
+            if option == 'db-name':
+                optdict = optdict.copy()
+                optdict['help'] = 'path to the sqlite database'
+                optdict['default'] = join(self.appconfig.appdatahome,
+                                          self.appconfig.appid + '.sqlite')
+        super(SourceConfiguration, self).input_option(option, optdict, inputlevel)
+
+
+def generate_sources_file(appconfig, sourcesfile, sourcescfg, keys=None):
     """serialize repository'sources configuration into a INI like file
 
     the `keys` parameter may be used to sort sections
@@ -73,7 +85,7 @@
                 options = USER_OPTIONS
             else:
                 options = SOURCE_TYPES[sconfig['adapter']].options
-            _sconfig = SourceConfiguration(appid, options=options)
+            _sconfig = SourceConfiguration(appconfig, options=options)
             for attr, val in sconfig.items():
                 if attr == 'uri':
                     continue
@@ -272,7 +284,7 @@
         if exists(sourcesfile):
             import shutil
             shutil.copy(sourcesfile, sourcesfile + '.bak')
-        generate_sources_file(self.appid, sourcesfile, sourcescfg,
+        generate_sources_file(self, sourcesfile, sourcescfg,
                               ['admin', 'system'])
         restrict_perms_to_user(sourcesfile)
 
--- a/server/serverctl.py	Wed Sep 22 12:14:54 2010 +0200
+++ b/server/serverctl.py	Wed Sep 22 12:29:20 2010 +0200
@@ -174,7 +174,7 @@
         sourcesfile = config.sources_file()
         # XXX hack to make Method('default_instance_id') usable in db option
         # defs (in native.py)
-        sconfig = SourceConfiguration(config.appid,
+        sconfig = SourceConfiguration(config,
                                       options=SOURCE_TYPES['native'].options)
         sconfig.adapter = 'native'
         sconfig.input_config(inputlevel=inputlevel)
@@ -234,6 +234,9 @@
         dbname = source['db-name']
         helper = get_db_helper(source['db-driver'])
         if ASK.confirm('Delete database %s ?' % dbname):
+            if source['db-driver'] == 'sqlite':
+                os.unlink(source['db-name'])
+                return
             user = source['db-user'] or None
             cnx = _db_sys_cnx(source, 'DROP DATABASE', user=user)
             cursor = cnx.cursor()