From: Michael Tremer Date: Fri, 6 Oct 2017 14:18:17 +0000 (+0100) Subject: Move main.py to __init__.py X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=085af6d49622cd010b0beafdc70c0127085cbbff;p=pbs.git Move main.py to __init__.py There is no need for an extra file like this Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 89842ed2..64494a30 100644 --- a/Makefile.am +++ b/Makefile.am @@ -84,7 +84,6 @@ buildservice_PYTHON = \ src/buildservice/__init__.py \ src/buildservice/keys.py \ src/buildservice/logs.py \ - src/buildservice/main.py \ src/buildservice/messages.py \ src/buildservice/mirrors.py \ src/buildservice/misc.py \ diff --git a/src/buildservice/__init__.py b/src/buildservice/__init__.py index e8b8fe84..00cf507e 100644 --- a/src/buildservice/__init__.py +++ b/src/buildservice/__init__.py @@ -1,3 +1,122 @@ #!/usr/bin/python -from main import Pakfire +import ConfigParser +import logging +import os +import pakfire + +from . import arches +from . import bugtracker +from . import builders +from . import builds +from . import cache +from . import database +from . import distribution +from . import keys +from . import logs +from . import messages +from . import mirrors +from . import packages +from . import repository +from . import settings +from . import sessions +from . import sources +from . import updates +from . import uploads +from . import users + +from .constants import * + +class Pakfire(object): + def __init__(self, config_file="pbs.conf"): + # Read configuration file. + self.config = self.read_config(config_file) + + # Connect to databases. + self.db = self.connect_database() + self.geoip_db = self.connect_database("geoip-database") + + # Global pakfire settings (from database). + self.settings = settings.Settings(self) + + self.arches = arches.Arches(self) + self.builds = builds.Builds(self) + self.cache = cache.Cache(self) + self.geoip = mirrors.GeoIP(self) + self.jobs = builds.Jobs(self) + self.builders = builders.Builders(self) + self.distros = distribution.Distributions(self) + self.keys = keys.Keys(self) + self.messages = messages.Messages(self) + self.mirrors = mirrors.Mirrors(self) + self.packages = packages.Packages(self) + self.repos = repository.Repositories(self) + self.sessions = sessions.Sessions(self) + self.sources = sources.Sources(self) + self.updates = updates.Updates(self) + self.uploads = uploads.Uploads(self) + self.users = users.Users(self) + + # Open a connection to bugzilla. + self.bugzilla = bugtracker.Bugzilla(self) + + # A pool to store strings (for comparison). + self.pool = pakfire.satsolver.Pool("dummy") + + def __del__(self): + if self.db: + self.db.close() + del self.db + + def read_config(self, path): + c = ConfigParser.SafeConfigParser() + c.read(path) + + return c + + def connect_database(self, section="database"): + db = self.config.get(section, "db") + host = self.config.get(section, "host") + user = self.config.get(section, "user") + + if self.config.has_option(section, "pass"): + pw = self.config.get(section, "pass") + else: + pw = None + + return database.Connection(host, db, user=user, password=pw) + + def cleanup_files(self): + query = self.db.query("SELECT * FROM queue_delete") + + for row in query: + if not row.path: + continue + + path = os.path.join(PACKAGES_DIR, row.path) + + try: + logging.debug("Removing %s..." % path) + os.unlink(path) + except OSError, e: + logging.error("Could not remove %s: %s" % (path, e)) + + while True: + path = os.path.dirname(path) + + # Stop if we are running outside of the tree. + if not path.startswith(PACKAGES_DIR): + break + + # If the directory is not empty, we cannot remove it. + if os.path.exists(path) and os.listdir(path): + break + + try: + logging.debug("Removing %s..." % path) + os.rmdir(path) + except OSError, e: + logging.error("Could not remove %s: %s" % (path, e)) + break + + self.db.execute("DELETE FROM queue_delete WHERE id = %s", row.id) diff --git a/src/buildservice/main.py b/src/buildservice/main.py deleted file mode 100644 index e27e5cca..00000000 --- a/src/buildservice/main.py +++ /dev/null @@ -1,122 +0,0 @@ -#!/usr/bin/python - -import ConfigParser -import logging -import os -import pakfire - -import arches -import bugtracker -import builders -import builds -import cache -import database -import distribution -import keys -import logs -import messages -import mirrors -import packages -import repository -import settings -import sessions -import sources -import updates -import uploads -import users - -from constants import * - -class Pakfire(object): - def __init__(self, config_file="pbs.conf"): - # Read configuration file. - self.config = self.read_config(config_file) - - # Connect to databases. - self.db = self.connect_database() - self.geoip_db = self.connect_database("geoip-database") - - # Global pakfire settings (from database). - self.settings = settings.Settings(self) - - self.arches = arches.Arches(self) - self.builds = builds.Builds(self) - self.cache = cache.Cache(self) - self.geoip = mirrors.GeoIP(self) - self.jobs = builds.Jobs(self) - self.builders = builders.Builders(self) - self.distros = distribution.Distributions(self) - self.keys = keys.Keys(self) - self.messages = messages.Messages(self) - self.mirrors = mirrors.Mirrors(self) - self.packages = packages.Packages(self) - self.repos = repository.Repositories(self) - self.sessions = sessions.Sessions(self) - self.sources = sources.Sources(self) - self.updates = updates.Updates(self) - self.uploads = uploads.Uploads(self) - self.users = users.Users(self) - - # Open a connection to bugzilla. - self.bugzilla = bugtracker.Bugzilla(self) - - # A pool to store strings (for comparison). - self.pool = pakfire.satsolver.Pool("dummy") - - def __del__(self): - if self.db: - self.db.close() - del self.db - - def read_config(self, path): - c = ConfigParser.SafeConfigParser() - c.read(path) - - return c - - def connect_database(self, section="database"): - db = self.config.get(section, "db") - host = self.config.get(section, "host") - user = self.config.get(section, "user") - - if self.config.has_option(section, "pass"): - pw = self.config.get(section, "pass") - else: - pw = None - - return database.Connection(host, db, user=user, password=pw) - - def cleanup_files(self): - query = self.db.query("SELECT * FROM queue_delete") - - for row in query: - if not row.path: - continue - - path = os.path.join(PACKAGES_DIR, row.path) - - try: - logging.debug("Removing %s..." % path) - os.unlink(path) - except OSError, e: - logging.error("Could not remove %s: %s" % (path, e)) - - while True: - path = os.path.dirname(path) - - # Stop if we are running outside of the tree. - if not path.startswith(PACKAGES_DIR): - break - - # If the directory is not empty, we cannot remove it. - if os.path.exists(path) and os.listdir(path): - break - - try: - logging.debug("Removing %s..." % path) - os.rmdir(path) - except OSError, e: - logging.error("Could not remove %s: %s" % (path, e)) - break - - self.db.execute("DELETE FROM queue_delete WHERE id = %s", row.id)