]>
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
21 from . import messages
23 from . import packages
24 from . import repository
25 from . import settings
26 from . import sessions
32 log
= logging
.getLogger("backend")
36 from .__version
__ import VERSION
as __version__
38 from .decorators
import *
39 from .constants
import *
41 class Backend(object):
42 def __init__(self
, config_file
=None):
43 # Read configuration file.
44 self
.config
= self
.read_config(config_file
)
46 # Global pakfire settings (from database).
47 self
.settings
= settings
.Settings(self
)
49 self
.arches
= arches
.Arches(self
)
50 self
.builds
= builds
.Builds(self
)
51 self
.cache
= cache
.Cache(self
)
52 self
.geoip
= geoip
.GeoIP(self
)
53 self
.jobs
= builds
.Jobs(self
)
54 self
.builders
= builders
.Builders(self
)
55 self
.distros
= distribution
.Distributions(self
)
56 self
.jobqueue
= jobqueue
.JobQueue(self
)
57 self
.keys
= keys
.Keys(self
)
58 self
.messages
= messages
.Messages(self
)
59 self
.mirrors
= mirrors
.Mirrors(self
)
60 self
.packages
= packages
.Packages(self
)
61 self
.repos
= repository
.Repositories(self
)
62 self
.sessions
= sessions
.Sessions(self
)
63 self
.sources
= sources
.Sources(self
)
64 self
.updates
= updates
.Updates(self
)
65 self
.uploads
= uploads
.Uploads(self
)
66 self
.users
= users
.Users(self
)
68 # Open a connection to bugzilla.
69 self
.bugzilla
= bugtracker
.Bugzilla(self
)
71 # A pool to store strings (for comparison).
72 self
.pool
= pakfire
.satsolver
.Pool("dummy")
74 def read_config(self
, path
):
75 c
= ConfigParser
.SafeConfigParser()
77 c
.add_section("database")
78 c
.set("database", "name", os
.environ
.get("PBS_DATABASE_NAME"))
79 c
.set("database", "hostname", os
.environ
.get("PBS_DATABASE_HOSTNAME"))
80 c
.set("database", "user", os
.environ
.get("PBS_DATABASE_USER"))
81 c
.set("database", "password", os
.environ
.get("PBS_DATABASE_PASSWORD"))
83 # Load default configuration file first
85 os
.path
.join(CONFIGSDIR
, "pbs.conf"),
91 # Load all configuration files
93 if os
.path
.exists(path
):
94 log
.debug("Loading configuration from %s" % path
)
97 log
.error("No such file %s" % path
)
104 name
= self
.config
.get("database", "name")
105 hostname
= self
.config
.get("database", "hostname")
106 user
= self
.config
.get("database", "user")
107 password
= self
.config
.get("database", "password")
108 except ConfigParser
.Error
as e
:
109 log
.error("Error parsing the config: %s" % e
.message
)
111 log
.debug("Connecting to database %s @ %s" % (name
, hostname
))
113 return database
.Connection(hostname
, name
, user
=user
, password
=password
)
115 def cleanup_files(self
):
116 query
= self
.db
.query("SELECT * FROM queue_delete")
122 path
= os
.path
.join(PACKAGES_DIR
, row
.path
)
125 logging
.debug("Removing %s..." % path
)
128 logging
.error("Could not remove %s: %s" % (path
, e
))
131 path
= os
.path
.dirname(path
)
133 # Stop if we are running outside of the tree.
134 if not path
.startswith(PACKAGES_DIR
):
137 # If the directory is not empty, we cannot remove it.
138 if os
.path
.exists(path
) and os
.listdir(path
):
142 logging
.debug("Removing %s..." % path
)
145 logging
.error("Could not remove %s: %s" % (path
, e
))
148 self
.db
.execute("DELETE FROM queue_delete WHERE id = %s", row
.id)