]> git.ipfire.org Git - pakfire.git/commitdiff
packages: Add distribution information
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 17 May 2022 14:09:20 +0000 (14:09 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 17 May 2022 14:09:20 +0000 (14:09 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/package.c
src/libpakfire/archive.c
src/libpakfire/build.c
src/libpakfire/db.c
src/libpakfire/include/pakfire/package.h
src/libpakfire/libpakfire.sym
src/libpakfire/package.c

index 5c79c01c799e40c1f4e6d0ce1a8f98d972bddd3a..783e813f8635535114e41888949d6b6b8da844ef 100644 (file)
@@ -315,6 +315,20 @@ static void Package_set_vendor(PackageObject* self, PyObject* value) {
        pakfire_package_set_vendor(self->package, vendor);
 }
 
+static PyObject* Package_get_distribution(PackageObject* self) {
+       const char* distribution = pakfire_package_get_distribution(self->package);
+       if (!distribution)
+               Py_RETURN_NONE;
+
+       return PyUnicode_FromString(distribution);
+}
+
+static void Package_set_distribution(PackageObject* self, PyObject* value) {
+       const char* distribution = PyUnicode_AsUTF8(value);
+
+       pakfire_package_set_distribution(self->package, distribution);
+}
+
 static PyObject* Package_get_maintainer(PackageObject* self) {
        const char* maintainer = pakfire_package_get_maintainer(self->package);
        if (!maintainer)
@@ -816,6 +830,13 @@ static struct PyGetSetDef Package_getsetters[] = {
                NULL,
                NULL
        },
+       {
+               "distribution",
+               (getter)Package_get_distribution,
+               (setter)Package_set_distribution,
+               NULL,
+               NULL
+       },
        {
                "maintainer",
                (getter)Package_get_maintainer,
index bfb83eab73c347c2ad9927f1cdb9a5b8b53e4e59..18653c12e7230538f3f091ee38daee710f84deb9 100644 (file)
@@ -2115,6 +2115,11 @@ static int pakfire_archive_make_package_from_json(struct pakfire_archive* archiv
        if (vendor)
                pakfire_package_set_vendor(pkg, vendor);
 
+       // Distribution
+       const char* distribution = pakfire_archive_metadata_get(archive, "distribution", NULL);
+       if (distribution)
+               pakfire_package_set_distribution(pkg, distribution);
+
        // UUID
        const char* uuid = pakfire_archive_metadata_get(archive, "uuid", NULL);
        if (uuid)
index 5e4d15c8b742baa8f03c4441e80a3eba9ccb339e..b7c91f81588746e1e57ecf7216f5720d21264d39 100644 (file)
@@ -476,6 +476,11 @@ static int pakfire_build_package(struct pakfire* pakfire, struct pakfire_parser*
                goto ERROR;
        }
 
+       // Set distribution
+       const char* distribution = pakfire_parser_get(makefile, NULL, "DISTRO_NAME");
+       if (distribution)
+               pakfire_package_set_distribution(pkg, distribution);
+
        // Set build ID
        pakfire_package_set_build_id_from_uuid(pkg, build_id);
 
index 23a878fe9becea7df7ae0da4d8b73a954a9e1ef0..f153bcef9e624b8c502d1ebc95c42b715207787b 100644 (file)
@@ -370,7 +370,8 @@ static int pakfire_db_create_schema(struct pakfire_db* db) {
                        "repository     TEXT, "
                        "source_name    TEXT, "
                        "source_evr     TEXT, "
-                       "source_arch    TEXT"
+                       "source_arch    TEXT, "
+                       "distribution   TEXT"
                ")");
        if (r)
                return 1;
@@ -1266,7 +1267,8 @@ int pakfire_db_add_package(struct pakfire_db* db,
                        "userinstalled, "
                        "source_name, "
                        "source_evr, "
-                       "source_arch"
+                       "source_arch, "
+                       "distribution"
                ") VALUES("
                        "?, "
                        "?, "
@@ -1288,6 +1290,7 @@ int pakfire_db_add_package(struct pakfire_db* db,
                        "?, "
                        "?, "
                        "?, "
+                       "?, "
                        "?"
                ")";
 
@@ -1510,6 +1513,18 @@ int pakfire_db_add_package(struct pakfire_db* db,
                        goto ERROR;
        }
 
+       // Distribution
+       const char* distribution = pakfire_package_get_distribution(pkg);
+       if (distribution) {
+               r = sqlite3_bind_text(stmt, 21, distribution, -1, NULL);
+               if (r)
+                       goto ERROR;
+       } else {
+               r = sqlite3_bind_null(stmt, 21);
+               if (r)
+                       goto ERROR;
+       }
+
        // Run query
        do {
                r = sqlite3_step(stmt);
@@ -1850,6 +1865,11 @@ static int pakfire_db_load_package(struct pakfire_db* db, struct pakfire_repo* r
        if (source_arch)
                pakfire_package_set_source_arch(pkg, source_arch);
 
+       // Distribution
+       const char* distribution = (const char*)sqlite3_column_text(stmt, 31);
+       if (distribution)
+               pakfire_package_set_distribution(pkg, distribution);
+
        // Success
        r = 0;
 
@@ -1934,7 +1954,8 @@ int pakfire_db_load(struct pakfire_db* db, struct pakfire_repo* repo) {
                        ") AS enhances, "
                        "source_name, "
                        "source_evr, "
-                       "source_arch "
+                       "source_arch, "
+                       "distribution "
                "FROM "
                        "packages"
                ";";
index 7ad9f04165f189939ff76e03f0630eef9703007b..728e7e7bb994f3abb3d2d086ebb81ca0b2b33f4b 100644 (file)
@@ -71,6 +71,8 @@ char* pakfire_package_get_groups(struct pakfire_package* pkg);
 void pakfire_package_set_groups(struct pakfire_package* pkg, const char* groups);
 const char* pakfire_package_get_vendor(struct pakfire_package* pkg);
 void pakfire_package_set_vendor(struct pakfire_package* pkg, const char* vendor);
+const char* pakfire_package_get_distribution(struct pakfire_package* pkg);
+void pakfire_package_set_distribution(struct pakfire_package* pkg, const char* distribution);
 const char* pakfire_package_get_maintainer(struct pakfire_package* pkg);
 void pakfire_package_set_maintainer(struct pakfire_package* pkg, const char* maintainer);
 const char* pakfire_package_get_filename(struct pakfire_package* pkg);
index 9d380bc6f5f90401b90b181f28073623f65a5287..fd1720737b66afbcf8ac32da261cd3d7471661cc 100644 (file)
@@ -148,6 +148,7 @@ global:
        pakfire_package_get_conflicts;
        pakfire_package_get_description;
        pakfire_package_get_digest;
+       pakfire_package_get_distribution;
        pakfire_package_get_downloadsize;
        pakfire_package_get_enhances;
        pakfire_package_get_evr;
@@ -190,6 +191,7 @@ global:
        pakfire_package_set_build_time;
        pakfire_package_set_checksum;
        pakfire_package_set_description;
+       pakfire_package_set_distribution;
        pakfire_package_set_downloadsize;
        pakfire_package_set_evr;
        pakfire_package_set_filelist;
index ec6198ea4364845718fc0ba0e4786e4e3283b756..fa642b6a3f10ccf9990d48fe116c9a48af2fe1d7 100644 (file)
@@ -568,6 +568,14 @@ PAKFIRE_EXPORT void pakfire_package_set_vendor(struct pakfire_package* pkg, cons
        pakfire_package_set_string(pkg, SOLVABLE_VENDOR, vendor);
 }
 
+PAKFIRE_EXPORT const char* pakfire_package_get_distribution(struct pakfire_package* pkg) {
+       return pakfire_package_get_string(pkg, SOLVABLE_DISTRIBUTION);
+}
+
+PAKFIRE_EXPORT void pakfire_package_set_distribution(struct pakfire_package* pkg, const char* distribution) {
+       pakfire_package_set_string(pkg, SOLVABLE_DISTRIBUTION, distribution);
+}
+
 PAKFIRE_EXPORT const char* pakfire_package_get_maintainer(struct pakfire_package* pkg) {
        return pakfire_package_get_string(pkg, SOLVABLE_PACKAGER);
 }
@@ -1630,6 +1638,14 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) {
                        goto ERROR;
        }
 
+       // Distribution
+       const char* distribution = pakfire_package_get_distribution(pkg);
+       if (distribution) {
+               r = pakfire_json_add_string(pkg->pakfire, md, "distribution", distribution);
+               if (r)
+                       goto ERROR;
+       }
+
        // UUID
        const char* uuid = pakfire_package_get_uuid(pkg);
        if (uuid) {