proj/mirrorselect:master commit in: /, tests/, mirrorselect/, mirrorselect/configs/

"Mike Gilbert" <[email protected]> Sun, 02 Aug 2026 18:44:05 +0000 (UTC)
Newsgroups gmane.linux.gentoo.cvs
Message-ID <1785696136.88e8bb52df9a5af4ee1c9d1608af2b8853662cf4.floppym@gentoo>
commit:     88e8bb52df9a5af4ee1c9d1608af2b8853662cf4
Author:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
AuthorDate: Sun Aug  2 18:42:16 2026 +0000
Commit:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
CommitDate: Sun Aug  2 18:42:16 2026 +0000
URL:        https://gitweb.gentoo.org/proj/mirrorselect.git/commit/?id=88e8bb52

Use sysconfdir instead of EPREFIX

Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org>

 meson.build                             |  8 ++------
 mirrorselect/configs/configuration.py   |  4 ++--
 mirrorselect/configs/distfilesconfig.py |  8 ++++----
 mirrorselect/configs/rsyncconfig.py     | 17 +++++++----------
 mirrorselect/main.py                    | 13 +++++--------
 tests/test_write_make_conf.py           |  2 +-
 6 files changed, 21 insertions(+), 31 deletions(-)

diff --git a/meson.build b/meson.build
index bc893bd..9d36ca5 100644
--- a/meson.build
+++ b/meson.build
@@ -4,16 +4,12 @@ project('mirrorselect',
   version : '2.7.0',
 )
 
-fs = import('fs')
 py = import('python').find_installation(pure : true)
 
-eprefix = fs.parent(get_option('prefix') / get_option('sysconfdir'))
-if eprefix == '/'
-  eprefix = ''
-endif
+confdir = get_option('prefix') / get_option('sysconfdir')
 
 cdata = configuration_data()
-cdata.set('GENTOO_PORTAGE_EPREFIX', eprefix)
+cdata.set('CONFDIR', confdir)
 cdata.set('VERSION', meson.project_version())
 
 subdir('mirrorselect')

diff --git a/mirrorselect/configs/configuration.py b/mirrorselect/configs/configuration.py
index b125133..0454ad7 100644
--- a/mirrorselect/configs/configuration.py
+++ b/mirrorselect/configs/configuration.py
@@ -35,8 +35,8 @@ from mirrorselect.output import Output
 
 
 class Configuration(ABC):
-    def __init__(self, var: str, eprefix: str):
-        self.eprefix = eprefix
+    def __init__(self, var: str, confdir: str):
+        self.confdir = confdir
         self.var = var
 
     @abstractmethod

diff --git a/mirrorselect/configs/distfilesconfig.py b/mirrorselect/configs/distfilesconfig.py
index 277e494..5d68c87 100644
--- a/mirrorselect/configs/distfilesconfig.py
+++ b/mirrorselect/configs/distfilesconfig.py
@@ -41,15 +41,15 @@ from .configuration import Configuration
 
 
 class DistfilesConfig(Configuration):
-    def __init__(self, eprefix: str = ""):
-        super().__init__("GENTOO_MIRRORS", eprefix)
+    def __init__(self, confdir: str):
+        super().__init__("GENTOO_MIRRORS", confdir)
 
     def get_conf_path(self, output: Output):
         # try the newer make.conf location
-        config_path = self.eprefix + "/etc/portage/make.conf"
+        config_path = os.path.join(self.confdir, "portage", "make.conf")
         if not os.path.exists(config_path):
             # check if the old location is what is used
-            old_path = self.eprefix + "/etc/make.conf"
+            old_path = os.path.join(self.confdir, "make.conf")
             if os.path.exists(old_path):
                 config_path = old_path
         return config_path

diff --git a/mirrorselect/configs/rsyncconfig.py b/mirrorselect/configs/rsyncconfig.py
index d736606..280e847 100644
--- a/mirrorselect/configs/rsyncconfig.py
+++ b/mirrorselect/configs/rsyncconfig.py
@@ -26,6 +26,7 @@ Distributed under the terms of the GNU General Public License v2
 """
 
 import os
+import os.path
 from optparse import Values
 
 from mirrorselect.extractor import Extractor
@@ -36,16 +37,12 @@ from .configuration import Configuration
 
 
 class RsyncConfig(Configuration):
-    def __init__(self, eprefix: str = ""):
-        super().__init__("sync-uri", eprefix)
+    def __init__(self, confdir: str):
+        super().__init__("sync-uri", confdir)
 
     def get_conf_path(self, output: Output):
-        config_path = self.eprefix + "/etc/portage/repos.conf/gentoo.conf"
-        if not os.access(config_path, os.F_OK):
-            output.write(
-                f"Failed access to gentoo.conf: {os.access(config_path, os.F_OK)}\n",
-                2,
-            )
+        config_path = os.path.join(self.confdir, "portage", "repos.conf", "gentoo.conf")
+        if not os.path.exists(config_path):
             config_path = None
         return config_path
 
@@ -67,10 +64,10 @@ class RsyncConfig(Configuration):
         from configparser import ConfigParser
 
         config = ConfigParser()
-        config.read(config_path)
+        config.read(config_path, encoding="utf-8")
         if config.has_option("gentoo", self.var):
             config.set("gentoo", self.var, " ".join(hosts))
-            with open(config_path, "w") as configfile:
+            with open(config_path, "w", encoding="utf-8") as configfile:
                 config.write(configfile)
         else:
             output.print_err(

diff --git a/mirrorselect/main.py b/mirrorselect/main.py
index 40b806f..a0494b3 100644
--- a/mirrorselect/main.py
+++ b/mirrorselect/main.py
@@ -39,13 +39,10 @@ from mirrorselect.output import ColoredFormatter, Output
 from mirrorselect.selectors import Deep, Interactive, Shallow
 from mirrorselect.version import version
 
-# establish the eprefix, initially set so exprefixify can
-# set it on install
-EPREFIX = "@GENTOO_PORTAGE_EPREFIX@"
 
-# check and set it if it wasn't
-if "GENTOO_PORTAGE_EPREFIX" in EPREFIX:
-    EPREFIX = ""
+confdir = "@CONFDIR@"
+if confdir == "@" "CONFDIR@":
+    confdir = "/etc"
 
 
 class MirrorSelect:
@@ -388,9 +385,9 @@ class MirrorSelect:
         self.output.verbosity = options.verbosity
 
         if options.rsync:
-            self.mirror_type = RsyncConfig()
+            self.mirror_type = RsyncConfig(confdir)
         else:
-            self.mirror_type = DistfilesConfig(EPREFIX)
+            self.mirror_type = DistfilesConfig(confdir)
 
         config_path = self.mirror_type.get_conf_path(self.output)
         self.output.write(f"main(); config_path = {config_path}\n", 2)

diff --git a/tests/test_write_make_conf.py b/tests/test_write_make_conf.py
index 989249b..4f9191b 100644
--- a/tests/test_write_make_conf.py
+++ b/tests/test_write_make_conf.py
@@ -12,8 +12,8 @@ from mirrorselect.output import Output
 class WriteMakeConfTestCase(unittest.TestCase):
     def test_write_make_conf(self):
         def __do_it(var, mirror_list, make_conf, expected_result):
-            sut = DistfilesConfig()
             tempdir = tempfile.mkdtemp()
+            sut = DistfilesConfig(tempdir)
             status_output = open(os.devnull, "w")
             # print("------make_conf--------", make_conf, "----------------------")
             # print("*****expect*****\n", expected_result, "***********")