From: Michael Tremer Date: Sat, 7 Oct 2017 11:54:59 +0000 (+0100) Subject: Cleanup database initialisation code X-Git-Url: http://git.ipfire.org/?p=people%2Fjschlag%2Fpbs.git;a=commitdiff_plain;h=fe1f59cab9855ab8fc35acf6ea126dc887e45869 Cleanup database initialisation code Signed-off-by: Michael Tremer --- diff --git a/pbs.conf.sample b/pbs.conf.sample index 6578f86..57404e6 100644 --- a/pbs.conf.sample +++ b/pbs.conf.sample @@ -1,7 +1,7 @@ [database] -; Credentials to the pakfire build service database. +; Credentials to the pakfire build service database -host = mysql-master.ipfire.org -user = pakfire -pass = pakfire -db = pakfire +name = pakfire +hostname = db-master.ipfire.org +user = pakfire +password = pakfire diff --git a/src/buildservice/__init__.py b/src/buildservice/__init__.py index 365c612..424bdb2 100644 --- a/src/buildservice/__init__.py +++ b/src/buildservice/__init__.py @@ -89,21 +89,14 @@ class Backend(object): @lazy_property def db(self): - return self.connect_database() + name = self.config.get("database", "name") + hostname = self.config.get("database", "hostname") + user = self.config.get("database", "user") + password = self.config.get("database", "password") - def connect_database(self, section="database"): - name = self.config.get(section, "db") - host = self.config.get(section, "host") - user = self.config.get(section, "user") + log.debug("Connecting to database %s @ %s" % (name, hostname)) - if self.config.has_option(section, "pass"): - pw = self.config.get(section, "pass") - else: - pw = None - - log.debug("Connecting to database %s @ %s" % (name, host)) - - return database.Connection(host, name, user=user, password=pw) + return database.Connection(hostname, name, user=user, password=password) def cleanup_files(self): query = self.db.query("SELECT * FROM queue_delete")