from . import database
from . import distribution
from . import geoip
+from . import jobqueue
+from . import jobs
from . import keys
from . import logs
from . import messages
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)
# 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"),
# 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)