Add options to explicitly set database uris during install
[cascardo/ipsilon.git] / ipsilon / util / data.py
old mode 100755 (executable)
new mode 100644 (file)
index 0e086b3..72e7f96
@@ -1,5 +1,3 @@
-#!/usr/bin/python
-#
 # Copyright (C) 2013  Simo Sorce <simo@redhat.com>
 #
 # see file 'COPYING' for use and warranty information
@@ -138,6 +136,7 @@ class FileStore(Log):
         timestamp = stat.st_mtime
         if self._config is None or timestamp > self._timestamp:
             self._config = ConfigParser.RawConfigParser()
+            self._config.optionxform = str
             self._config.read(self._filename)
         return self._config
 
@@ -231,10 +230,15 @@ class FileQuery(Log):
 
 
 class Store(Log):
-    def __init__(self, config_name):
-        if config_name not in cherrypy.config:
-            raise NameError('Unknown database %s' % config_name)
-        name = cherrypy.config[config_name]
+    def __init__(self, config_name=None, database_url=None):
+        if config_name is None and database_url is None:
+            raise ValueError('config_name or database_url must be provided')
+        if config_name:
+            if config_name not in cherrypy.config:
+                raise NameError('Unknown database %s' % config_name)
+            name = cherrypy.config[config_name]
+        else:
+            name = database_url
         if name.startswith('configfile://'):
             _, filename = name.split('://')
             self._db = FileStore(filename)
@@ -394,6 +398,7 @@ class Store(Log):
             self.error("Failed to delete data from %s: [%s]" % (table, e))
 
     def _reset_data(self, table):
+        q = None
         try:
             q = self._query(self._db, table, UNIQUE_DATA_COLUMNS)
             q.drop()