]>
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
20 from . import messages
22 from . import packages
23 from . import repository
24 from . import settings
25 from . import sessions
31 log
= logging
.getLogger("backend")
35 from .__version
__ import VERSION
as __version__
37 from .decorators
import *
38 from .constants
import *
40 class Backend(object):
41 def __init__(self
, config_file
=None):
42 # Read configuration file.
43 self
.config
= self
.read_config(config_file
)
45 # Global pakfire settings (from database).
46 self
.settings
= settings
.Settings(self
)
48 self
.arches
= arches
.Arches(self
)
49 self
.builds
= builds
.Builds(self
)
50 self
.cache
= cache
.Cache(self
)
51 self
.geoip
= geoip
.GeoIP(self
)
52 self
.jobs
= builds
.Jobs(self
)
53 self
.builders
= builders
.Builders(self
)
54 self
.distros
= distribution
.Distributions(self
)
55 self
.keys
= keys
.Keys(self
)
56 self
.messages
= messages
.Messages(self
)
57 self
.mirrors
= mirrors
.Mirrors(self
)
58 self
.packages
= packages
.Packages(self
)
59 self
.repos
= repository
.Repositories(self
)
60 self
.sessions
= sessions
.Sessions(self
)
61 self
.sources
= sources
.Sources(self
)
62 self
.updates
= updates
.Updates(self
)
63 self
.uploads
= uploads
.Uploads(self
)
64 self
.users
= users
.Users(self
)
66 # Open a connection to bugzilla.
67 self
.bugzilla
= bugtracker
.Bugzilla(self
)
69 # A pool to store strings (for comparison).
70 self
.pool
= pakfire
.satsolver
.Pool("dummy")
72 def read_config(self
, path
):
73 c
= ConfigParser
.SafeConfigParser()
75 # Load default configuration file first
77 os
.path
.join(CONFIGSDIR
, "pbs.conf"),
83 # Load all configuration files
85 log
.debug("Loading configuration from %s" % path
)
92 name
= self
.config
.get("database", "name")
93 hostname
= self
.config
.get("database", "hostname")
94 user
= self
.config
.get("database", "user")
95 password
= self
.config
.get("database", "password")
97 log
.debug("Connecting to database %s @ %s" % (name
, hostname
))
99 return database
.Connection(hostname
, name
, user
=user
, password
=password
)
101 def cleanup_files(self
):
102 query
= self
.db
.query("SELECT * FROM queue_delete")
108 path
= os
.path
.join(PACKAGES_DIR
, row
.path
)
111 logging
.debug("Removing %s..." % path
)
114 logging
.error("Could not remove %s: %s" % (path
, e
))
117 path
= os
.path
.dirname(path
)
119 # Stop if we are running outside of the tree.
120 if not path
.startswith(PACKAGES_DIR
):
123 # If the directory is not empty, we cannot remove it.
124 if os
.path
.exists(path
) and os
.listdir(path
):
128 logging
.debug("Removing %s..." % path
)
131 logging
.error("Could not remove %s: %s" % (path
, e
))
134 self
.db
.execute("DELETE FROM queue_delete WHERE id = %s", row
.id)