]>
git.ipfire.org Git - people/jschlag/pbs.git/blob - src/buildservice/__init__.py
3 from __future__
import absolute_import
12 from . import bugtracker
13 from . import builders
16 from . import database
17 from . import distribution
19 from . import jobqueue
23 from . import messages
25 from . import packages
26 from . import repository
27 from . import settings
28 from . import sessions
34 log
= logging
.getLogger("backend")
38 from .__version
__ import VERSION
as __version__
40 from .decorators
import *
41 from .constants
import *
43 class Backend(object):
44 def __init__(self
, config_file
=None):
45 # Read configuration file.
46 self
.config
= self
.read_config(config_file
)
48 # Global pakfire settings (from database).
49 self
.settings
= settings
.Settings(self
)
51 self
.arches
= arches
.Arches(self
)
52 self
.builds
= builds
.Builds(self
)
53 self
.cache
= cache
.Cache(self
)
54 self
.geoip
= geoip
.GeoIP(self
)
55 self
.jobs
= jobs
.Jobs(self
)
56 self
.builders
= builders
.Builders(self
)
57 self
.distros
= distribution
.Distributions(self
)
58 self
.jobqueue
= jobqueue
.JobQueue(self
)
59 self
.keys
= keys
.Keys(self
)
60 self
.messages
= messages
.Messages(self
)
61 self
.mirrors
= mirrors
.Mirrors(self
)
62 self
.packages
= packages
.Packages(self
)
63 self
.repos
= repository
.Repositories(self
)
64 self
.sessions
= sessions
.Sessions(self
)
65 self
.sources
= sources
.Sources(self
)
66 self
.updates
= updates
.Updates(self
)
67 self
.uploads
= uploads
.Uploads(self
)
68 self
.users
= users
.Users(self
)
70 # Open a connection to bugzilla.
71 self
.bugzilla
= bugtracker
.Bugzilla(self
)
73 # A pool to store strings (for comparison).
74 self
.pool
= pakfire
.satsolver
.Pool("dummy")
77 def _environment_configuration(self
):
80 # Get database configuration
82 "name" : os
.environ
.get("PBS_DATABASE_NAME"),
83 "hostname" : os
.environ
.get("PBS_DATABASE_HOSTNAME"),
84 "user" : os
.environ
.get("PBS_DATABASE_USER"),
85 "password" : os
.environ
.get("PBS_DATABASE_PASSWORD"),
90 def read_config(self
, path
):
91 c
= ConfigParser
.SafeConfigParser()
93 # Import configuration from environment
94 for section
in self
._environment
_configuration
:
95 c
.add_section(section
)
97 for k
in self
._environment
_configuration
[section
]:
98 c
.set(section
, k
, self
._environment
_configuration
[section
][k
] or "")
100 # Load default configuration file first
102 os
.path
.join(CONFIGSDIR
, "pbs.conf"),
108 # Load all configuration files
110 if os
.path
.exists(path
):
111 log
.debug("Loading configuration from %s" % path
)
114 log
.error("No such file %s" % path
)
121 name
= self
.config
.get("database", "name")
122 hostname
= self
.config
.get("database", "hostname")
123 user
= self
.config
.get("database", "user")
124 password
= self
.config
.get("database", "password")
125 except ConfigParser
.Error
as e
:
126 log
.error("Error parsing the config: %s" % e
.message
)
128 log
.debug("Connecting to database %s @ %s" % (name
, hostname
))
130 return database
.Connection(hostname
, name
, user
=user
, password
=password
)
132 def delete_file(self
, path
, not_before
=None):
133 self
.db
.execute("INSERT INTO queue_delete(path, not_before) \
134 VALUES(%s, %s)", path
, not_before
)
136 def cleanup_files(self
):
137 query
= self
.db
.query("SELECT * FROM queue_delete \
138 WHERE (not_before IS NULL OR not_before <= NOW())")
143 if not path
or not paths
.startswith("%s/" % PAKFIRE_DIR
):
144 log
.warning("Cannot delete file outside of the tree")
148 logging
.debug("Removing %s..." % path
)
150 except shutil
.Error
as e
:
151 logging
.error("Could not remove %s: %s" % (path
, e
))
154 self
.db
.execute("DELETE FROM queue_delete WHERE id = %s", row
.id)