summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2014-09-25 16:05:04 -0400
committerPatrick Uiterwijk <puiterwijk@redhat.com>2014-10-06 20:25:04 +0200
commitcc0237a0ada6b6c2ec74d698391f47a38dee59a9 (patch)
tree275715cccbf76dee4645bcbc0c0a3f049c8ffbf5
parentbb9fddbbdc7c7b963feeffc73e96451d9607d2d4 (diff)
downloadipsilon-cc0237a0ada6b6c2ec74d698391f47a38dee59a9.tar.gz
ipsilon-cc0237a0ada6b6c2ec74d698391f47a38dee59a9.tar.xz
ipsilon-cc0237a0ada6b6c2ec74d698391f47a38dee59a9.zip
Databases must be configured in cherrypy.config
There was annoying duplicated init code in the data store classes that was unused. Just require configuration to be present in cherrypy.config or bail. Signed-off-by: Simo Sorce <simo@redhat.com> Reviewed-by: Patrick Uiterwijk <puiterwijk@redhat.com>
-rwxr-xr-xipsilon/util/data.py42
1 files changed, 8 insertions, 34 deletions
diff --git a/ipsilon/util/data.py b/ipsilon/util/data.py
index 5a144a4..1f34860 100755
--- a/ipsilon/util/data.py
+++ b/ipsilon/util/data.py
@@ -17,7 +17,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-import os
import sqlite3
import cherrypy
from ipsilon.util.log import Log
@@ -30,8 +29,10 @@ UNIQUE_DATA_COLUMNS = ['uuid', 'name', 'value']
class Store(Log):
- def __init__(self, name):
- self._dbname = name
+ def __init__(self, config_name):
+ if config_name not in cherrypy.config:
+ raise NameError('Unknown database type %s' % config_name)
+ self._dbname = cherrypy.config[config_name]
def _build_where(self, kvfilter, kvout):
where = ""
@@ -287,17 +288,8 @@ class Store(Log):
class AdminStore(Store):
- def __init__(self, path=None):
- if path is None:
- self._path = os.getcwd()
- else:
- self._path = path
- self._name = None
- if 'admin.config.db' in cherrypy.config:
- self._name = cherrypy.config['admin.config.db']
- if not self._name:
- self._name = os.path.join(self._path, 'adminconfig.sqlite')
- super(AdminStore, self).__init__(self._name)
+ def __init__(self):
+ super(AdminStore, self).__init__('admin.config.db')
def get_data(self, plugin, idval=None, name=None, value=None):
return self.get_unique_data(plugin+"_data", idval, name, value)
@@ -335,16 +327,7 @@ class AdminStore(Store):
class UserStore(Store):
def __init__(self, path=None):
- if path is None:
- self._path = os.getcwd()
- else:
- self._path = path
- self._name = None
- if 'user.prefs.db' in cherrypy.config:
- self._name = cherrypy.config['user.prefs.db']
- if not self._name:
- self._name = os.path.join(self._path, 'userprefs.sqlite')
- super(UserStore, self).__init__(self._name)
+ super(UserStore, self).__init__('user.prefs.db')
def save_user_preferences(self, user, options):
return self.save_options('users', user, options)
@@ -353,13 +336,4 @@ class UserStore(Store):
class TranStore(Store):
def __init__(self, path=None):
- if path is None:
- self._path = os.getcwd()
- else:
- self._path = path
- self._name = None
- if 'transactions.db' in cherrypy.config:
- self._name = cherrypy.config['transactions.db']
- if not self._name:
- self._name = os.path.join(self._path, 'transactions.sqlite')
- super(TranStore, self).__init__(self._name)
+ super(TranStore, self).__init__('transactions.db')