]> git.ipfire.org Git - pbs.git/commitdiff
repos: Use configparser to create configuration
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 12 Oct 2022 10:47:17 +0000 (10:47 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 12 Oct 2022 10:47:17 +0000 (10:47 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/repository.py

index 9364ce52847ec793f835f1720577e8533bce6eec..e05784bb0f14024d83dcd4d345140b4a6cdd17d3 100644 (file)
@@ -1,7 +1,9 @@
 #!/usr/bin/python
 
 import asyncio
+import configparser
 import datetime
+import io
 import logging
 import os.path
 
@@ -294,27 +296,36 @@ class Repository(base.DataObject):
                        "mirrorlist?arch=%{arch}"
                ))
 
-       def get_config(self, local=False):
-               lines = [
-                       "[repo:%s]" % self.slug,
-                       "description = %s - %s" % (self.distro.name, self.summary),
-                       "enabled = 1",
-                       "baseurl = %s/%%{arch}" % (self.path if local else self.url),
+       def _make_config(self, local=False):
+               buffer = io.StringIO()
+               config = configparser.ConfigParser()
 
-                       # Key
-                       "key = %s/keys/%s" % (
-                               self.settings.get("baseurl", "https://pakfire.ipfire.org"),
-                               self.key.fingerprint,
-                       ),
-               ]
+               section = "repo:%s" % self.slug
 
+               # Add a new section
+               config.add_section(section)
+
+               # Description
+               config.set(section, "description", "%s - %s" % (self.distro.name, self.summary))
+
+               # Base URL
+               config.set(section, "baseurl", self.path if local else self.url)
+
+               # Key
+               config.set(section, "key", self.key.public_key)
+
+               # Mirrorlist
                if self.mirrored and not local:
-                       lines.append("mirrors = %s" % self.mirrorlist)
+                       config.set(section, "mirrors", self.mirrorlist)
 
+               # Priority
                if self.priority:
-                       lines.append("priority = %s" % self.priority)
+                       config.set(section, "priority", "%s" % self.priority)
+
+               # Write the configuration
+               config.write(buffer)
 
-               return "\n".join(lines)
+               return buffer.getvalue()
 
        # Name