###############################################################################
from .constants import PAKFIRE_VERSION as __version__
+from .logger import setup_logging
-# Initialize logging as soon as the module is loaded
-from . import logger
-log = logger.setup_logging()
-
-from . import base
-
-Pakfire = base.Pakfire
-PakfireBuilder = base.PakfireBuilder
-PakfireServer = base.PakfireServer
-
-# Log when loaded
+log = setup_logging()
log.debug("Pakfire %s initialised" % __version__)
+
+from .base import Pakfire, PakfireBuilder, PakfireServer
import configparser
import io
+import logging
import os
import socket
-import logging
-log = logging.getLogger("pakfire")
+log = logging.getLogger("pakfire.config")
+log.propagate = 1
-from . import logger
from .system import system
from .constants import *
from .i18n import _
+class Config(object):
+ def __init__(self, *files):
+ self._config = configparser.ConfigParser(
+ interpolation=configparser.ExtendedInterpolation()
+ )
+
+ # Read any passed configuration files
+ for f in files:
+ self.read(f)
+
+ def read(self, path):
+ """
+ Reads configuration from the given file
+ """
+ if not path.startswith("/"):
+ path = os.path.join(CONFIG_DIR, path)
+
+ log.debug("Reading configuration from %s" % path)
+
+ with open(path) as f:
+ self._config.readfp(f)
+
+ def get(self, section, option, default=None):
+ return self._config.get(section, option, fallback=default)
+
+ def get_bool(self, section, option, default=None):
+ return self._config.getboolean(section, option, fallback=default)
+
+ def dump(self):
+ """
+ Dump the configuration that was read
+
+ (Only in debugging mode)
+ """
+ log.debug(_("Configuration:"))
+
+ for section in self._config.sections():
+ log.debug(" " + _("Section: %s") % section)
+
+ for option in self._config[section]:
+ value = self.get(section, option)
+
+ log.debug(" %-20s: %s" % (option, value))
+
+
+# Read initial configuration
+config = Config("general.conf")
+
class _Config(object):
files = []
except KeyError:
self._config[section] = items
- # Update the logger, because the logging configuration may
- # have been altered.
- logger.setup_logging(self)
-
def set(self, section, key, value):
try:
self._config[section][key] = value
return self.get_section("distro")
-class Config(_Config):
- files = ["general.conf", "distro.conf"]
-
-
class ConfigBuilder(_Config):
files = ["general.conf", "builder.conf"]
import logging
import logging.handlers
-def setup_logging(debug=False):
+from .config import config
+
+def setup_logging(debug=None):
"""
This function initialized the logger that is enabled immediately
"""
+ # If debug is None, we read it from the configuration
+ if debug is None:
+ debug = config.get_bool("log", "debug", False)
+
l = logging.getLogger("pakfire")
l.propagate = 0