From: Michael Tremer Date: Wed, 12 Oct 2022 10:47:17 +0000 (+0000) Subject: repos: Use configparser to create configuration X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=75690d8d115469978eb9e4ca34b043db1b51a260;p=pbs.git repos: Use configparser to create configuration Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/repository.py b/src/buildservice/repository.py index 9364ce52..e05784bb 100644 --- a/src/buildservice/repository.py +++ b/src/buildservice/repository.py @@ -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