]> git.ipfire.org Git - people/jschlag/pbs.git/blobdiff - src/buildservice/__init__.py
Redesign mastering repositories
[people/jschlag/pbs.git] / src / buildservice / __init__.py
index 424bdb2fb5e3e9cb3cef3b44227ca22b11dc61ae..b40527d89c25f5454a86626f3e5da594720482b6 100644 (file)
@@ -15,6 +15,8 @@ from . import cache
 from . import database
 from . import distribution
 from . import geoip
+from . import jobqueue
+from . import jobs
 from . import keys
 from . import logs
 from . import messages
@@ -49,9 +51,10 @@ class Backend(object):
                self.builds      = builds.Builds(self)
                self.cache       = cache.Cache(self)
                self.geoip       = geoip.GeoIP(self)
-               self.jobs        = builds.Jobs(self)
+               self.jobs        = jobs.Jobs(self)
                self.builders    = builders.Builders(self)
                self.distros     = distribution.Distributions(self)
+               self.jobqueue    = jobqueue.JobQueue(self)
                self.keys        = keys.Keys(self)
                self.messages    = messages.Messages(self)
                self.mirrors     = mirrors.Mirrors(self)
@@ -69,9 +72,30 @@ class Backend(object):
                # A pool to store strings (for comparison).
                self.pool        = pakfire.satsolver.Pool("dummy")
 
+       @lazy_property
+       def _environment_configuration(self):
+               env = {}
+
+               # Get database configuration
+               env["database"] = {
+                       "name"     : os.environ.get("PBS_DATABASE_NAME"),
+                       "hostname" : os.environ.get("PBS_DATABASE_HOSTNAME"),
+                       "user"     : os.environ.get("PBS_DATABASE_USER"),
+                       "password" : os.environ.get("PBS_DATABASE_PASSWORD"),
+               }
+
+               return env
+
        def read_config(self, path):
                c = ConfigParser.SafeConfigParser()
 
+               # Import configuration from environment
+               for section in self._environment_configuration:
+                       c.add_section(section)
+
+                       for k in self._environment_configuration[section]:
+                               c.set(section, k, self._environment_configuration[section][k] or "")
+
                # Load default configuration file first
                paths = [
                        os.path.join(CONFIGSDIR, "pbs.conf"),
@@ -82,30 +106,43 @@ class Backend(object):
 
                # Load all configuration files
                for path in paths:
-                       log.debug("Loading configuration from %s" % path)
-                       c.read(path)
+                       if os.path.exists(path):
+                               log.debug("Loading configuration from %s" % path)
+                               c.read(path)
+                       else:
+                               log.error("No such file %s" % path)
 
                return c
 
        @lazy_property
        def db(self):
-               name     = self.config.get("database", "name")
-               hostname = self.config.get("database", "hostname")
-               user     = self.config.get("database", "user")
-               password = self.config.get("database", "password")
+               try:
+                       name     = self.config.get("database", "name")
+                       hostname = self.config.get("database", "hostname")
+                       user     = self.config.get("database", "user")
+                       password = self.config.get("database", "password")
+               except ConfigParser.Error as e:
+                       log.error("Error parsing the config: %s" % e.message)
 
                log.debug("Connecting to database %s @ %s" % (name, hostname))
 
                return database.Connection(hostname, name, user=user, password=password)
 
+       def delete_file(self, path, not_before=None):
+               self.db.execute("INSERT INTO queue_delete(path, not_before) \
+                       VALUES(%s, %s)", path, not_before)
+
        def cleanup_files(self):
-               query = self.db.query("SELECT * FROM queue_delete")
+               query = self.db.query("SELECT * FROM queue_delete \
+                       WHERE (not_before IS NULL OR not_before <= NOW())")
 
                for row in query:
                        if not row.path:
                                continue
 
-                       path = os.path.join(PACKAGES_DIR, row.path)
+                       path = row.path
+                       if not path.startswith("/"):
+                               path = os.path.join(PACKAGES_DIR, path)
 
                        try:
                                logging.debug("Removing %s..." % path)