]>
git.ipfire.org Git - people/jschlag/pbs.git/blob - src/buildservice/__init__.py
3 from __future__
import absolute_import
11 from . import bugtracker
12 from . import builders
15 from . import database
16 from . import distribution
18 from . import jobqueue
22 from . import messages
24 from . import packages
25 from . import repository
26 from . import settings
27 from . import sessions
33 log
= logging
.getLogger("backend")
37 from .__version
__ import VERSION
as __version__
39 from .decorators
import *
40 from .constants
import *
42 class Backend(object):
43 def __init__(self
, config_file
=None):
44 # Read configuration file.
45 self
.config
= self
.read_config(config_file
)
47 # Global pakfire settings (from database).
48 self
.settings
= settings
.Settings(self
)
50 self
.arches
= arches
.Arches(self
)
51 self
.builds
= builds
.Builds(self
)
52 self
.cache
= cache
.Cache(self
)
53 self
.geoip
= geoip
.GeoIP(self
)
54 self
.jobs
= jobs
.Jobs(self
)
55 self
.builders
= builders
.Builders(self
)
56 self
.distros
= distribution
.Distributions(self
)
57 self
.jobqueue
= jobqueue
.JobQueue(self
)
58 self
.keys
= keys
.Keys(self
)
59 self
.messages
= messages
.Messages(self
)
60 self
.mirrors
= mirrors
.Mirrors(self
)
61 self
.packages
= packages
.Packages(self
)
62 self
.repos
= repository
.Repositories(self
)
63 self
.sessions
= sessions
.Sessions(self
)
64 self
.sources
= sources
.Sources(self
)
65 self
.updates
= updates
.Updates(self
)
66 self
.uploads
= uploads
.Uploads(self
)
67 self
.users
= users
.Users(self
)
69 # Open a connection to bugzilla.
70 self
.bugzilla
= bugtracker
.Bugzilla(self
)
72 # A pool to store strings (for comparison).
73 self
.pool
= pakfire
.satsolver
.Pool("dummy")
76 def _environment_configuration(self
):
79 # Get database configuration
81 "name" : os
.environ
.get("PBS_DATABASE_NAME"),
82 "hostname" : os
.environ
.get("PBS_DATABASE_HOSTNAME"),
83 "user" : os
.environ
.get("PBS_DATABASE_USER"),
84 "password" : os
.environ
.get("PBS_DATABASE_PASSWORD"),
89 def read_config(self
, path
):
90 c
= ConfigParser
.SafeConfigParser()
92 # Import configuration from environment
93 for section
in self
._environment
_configuration
:
94 c
.add_section(section
)
96 for k
in self
._environment
_configuration
[section
]:
97 c
.set(section
, k
, self
._environment
_configuration
[section
][k
] or "")
99 # Load default configuration file first
101 os
.path
.join(CONFIGSDIR
, "pbs.conf"),
107 # Load all configuration files
109 if os
.path
.exists(path
):
110 log
.debug("Loading configuration from %s" % path
)
113 log
.error("No such file %s" % path
)
120 name
= self
.config
.get("database", "name")
121 hostname
= self
.config
.get("database", "hostname")
122 user
= self
.config
.get("database", "user")
123 password
= self
.config
.get("database", "password")
124 except ConfigParser
.Error
as e
:
125 log
.error("Error parsing the config: %s" % e
.message
)
127 log
.debug("Connecting to database %s @ %s" % (name
, hostname
))
129 return database
.Connection(hostname
, name
, user
=user
, password
=password
)
131 def cleanup_files(self
):
132 query
= self
.db
.query("SELECT * FROM queue_delete")
138 path
= os
.path
.join(PACKAGES_DIR
, row
.path
)
141 logging
.debug("Removing %s..." % path
)
144 logging
.error("Could not remove %s: %s" % (path
, e
))
147 path
= os
.path
.dirname(path
)
149 # Stop if we are running outside of the tree.
150 if not path
.startswith(PACKAGES_DIR
):
153 # If the directory is not empty, we cannot remove it.
154 if os
.path
.exists(path
) and os
.listdir(path
):
158 logging
.debug("Removing %s..." % path
)
161 logging
.error("Could not remove %s: %s" % (path
, e
))
164 self
.db
.execute("DELETE FROM queue_delete WHERE id = %s", row
.id)