]> git.ipfire.org Git - pbs.git/commitdiff
distros: Add required version values
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 9 Mar 2023 13:07:58 +0000 (13:07 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 9 Mar 2023 14:11:12 +0000 (14:11 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/distribution.py
src/database.sql

index 316de0ebcb7372127ab1dc31a77493eaa7c7a9e8..d80bfcc06e83ac5bbeb5ac69e3b5d52fe8179c21 100644 (file)
@@ -1,5 +1,7 @@
 #!/usr/bin/python
 
+import configparser
+import io
 import logging
 import pakfire
 
@@ -35,8 +37,17 @@ class Distributions(base.Object):
                        WHERE id = %s", distro_id)
 
        def get_by_slug(self, slug):
-               return self._get_distribution("SELECT * FROM distributions \
-                       WHERE slug = %s AND deleted IS FALSE", slug)
+               return self._get_distribution("""
+                       SELECT
+                               *
+                       FROM
+                               distributions
+                       WHERE
+                               deleted IS FALSE
+                       AND
+                               distro_id || '-' || version_id = %s
+                       """, slug,
+               )
 
        def get_by_tag(self, tag):
                return self._get_distribution("""
@@ -47,25 +58,23 @@ class Distributions(base.Object):
                        WHERE
                                deleted IS FALSE
                        AND
-                               tag = %s
+                               distro_id || version_id = %s
                        """, tag,
                )
 
-       def create(self, name, tag):
-               slug = misc.normalize(name)
-
+       def create(self, name, distro_id, version_id):
                # Insert into the database
                return self._get_distribution("""
                        INSERT INTO
                                distributions(
-                                       name, slug, tag
+                                       name, distro_id, version_id
                                )
                        VALUES(
                                %s, %s, %s
                        )
                        RETURNING
                                *""",
-                       name, slug, tag,
+                       name, distro_id, version_id,
                )
 
 
@@ -76,34 +85,33 @@ class Distribution(base.DataObject):
                return "<%s %s>" % (self.__class__.__name__, self.name)
 
        def __str__(self):
-               return self.name
+               return "%s %s" % (self.name, self.version)
 
        def _make_config(self, local=False, vendor=None, contact=None):
-               try:
-                       name, release = self.name.split()
-               except:
-                       name = self.name
-                       release = "N/A"
-
-               lines = [
-                       "[distro]",
-                       "name = %s" % name,
-                       "release = %s" % release,
-                       "slogan = %s" % self.slogan,
-                       "",
-                       "vendor = %s" % (vendor or self.vendor),
-                       "contact = %s" % (contact or self.contact),
-               ]
+               buffer = io.StringIO()
+
+               # Create a new configuration object
+               config = configparser.ConfigParser(interpolation=None)
+
+               config["distro"] = {
+                       "name"       : self.name,
+                       "id"         : self.distro_id,
+                       "version_id" : self.version_id,
+                       "codename"   : self.codename,
+                       "slogan"     : self.slogan,
+                       "vendor"     : vendor or self.vendor,
+                       "contact"    : contact or self.contact,
+               }
 
                # Add any custom configuration
                if self.custom_config:
-                       lines += (
-                               "### CUSTOM CONFIG ###",
-                               self.custom_config,
-                               "### CUSTOM CONFIG END ###",
-                       )
+                       config.read_string(self.custom_config)
+
+               # Write the configuration to a buffer
+               config.write(buffer)
 
-               return "\n".join(lines)
+               # Return the configuration as string
+               return buffer.getvalue()
 
        # Name
 
@@ -115,11 +123,32 @@ class Distribution(base.DataObject):
 
        name = property(get_name, set_name)
 
+       # Distro ID
+
+       @property
+       def distro_id(self):
+               return self.data.distro_id
+
+       # Version
+
+       @property
+       def version(self):
+               if self.codename:
+                       return "%s (%s)" % (self.version_id, self.codename)
+
+               return "%s" % self.version_id
+
+       # Version ID
+
+       @property
+       def version_id(self):
+               return self.data.version_id
+
        # Slug
 
        @property
        def slug(self):
-               return self.data.slug
+               return "%s-%s" % (self.distro_id, self.version_id)
 
        # Slogan
 
@@ -131,6 +160,16 @@ class Distribution(base.DataObject):
 
        slogan = property(get_slogan, set_slogan)
 
+       # Codename
+
+       def get_codename(self):
+               return self.data.codename
+
+       def set_codename(self, codename):
+               self._set_attribute("codename", codename or "")
+
+       codename = property(get_codename, set_codename)
+
        # Description
 
        def get_description(self):
@@ -175,7 +214,7 @@ class Distribution(base.DataObject):
 
        @property
        def tag(self):
-               return self.data.tag
+               return "%s%s" % (self.distro_id, self.version_id)
 
        # Custom Configuration
 
index f6199208197ad0ba251f83d9ad987abe7a681d51..5904c615517853db4964ed0d1c93963b729838c7 100644 (file)
@@ -2,8 +2,8 @@
 -- PostgreSQL database dump
 --
 
--- Dumped from database version 13.8 (Debian 13.8-0+deb11u1)
--- Dumped by pg_dump version 13.8 (Debian 13.8-0+deb11u1)
+-- Dumped from database version 13.9 (Debian 13.9-0+deb11u1)
+-- Dumped by pg_dump version 13.9 (Debian 13.9-0+deb11u1)
 
 SET statement_timeout = 0;
 SET lock_timeout = 0;
@@ -292,16 +292,17 @@ ALTER SEQUENCE public.builds_id_seq OWNED BY public.builds.id;
 CREATE TABLE public.distributions (
     id integer NOT NULL,
     name text NOT NULL,
-    slug text NOT NULL,
+    distro_id text NOT NULL,
     slogan text DEFAULT ''::text NOT NULL,
     description text DEFAULT ''::text NOT NULL,
     vendor text DEFAULT ''::text NOT NULL,
     contact text DEFAULT ''::text NOT NULL,
-    tag text NOT NULL,
+    version_id integer NOT NULL,
     deleted boolean DEFAULT false NOT NULL,
     arches text[] DEFAULT ARRAY[]::text[] NOT NULL,
     created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
-    custom_config text DEFAULT ''::text NOT NULL
+    custom_config text DEFAULT ''::text NOT NULL,
+    codename text DEFAULT ''::text NOT NULL
 );
 
 
@@ -1530,10 +1531,10 @@ CREATE UNIQUE INDEX builds_uuid ON public.builds USING btree (uuid) WHERE (delet
 
 
 --
--- Name: distributions_slug; Type: INDEX; Schema: public; Owner: -
+-- Name: distributions_unique; Type: INDEX; Schema: public; Owner: -
 --
 
-CREATE UNIQUE INDEX distributions_slug ON public.distributions USING btree (slug) WHERE (deleted IS FALSE);
+CREATE UNIQUE INDEX distributions_unique ON public.distributions USING btree (distro_id, version_id) WHERE (deleted IS FALSE);
 
 
 --