]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: Move Repository.get_config function into C library
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 22 Jan 2018 17:52:03 +0000 (18:52 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 22 Jan 2018 17:52:03 +0000 (18:52 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/repo.c
src/libpakfire/include/pakfire/repo.h
src/libpakfire/libpakfire.sym
src/libpakfire/repo.c
src/pakfire/repository/base.py
src/pakfire/repository/remote.py

index 659f7e37d69ab2aae1397b3970a9b643305a735f..dd4266d68f8aea400b121dfc4fd003a33afec408 100644 (file)
@@ -189,6 +189,19 @@ static int Repo_set_mirrorlist(RepoObject* self, PyObject* value) {
        return pakfire_repo_set_mirrorlist(self->repo, mirrorlist);
 }
 
+static PyObject* Repo_get_config(RepoObject* self) {
+       char* config = pakfire_repo_get_config(self->repo);
+
+       if (config) {
+               PyObject* obj = PyUnicode_FromString(config);
+               pakfire_free(config);
+
+               return obj;
+       }
+
+       Py_RETURN_NONE;
+}
+
 static PyObject* Repo_read_solv(RepoObject* self, PyObject* args) {
        const char* filename = NULL;
 
@@ -370,6 +383,12 @@ static struct PyMethodDef Repo_methods[] = {
                METH_VARARGS,
                NULL,
        },
+       {
+               "get_config",
+               (PyCFunction)Repo_get_config,
+               METH_NOARGS,
+               NULL,
+       },
        {
                "read_solv",
                (PyCFunction)Repo_read_solv,
index 30050d1505ec6733c4e67af2eeaab74928c69a2d..8fde3e1f3b7bed4d8c92d19532aae5cd9b620b6a 100644 (file)
@@ -56,6 +56,8 @@ int pakfire_repo_set_keyfile(PakfireRepo repo, const char* keyfile);
 const char* pakfire_repo_get_mirrorlist(PakfireRepo repo);
 int pakfire_repo_set_mirrorlist(PakfireRepo repo, const char* mirrorlist);
 
+char* pakfire_repo_get_config(PakfireRepo repo);
+
 int pakfire_repo_is_installed_repo(PakfireRepo repo);
 
 int pakfire_repo_read_solv(PakfireRepo repo, const char* filename, int flags);
index 8dba79580d30fdfbe87112b8d7239862bb659ab4..bd64a7a7db536cefd8960c14dcbabcbb9b6d379f 100644 (file)
@@ -227,6 +227,7 @@ global:
        pakfire_repo_create;
        pakfire_repo_get_baseurl;
        pakfire_repo_get_cache;
+       pakfire_repo_get_config;
        pakfire_repo_get_name;
        pakfire_repo_get_enabled;
        pakfire_repo_get_keyfile;
index 4468abf98ff411bbb068e65152b3b6b44742098f..f58380fd6e3719517d16231445b4d1f1d1986b17 100644 (file)
@@ -301,6 +301,40 @@ PAKFIRE_EXPORT int pakfire_repo_set_mirrorlist(PakfireRepo repo, const char* mir
        return 0;
 }
 
+PAKFIRE_EXPORT char* pakfire_repo_get_config(PakfireRepo repo) {
+       if (pakfire_repo_is_installed_repo(repo) == 0)
+               return NULL;
+
+       char buffer[1024 * 4];
+       char* p = buffer;
+
+       // Headline
+       p += sprintf(p, "[repo:%s]\n", pakfire_repo_get_name(repo));
+
+       // Enabled
+       p += sprintf(p, "enabled = %d\n", pakfire_repo_get_enabled(repo));
+
+       // Base URL
+       const char* baseurl = pakfire_repo_get_baseurl(repo);
+       if (baseurl)
+               p += sprintf(p, "baseurl = %s\n", baseurl);
+
+       // Mirror List
+       const char* mirrorlist = pakfire_repo_get_mirrorlist(repo);
+       if (mirrorlist)
+               p += sprintf(p, "mirrors = %s\n", mirrorlist);
+
+       // Key File
+       const char* keyfile = pakfire_repo_get_keyfile(repo);
+       if (keyfile)
+               p += sprintf(p, "keyfile = %s\n", keyfile);
+
+       // Priority
+       p += sprintf(p, "priority = %d\n", pakfire_repo_get_priority(repo));
+
+       return pakfire_strdup(buffer);
+}
+
 PAKFIRE_EXPORT int pakfire_repo_is_installed_repo(PakfireRepo repo) {
        PakfireRepo installed_repo = pakfire_get_installed_repo(repo->pakfire);
 
index ea56d0eb053215c54054575e76059bbbb2c432e2..989d1744a634429551f308c5c1e1aec1163aad09 100644 (file)
@@ -88,13 +88,6 @@ class RepositoryFactory(_pakfire.Repo):
 
                return "\n\n".join(dumps)
 
-       def get_config(self):
-               """
-                       Return the configuration as a list of string which
-                       can be written to a configuration file.
-               """
-               pass
-
 
 class RepositoryDummy(RepositoryFactory):
        """
index cd2b85075b1550cbbaba201cdb63bdb72abbc526..289c1c2ce07569624a3d8067093250ad8cf8e6fd 100644 (file)
@@ -268,27 +268,3 @@ class RepositoryRemote(base.RepositoryFactory):
                        grabber.increment_mirror(grabber)
 
                return os.path.join(self.cache.path, cache_filename)
-
-       def get_config(self):
-               if self.enabled:
-                       enabled = "1"
-               else:
-                       enabled = "0"
-
-               lines = [
-                       "[repo:%s]" % self.name,
-                       "description = %s" % self.description,
-                       "enabled = %s" % enabled,
-                       "baseurl = %s" % self.baseurl,
-               ]
-
-               mirrors = self.settings.get("mirrors", None)
-               if mirrors:
-                       lines.append("mirrors = %s" % mirrors)
-
-               lines += [
-                       #"gpgkey = %s" % self.keyfile,
-                       "priority = %s" % self.priority,
-               ]
-
-               return lines