#include <solv/repo.h>
+#include <pakfire/config.h>
#include <pakfire/downloader.h>
+int pakfire_repo_import(Pakfire pakfire, struct pakfire_config* config);
+
Id pakfire_repo_add_solvable(PakfireRepo repo);
PakfireRepo pakfire_repo_create_from_repo(Pakfire pakfire, Repo* r);
if (r)
goto ERROR;
+ // Create repositories
+ r = pakfire_repo_import(p, p->config);
+ if (r)
+ goto ERROR;
+
*pakfire = p;
return 0;
#include <pakfire/archive.h>
#include <pakfire/compress.h>
+#include <pakfire/config.h>
#include <pakfire/constants.h>
#include <pakfire/downloader.h>
#include <pakfire/file.h>
struct pakfire_downloader* downloader;
};
+int pakfire_repo_import(Pakfire pakfire, struct pakfire_config* config) {
+ char** sections = pakfire_config_sections(config);
+
+ // The configuration seems to be empty
+ if (!sections)
+ return 0;
+
+ int r = 0;
+
+ // Walk through all sections
+ for (char** section = sections; *section; section++) {
+ // Skip sections that do not start with "repo:"
+ if (!pakfire_string_startswith(*section, "repo:"))
+ continue;
+
+ const char* name = (*section) + strlen("repo:");
+ if (!*name)
+ continue;
+
+ DEBUG(pakfire, "Creating repository %s\n", name);
+
+ // Create a new repository
+ PakfireRepo repo = pakfire_repo_create(pakfire, name);
+ if (!repo) {
+ ERROR(pakfire, "Could not create repository '%s': %s\n", name, strerror(errno));
+ r = 1;
+ goto ERROR;
+ }
+
+ // Enabled
+ int enabled = pakfire_config_get_bool(config, *section, "enabled", 1);
+ pakfire_repo_set_enabled(repo, enabled);
+
+ // Priority
+ int priority = pakfire_config_get_int(config, *section, "priority", 0);
+ if (priority)
+ pakfire_repo_set_priority(repo, priority);
+
+ // Description
+ const char* description = pakfire_config_get(config, *section, "description", NULL);
+ if (description)
+ pakfire_repo_set_description(repo, description);
+
+ // baseurl
+ const char* baseurl = pakfire_config_get(config, *section, "baseurl", NULL);
+ if (baseurl)
+ pakfire_repo_set_baseurl(repo, baseurl);
+
+ // mirrors
+ const char* mirrors = pakfire_config_get(config, *section, "mirrors", NULL);
+ if (mirrors)
+ pakfire_repo_set_mirrorlist_url(repo, mirrors);
+
+ pakfire_repo_unref(repo);
+ }
+
+ERROR:
+ for (char** section = sections; *section; section++)
+ free(*section);
+ free(sections);
+
+ return r;
+}
+
Id pakfire_repo_add_solvable(PakfireRepo repo) {
return repo_add_solvable(repo->repo);
}
self.repos = repository.Repositories(self)
- # Load default repository configuration
- repos_dir = self.make_path(CONFIG_REPOS_DIR)
- if repos_dir:
- self.repos.load_configuration(repos_dir)
-
def _setup_logger(self):
log = logging.getLogger("pakfire")
log.propagate = 0
SYSCONFDIR = "/etc"
CONFIG_DIR = os.path.join(SYSCONFDIR, "pakfire")
-CONFIG_REPOS_DIR = os.path.join(CONFIG_DIR, "repos")
CONFIG_DISTRO_DIR = os.path.join(CONFIG_DIR, "distros")
CACHE_DIR = "/var/cache/pakfire"
# #
###############################################################################
-import glob
-import os
-import re
-
import logging
log = logging.getLogger("pakfire")
-from .. import _pakfire
-from .. import config
-
-from ..i18n import _
-
class Repositories(object):
"""
Class that loads all repositories from the configuration files.
# Place to store the repositories
self.__repos = {}
- self._load_from_configuration(self.pakfire.config)
-
def __iter__(self):
repositories = list(self.__repos.values())
repositories.sort()
def distro(self):
return self.pakfire.distro
- def load_configuration(self, *paths):
- c = config.Config()
-
- for path in paths:
- # Read directories
- if os.path.isdir(path):
- for file in glob.glob("%s/*.repo" % path):
- c.read(file)
-
- # Read files
- else:
- c.read(path)
-
- self._load_from_configuration(c)
-
- def _load_from_configuration(self, config):
- # Add all repositories that have been found
- for name, settings in config.get_repos():
- self._parse(name, settings)
-
- def _parse(self, name, args):
- _args = {
- "name" : name,
- "enabled" : True,
- "gpgkey" : None,
- "mirrors" : None,
- }
- _args.update(args)
-
- # Handle variable expansion.
- replaces = {
- "name" : name,
- "arch" : "%s" % self.pakfire.arch,
- }
-
- for k, v in list(_args.items()):
- # Skip all non-strings.
- if not type(v) == type("a"):
- continue
-
- while True:
- m = re.search(r"\%\{([A-Za-z0-9_\-]+)\}", v)
-
- # If we cannot find a match, we are done.
- if not m:
- _args[k] = v
- break
-
- # Get the name of the variable.
- (var,) = m.groups()
-
- # Replace the variable with its value.
- v = v.replace("%%{%s}" % var, replaces.get(var, ""))
-
- repo = _pakfire.Repo(self.pakfire, name)
- repo.enabled = _args.get("enabled", True)
- repo.description = _args.get("description", None)
- repo.baseurl = _args.get("baseurl", None)
- repo.keyfile = _args.get("gpgkey", None)
- repo.mirrorlist = _args.get("mirrors", None)
-
- self.add_repo(repo)
-
- def add_repo(self, repo):
- if repo.name in self.__repos:
- raise Exception("Repository with that name does already exist: %s" % repo.name)
-
- self.__repos[repo.name] = repo
-
- def rem_repo(self, repo):
- """
- Remove the given repository from the global repository set.
- """
- try:
- del self.__repos[repo.name]
- except KeyError:
- log.debug("Repository that was to be removed does not exist: %s" % repo.name)
-
def get_repo(self, name):
"""
Get the repository with the given name, if not available, return
try:
return self.__repos[name]
except KeyError:
- return self.dummy
+ pass
def clean(self):
log.info("Cleaning up all repository caches...")