#!/usr/bin/python
+import configparser
+import io
import logging
import pakfire
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("""
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,
)
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
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
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):
@property
def tag(self):
- return self.data.tag
+ return "%s%s" % (self.distro_id, self.version_id)
# Custom Configuration
-- 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;
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
);
--
--- 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);
--