]> git.ipfire.org Git - people/jschlag/pbs.git/commitdiff
Move database configuration into a configuration file.
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 25 Nov 2012 11:58:17 +0000 (12:58 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 25 Nov 2012 11:58:17 +0000 (12:58 +0100)
.gitignore
backend/main.py
backend/mirrors.py
hub/__init__.py
pakfire-manager
pbs.conf.example [new file with mode: 0644]
web/__init__.py

index edc24a401ed125a2d5b97b3e6bc5d3076b36a898..cb99eec97621e9b9a706e7db79203ed5677ac8ae 100644 (file)
@@ -1,2 +1,4 @@
 *.py[co]
 *.mo
+
+pbs.conf
index 9eee8524ef77a8acbe349764d3a899eafbfaf29d..e7aaf41a63ff56120300ea17abbd340b484e097c 100644 (file)
@@ -1,5 +1,6 @@
 #!/usr/bin/python
 
+import ConfigParser
 import logging
 import os
 import pakfire
@@ -25,15 +26,14 @@ import users
 
 from constants import *
 
-# Database access.
-MYSQL_SERVER   = "mysql-master.ipfire.org"
-MYSQL_USER     = "pakfire"
-MYSQL_DB       = "pakfire"
-MYSQL_GEOIP_DB = "geoip"
-
 class Pakfire(object):
-       def __init__(self):
-               self.db = database.Connection(MYSQL_SERVER, MYSQL_DB, user=MYSQL_USER)
+       def __init__(self, config_file):
+               # Read configuration file.
+               self.config = self.read_config(config_file)
+
+               # Connect to databases.
+               self.db = self.connect_database()
+               self.geoip_db = self.connect_database("geoip-database")
 
                # Global pakfire settings (from database).
                self.settings = settings.Settings(self)
@@ -41,8 +41,7 @@ class Pakfire(object):
                self.arches      = arches.Arches(self)
                self.builds      = builds.Builds(self)
                self.cache       = cache.Cache(self)
-               self.geoip       = mirrors.GeoIP(self, MYSQL_SERVER, MYSQL_GEOIP_DB,
-                                                               user=MYSQL_USER)
+               self.geoip       = mirrors.GeoIP(self)
                self.jobs        = builds.Jobs(self)
                self.builders    = builders.Builders(self)
                self.distros     = distribution.Distributions(self)
@@ -67,6 +66,24 @@ class Pakfire(object):
                        self.db.close()
                        del self.db
 
+       def read_config(self, path):
+               c = ConfigParser.SafeConfigParser()
+               c.read(path)
+
+               return c
+
+       def connect_database(self, section="database"):
+               db = self.config.get(section, "db")
+               host = self.config.get(section, "host")
+               user = self.config.get(section, "user")
+
+               if self.config.has_option(section, "pass"):
+                       pw = self.config.get(section, "pass")
+               else:
+                       pw = None
+
+               return database.Connection(host, db, user=user, password=pw)
+
        def cleanup_files(self):
                query = self.db.query("SELECT * FROM queue_delete")
 
index fb05f011e397b15b6254c6153eab2a60ad2e630c..261682b167448c5df569fb95b4a23745b41ff222 100644 (file)
@@ -9,17 +9,10 @@ import base
 import logs
 
 class GeoIP(object):
-       db = None
-
-       def __init__(self, pakfire, server, name, user):
+       def __init__(self, pakfire):
                self.pakfire = pakfire
 
-               if self.db is None:
-                       self.db = tornado.database.Connection(
-                               server, name, user=user
-                       )
-
-                       logging.info("Creating database connection to GeoIP database.")
+               self.db = self.pakfire.geoip_db
 
        @property
        def cache(self):
index 484d9a3f07d6431a2c7c7b36b8e054644051c5b4..748ff5fbb3c1ab8332d63c745cc05d0f4dbb645b 100644 (file)
@@ -44,7 +44,9 @@ class Application(tornado.web.Application):
        @property
        def pakfire(self):
                if self.__pakfire is None:
-                       self.__pakfire = backend.Pakfire()
+                       config_file = os.path.join(BASEDIR, "..", "pbs.conf")
+
+                       self.__pakfire = backend.Pakfire(config_file=config_file)
 
                return self.__pakfire
 
index 4a6bd8993cdc2560bd9e18d01dc21f65ae2416b8..956f9c53a804070aed3fa92edab3de1a6a1eaff9 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/bin/python
 
 import logging
+import os.path
 import time
 import tornado.ioloop
 import tornado.options
@@ -10,13 +11,16 @@ from backend.managers import *
 
 tornado.options.parse_command_line()
 
+BASEDIR = os.path.dirname(__file__)
+
 class Daemon(object):
        def __init__(self):
                self._managers = []
 
                self.ioloop.set_blocking_log_threshold(300)
 
-               self.pakfire = backend.Pakfire()
+               config_file = os.path.join(BASEDIR, "pbs.conf")
+               self.pakfire = backend.Pakfire(config_file=config_file)
 
        @property
        def ioloop(self):
diff --git a/pbs.conf.example b/pbs.conf.example
new file mode 100644 (file)
index 0000000..373cbd2
--- /dev/null
@@ -0,0 +1,15 @@
+[database]
+; Credentials to the pakfire build service database.
+
+host  = mysql-master.ipfire.org
+user  = pakfire
+pass  = pakfire
+db    = pakfire
+
+[geoip-database]
+; Credentials to the geoip database.
+
+host  = mysql-master.ipfire.org
+user  = pakfire
+pass  = pakfire
+db    = geoip
index f298500db912351d70746662f570bbbcc6abc547..b3d6d952a4e185ef6d4c358e28ac9673336bf19c 100644 (file)
@@ -226,7 +226,9 @@ class Application(tornado.web.Application):
        @property
        def pakfire(self):
                if self.__pakfire is None:
-                       self.__pakfire = backend.Pakfire()
+                       config_file = os.path.join(BASEDIR, "..", "pbs.conf")
+
+                       self.__pakfire = backend.Pakfire(config_file=config_file)
 
                return self.__pakfire