diff --git a/pacman_mirrors/dialogs/consoleui.py b/pacman_mirrors/dialogs/consoleui.py index ad6ecb112175ba4af8542310cb113af1dcafdea6..5d03beff841fa3582d3fb139344dae106f4dc050 100644 --- a/pacman_mirrors/dialogs/consoleui.py +++ b/pacman_mirrors/dialogs/consoleui.py @@ -24,7 +24,7 @@ from collections import namedtuple import npyscreen from pacman_mirrors.constants import txt -from pacman_mirrors.functions import consolefn +from pacman_mirrors.functions import consoleFn from pacman_mirrors.translation import i18n _ = i18n.language.gettext @@ -58,8 +58,8 @@ class ConsoleUI(npyscreen.NPSAppManaged): "url": txt.I_URL}) main_server_list.append(header_cols) main_server_list.extend(self.server_list) - servers = consolefn.list_to_tuple(main_server_list, server) - server_rows = consolefn.rows_from_tuple(servers) + servers = consoleFn.list_to_tuple(main_server_list, server) + server_rows = consoleFn.rows_from_tuple(servers) header_row = ("{:<5}".format(txt.I_USE) + (server_rows[0].replace("|", " ").strip())) del server_rows[0] diff --git a/pacman_mirrors/config/configfn.py b/pacman_mirrors/functions/configFn.py similarity index 100% rename from pacman_mirrors/config/configfn.py rename to pacman_mirrors/functions/configFn.py diff --git a/pacman_mirrors/functions/consolefn.py b/pacman_mirrors/functions/consoleFn.py similarity index 100% rename from pacman_mirrors/functions/consolefn.py rename to pacman_mirrors/functions/consoleFn.py diff --git a/pacman_mirrors/functions/customfn.py b/pacman_mirrors/functions/customFn.py similarity index 95% rename from pacman_mirrors/functions/customfn.py rename to pacman_mirrors/functions/customFn.py index a6647b6ba0f053c6e72994e8a65a5aaf9c260237..f517138c59f6f33cad4428a7f09387bed4f4bd70 100644 --- a/pacman_mirrors/functions/customfn.py +++ b/pacman_mirrors/functions/customFn.py @@ -23,7 +23,7 @@ import os from pacman_mirrors.config import configuration as conf from pacman_mirrors.constants import txt -from pacman_mirrors.functions import jsonfn +from pacman_mirrors.functions import jsonFn def convert_to_json(): @@ -48,7 +48,7 @@ def convert_to_json(): "url": mirror_url }) # write new file - jsonfn.write_json_file(mirrors, conf.CUSTOM_FILE) + jsonFn.write_json_file(mirrors, conf.CUSTOM_FILE) os.remove(conf.O_CUST_FILE) diff --git a/pacman_mirrors/functions/filefn.py b/pacman_mirrors/functions/fileFn.py similarity index 98% rename from pacman_mirrors/functions/filefn.py rename to pacman_mirrors/functions/fileFn.py index aef2e54c2459efc5c4c0408fdcd02958aef2ea4d..19cafdb9f190c20f984660916814389cb6ceee9f 100644 --- a/pacman_mirrors/functions/filefn.py +++ b/pacman_mirrors/functions/fileFn.py @@ -26,7 +26,7 @@ import sys import pacman_mirrors.functions.util from pacman_mirrors.constants import colors as color from pacman_mirrors.constants import txt -from pacman_mirrors.functions import jsonfn +from pacman_mirrors.functions import jsonFn def check_existance_of(filename, folder=False): @@ -147,7 +147,7 @@ def read_mirror_file(filename): :param filename: :returns: list of mirrors """ - return jsonfn.read_json_file(filename, dictionary=True) + return jsonFn.read_json_file(filename, dictionary=True) def write_mirrorlist_header(handle, custom=False): diff --git a/pacman_mirrors/functions/httpfn.py b/pacman_mirrors/functions/httpFn.py similarity index 91% rename from pacman_mirrors/functions/httpfn.py rename to pacman_mirrors/functions/httpFn.py index 8576e4bfa56b44d262cc91fd9597f5abd2d8284f..f574dd0d947ce37e4e4cb6f51b02b6ae0378a975 100644 --- a/pacman_mirrors/functions/httpfn.py +++ b/pacman_mirrors/functions/httpFn.py @@ -35,8 +35,8 @@ from urllib.request import urlopen from pacman_mirrors import __version__ from pacman_mirrors.config import configuration as conf from pacman_mirrors.constants import txt -from pacman_mirrors.functions import filefn -from pacman_mirrors.functions import jsonfn +from pacman_mirrors.functions import fileFn +from pacman_mirrors.functions import jsonFn def download_mirrors(config): @@ -54,13 +54,13 @@ def download_mirrors(config): object_pairs_hook=collections.OrderedDict) fetchmirrors = True tempfile = config["work_dir"] + "/temp.file" - jsonfn.json_dump_file(mirrorlist, tempfile) + jsonFn.json_dump_file(mirrorlist, tempfile) filecmp.clear_cache() - if filefn.check_existance_of(conf.USR_DIR, folder=True): - if not filefn.check_existance_of(config["mirror_file"]): - jsonfn.json_dump_file(mirrorlist, config["mirror_file"]) + if fileFn.check_existance_of(conf.USR_DIR, folder=True): + if not fileFn.check_existance_of(config["mirror_file"]): + jsonFn.json_dump_file(mirrorlist, config["mirror_file"]) elif not filecmp.cmp(tempfile, config["mirror_file"]): - jsonfn.json_dump_file(mirrorlist, config["mirror_file"]) + jsonFn.json_dump_file(mirrorlist, config["mirror_file"]) os.remove(tempfile) except (HTTPException, json.JSONDecodeError, URLError): pass @@ -71,7 +71,7 @@ def download_mirrors(config): response.read().decode("utf8"), object_pairs_hook=collections.OrderedDict) fetchstatus = True - jsonfn.write_json_file(statuslist, config["status_file"]) + jsonFn.write_json_file(statuslist, config["status_file"]) except (HTTPException, json.JSONDecodeError, URLError): pass # result @@ -100,7 +100,7 @@ def get_geoip_country(): "United States": "United_States", } if country_name in country_fix.keys(): - country_name = country_fix[country_name] + country_name = [country_fix[country_name]] return country_name @@ -200,7 +200,7 @@ def update_mirrors(config, quiet=False): txt.REPO_SERVER)) result = download_mirrors(config) else: - if not filefn.check_existance_of(config["status_file"]): + if not fileFn.check_existance_of(config["status_file"]): if not quiet: print(".: {} {} {} {}".format(txt.WRN_CLR, txt.MIRROR_FILE, @@ -210,7 +210,7 @@ def update_mirrors(config, quiet=False): txt.FALLING_BACK, conf.MIRROR_FILE)) result = (True, False) - if not filefn.check_existance_of(config["mirror_file"]): + if not fileFn.check_existance_of(config["mirror_file"]): if not quiet: print(".: {} {}".format(txt.ERR_CLR, txt.HOUSTON)) result = (False, False) diff --git a/pacman_mirrors/functions/jsonfn.py b/pacman_mirrors/functions/jsonFn.py similarity index 100% rename from pacman_mirrors/functions/jsonfn.py rename to pacman_mirrors/functions/jsonFn.py diff --git a/pacman_mirrors/functions/validfn.py b/pacman_mirrors/functions/validFn.py similarity index 100% rename from pacman_mirrors/functions/validfn.py rename to pacman_mirrors/functions/validFn.py diff --git a/pacman_mirrors/mirrors/mirrorfn.py b/pacman_mirrors/mirrors/mirrorfn.py index a351f7ad234bffbbc9de6f06981f98d84b9673ea..52d9835ba8c3a5645bdcc71b4ec4401c5392fb8d 100644 --- a/pacman_mirrors/mirrors/mirrorfn.py +++ b/pacman_mirrors/mirrors/mirrorfn.py @@ -19,9 +19,9 @@ """Pacman-Mirror Mirror Functions""" -from pacman_mirrors.functions import validfn -from pacman_mirrors.functions import httpfn -from pacman_mirrors.functions import jsonfn +from pacman_mirrors.functions import validFn +from pacman_mirrors.functions import httpFn +from pacman_mirrors.functions import jsonFn def build_country_list(country_selection, country_pool, geoip=False): @@ -39,7 +39,7 @@ def build_country_list(country_selection, country_pool, geoip=False): if country_selection == ["all"]: result = country_pool else: - if validfn.country_list_is_valid(country_selection, + if validFn.country_list_is_valid(country_selection, country_pool): result = country_selection if not result: @@ -60,7 +60,7 @@ def get_geoip_country(country_pool): :param country_pool: :return: country name if found """ - g_country = httpfn.get_geoip_country() + g_country = httpFn.get_geoip_country() if g_country in country_pool: return g_country else: @@ -109,7 +109,7 @@ def set_custom_mirror_status(config, custom_pool): :param custom_pool: the custom mirror pool :return: custom mirror pool with status applied """ - status_list = tuple(jsonfn.read_json_file(config["status_file"], dictionary=False)) + status_list = tuple(jsonFn.read_json_file(config["status_file"], dictionary=False)) custom_list = tuple(custom_pool) try: _ = status_list[0] diff --git a/pacman_mirrors/pacman_mirrors.py b/pacman_mirrors/pacman_mirrors.py index 355d3d8fb5898cab47f8208216446077cb29f6fb..2bdbe288eb9c8c7f4b642682badfcd2239c8a806 100644 --- a/pacman_mirrors/pacman_mirrors.py +++ b/pacman_mirrors/pacman_mirrors.py @@ -35,14 +35,13 @@ from random import shuffle import pacman_mirrors.functions.util from pacman_mirrors import __version__ from pacman_mirrors.api import apifn -from pacman_mirrors.config import configfn from pacman_mirrors.config import configuration as conf from pacman_mirrors.constants import colors as color from pacman_mirrors.constants import txt -from pacman_mirrors.functions import filefn -from pacman_mirrors.functions import httpfn -from pacman_mirrors.functions import jsonfn -from pacman_mirrors.functions import validfn +from pacman_mirrors.functions import fileFn, configFn +from pacman_mirrors.functions import httpFn +from pacman_mirrors.functions import jsonFn +from pacman_mirrors.functions import validFn from pacman_mirrors.functions import util from pacman_mirrors.mirrors import mirrorfn from pacman_mirrors.mirrors.mirror import Mirror @@ -346,11 +345,11 @@ class PacmanMirrors: """ # pacman-mirrors.conf could absent so check for it """ - if not filefn.check_existance_of(self.config["config_file"]): + if not fileFn.check_existance_of(self.config["config_file"]): """ # Copy from host system """ - filefn.create_dir(set_pfx + "/etc") + fileFn.create_dir(set_pfx + "/etc") shutil.copyfile("/etc/pacman-mirrors.conf", self.config["config_file"]) """ @@ -370,7 +369,7 @@ class PacmanMirrors: """ # mirror list dir could absent so check for it """ - filefn.create_dir(set_pfx + "/etc/pacman.d") + fileFn.create_dir(set_pfx + "/etc/pacman.d") mirror = [ { "url": apifn.sanitize_url(set_url), @@ -379,7 +378,7 @@ class PacmanMirrors: "resp_time": "00.00" } ] - filefn.write_mirror_list(self.config, mirror, quiet=self.quiet) + fileFn.write_mirror_list(self.config, mirror, quiet=self.quiet) sys.exit(0) # Fourth API task: Write protocols to config if set_protocols: @@ -486,7 +485,7 @@ class PacmanMirrors: mirror["country"], mirror["last_sync"], mirror["url"]) print("{:.{}}".format(message, cols), end="") sys.stdout.flush() - resp_time = httpfn.get_mirror_response(mirror["url"], + resp_time = httpFn.get_mirror_response(mirror["url"], maxwait=self.max_wait_time, quiet=self.quiet) mirror["resp_time"] = resp_time @@ -676,7 +675,7 @@ class PacmanMirrors: Custom mirror pool or countries from CLI :return: True/False """ - if validfn.custom_config_is_valid(): + if validFn.custom_config_is_valid(): self.custom = True else: self.selected_countries = self.config["country_pool"] @@ -688,7 +687,7 @@ class PacmanMirrors: """ self.custom = False self.config["country_pool"] = [] - filefn.delete_file(self.config["custom_file"]) + fileFn.delete_file(self.config["custom_file"]) def filter_user_branch(self, mirror_pool): """ @@ -737,7 +736,7 @@ class PacmanMirrors: """ Load all available mirrors """ - (file, status) = filefn.return_mirror_filename(self.config) + (file, status) = fileFn.return_mirror_filename(self.config) self.seed_mirrors(file, status) def output_country_pool_console(self): @@ -757,7 +756,7 @@ class PacmanMirrors: txt.CUSTOM_MIRROR_LIST)) print("--------------------------") # output mirror file - jsonfn.write_json_file(selected_mirrors, + jsonFn.write_json_file(selected_mirrors, self.config["custom_file"]) print(".: {} {}: {}".format(txt.INF_CLR, txt.CUSTOM_MIRROR_FILE_SAVED, @@ -769,13 +768,13 @@ class PacmanMirrors: :param selected_servers: """ if self.custom: - filefn.write_mirror_list(self.config, + fileFn.write_mirror_list(self.config, selected_servers, custom=self.custom, quiet=self.quiet, interactive=True) else: - filefn.write_mirror_list(self.config, + fileFn.write_mirror_list(self.config, selected_servers, quiet=self.quiet) @@ -827,7 +826,7 @@ class PacmanMirrors: """ Seed mirrors """ - mirrors = filefn.read_mirror_file(file) + mirrors = fileFn.read_mirror_file(file) # seed mirror object if status: self.mirrors.seed(mirrors, status=status) @@ -870,7 +869,7 @@ class PacmanMirrors: else: self.max_wait_time = http_wait # let's see how responsive you are - mirror["resp_time"] = httpfn.get_mirror_response( + mirror["resp_time"] = httpFn.get_mirror_response( mirror["url"], maxwait=self.max_wait_time, quiet=self.quiet, ssl_verify=ssl_verify) @@ -903,13 +902,13 @@ class PacmanMirrors: # Check if mirrorlist is not to be touched - normal exit # Handle missing network """ - (self.config, self.custom) = configfn.build_config() - filefn.create_dir(self.config["work_dir"]) + (self.config, self.custom) = configFn.build_config() + fileFn.create_dir(self.config["work_dir"]) self.command_line_parse() self.i686_check() # transparent change to i686 - self.network = httpfn.inet_conn_check() + self.network = httpFn.inet_conn_check() if self.network: - httpfn.update_mirrors(self.config, quiet=self.quiet) + httpFn.update_mirrors(self.config, quiet=self.quiet) if self.no_mirrorlist: sys.exit(0) if not self.network: diff --git a/scripts/pacman-mirrors b/scripts/pacman-mirrors index 050b7122d9221a230d6735d0962eb2de8b391f29..756e04be31266d40697501930af956241ce5fbe6 100755 --- a/scripts/pacman-mirrors +++ b/scripts/pacman-mirrors @@ -1,30 +1,60 @@ -#!/bin/bash - -app="pacman-mirrors $*" - -if [ `id -u` -eq 0 ]; then - #user is admin - ${app} -else - #user is not admin - if `echo $- | grep "i" >/dev/null 2>&1`; then - #script is running in interactive mode - su - -c "${app}" - else - #script is running in non-interactive mode - if [ $XDG_SESSION_TYPE = "wayland" ] ; then - xhost +SI:localuser:root - pkexec ${app} - xhost -SI:localuser:root - xhost - elif command -v pkexec >/dev/null 2>&1; then - pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY ${app} - elif command -v sudo >/dev/null 2>&1; then - x-terminal-emulator -e "sudo ${app}" - elif command -v su >/dev/null 2>&1; then - x-terminal-emulator -e "su - -c '${app}'" - else - x-terminal-emulator -e "echo 'Command must be run as root user: ${app}'" - fi - fi -fi +#!/usr/bin/env python +# +# This file is part of pacman_mirrors. +# +# pacman_mirrors is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# pacman_mirrors is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with pacman_mirrors. If not, see <http://www.gnu.org/licenses/>. +# +# Author(s): Ramon Buldó <rbuldo@gmail.com> + +import os +import shutil + +from pacman_mirrors import pacman_mirrors +from pacman_mirrors.config.configuration import O_CUST_FILE +from pacman_mirrors.functions import customfn +from pacman_mirrors.translation import i18n + +_ = i18n.language.gettext + + +def move_custom_country(): + """ + Move custom country file from /etc/pacman.d/mirrors/ to + /var/lib/pacman_mirrors/ + """ + print(_("Moving 'Custom' mirrors file to ") + "/var/lib/pacman_mirrors/") + os.makedirs("/var/lib/pacman_mirrors", mode=0o755, exist_ok=True) + try: + shutil.move("/etc/pacman.d/mirrors/Custom", + "/var/lib/pacman_mirrors/Custom") + except OSError as e: + print(_("Warning: Cannot move '{filename}' to '{filename2}': {error}" + .format(filename=e.filename, + filename2=e.filename2, + error=e.strerror))) + +if os.path.isfile("/etc/pacman.d/mirrors/Custom"): + if os.getuid() == 0: + move_custom_country() + +if os.path.isfile(O_CUST_FILE): + if os.getuid() == 0: + customfn.convert_to_json() +try: + pm = pacman_mirrors.PacmanMirrors() + pm.run() + +except KeyboardInterrupt: + print("\n" + _("Error: interrupted by the user.")) + exit(1) diff --git a/scripts/pacman_mirrors b/scripts/pacman_mirrors deleted file mode 100755 index 756e04be31266d40697501930af956241ce5fbe6..0000000000000000000000000000000000000000 --- a/scripts/pacman_mirrors +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env python -# -# This file is part of pacman_mirrors. -# -# pacman_mirrors is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# pacman_mirrors is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with pacman_mirrors. If not, see <http://www.gnu.org/licenses/>. -# -# Author(s): Ramon Buldó <rbuldo@gmail.com> - -import os -import shutil - -from pacman_mirrors import pacman_mirrors -from pacman_mirrors.config.configuration import O_CUST_FILE -from pacman_mirrors.functions import customfn -from pacman_mirrors.translation import i18n - -_ = i18n.language.gettext - - -def move_custom_country(): - """ - Move custom country file from /etc/pacman.d/mirrors/ to - /var/lib/pacman_mirrors/ - """ - print(_("Moving 'Custom' mirrors file to ") + "/var/lib/pacman_mirrors/") - os.makedirs("/var/lib/pacman_mirrors", mode=0o755, exist_ok=True) - try: - shutil.move("/etc/pacman.d/mirrors/Custom", - "/var/lib/pacman_mirrors/Custom") - except OSError as e: - print(_("Warning: Cannot move '{filename}' to '{filename2}': {error}" - .format(filename=e.filename, - filename2=e.filename2, - error=e.strerror))) - -if os.path.isfile("/etc/pacman.d/mirrors/Custom"): - if os.getuid() == 0: - move_custom_country() - -if os.path.isfile(O_CUST_FILE): - if os.getuid() == 0: - customfn.convert_to_json() -try: - pm = pacman_mirrors.PacmanMirrors() - pm.run() - -except KeyboardInterrupt: - print("\n" + _("Error: interrupted by the user.")) - exit(1) diff --git a/share/mirrors.json b/share/mirrors.json index 5c22059e970b23ee31d2b28fc989f027dffe999e..fb94d21c85659659687df68f59d9d1ae9d4dcd47 100644 --- a/share/mirrors.json +++ b/share/mirrors.json @@ -111,6 +111,14 @@ ], "url": "https://mirrors.zju.edu.cn/manjaro/" }, + { + "country": "China", + "protocols": [ + "ftp", + "https" + ], + "url": "https://mirrors.shuosc.org/manjaro/" + }, { "country": "Colombia", "protocols": [ @@ -269,6 +277,15 @@ ], "url": "http://babyname.tips/mirrors/manjaro/" }, + { + "country": "Greece", + "protocols": [ + "ftp", + "http", + "https" + ], + "url": "https://ftp.cc.uoc.gr/mirrors/linux/manjaro/" + }, { "country": "Hong_Kong", "protocols": [ diff --git a/share/org.manjaro.pkexec.pacman-mirrors.policy b/share/org.manjaro.pkexec.pacman-mirrors.policy deleted file mode 100755 index d218314cce5c157c0d54129e277404f4c9bf5238..0000000000000000000000000000000000000000 --- a/share/org.manjaro.pkexec.pacman-mirrors.policy +++ /dev/null @@ -1,20 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE policyconfig PUBLIC - "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN" - "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd"> -<policyconfig> - <vendor>Manjaro</vendor> - <vendor_url>http://manjaro.org/</vendor_url> - <icon_name>package-x-generic</icon_name> - <action id="org.manjaro.pkexec.pacman_mirrors"> - <message gettext-domain="pacman-mirrors">Authentication is required to run pacman-mirrors</message> - <description>Run pacman-mirrors as Administrator</description> - <defaults> - <allow_any>auth_admin</allow_any> - <allow_inactive>auth_admin</allow_inactive> - <allow_active>auth_admin</allow_active> - </defaults> - <annotate key="org.freedesktop.policykit.exec.path">/usr/bin/pacman_mirrors</annotate> - <annotate key="org.freedesktop.policykit.exec.allow_gui">true</annotate> - </action> -</policyconfig> diff --git a/tests/test_command_line_parse.py b/tests/test_command_line_parse.py index e869d312dd2d75dc75e2a845e1ffbba9eacbbe93..c85c342c0cec79fec1f5b907b3c672c2404fb7a0 100644 --- a/tests/test_command_line_parse.py +++ b/tests/test_command_line_parse.py @@ -10,7 +10,7 @@ Tests for `pacman-mirrors` module. import unittest from unittest.mock import patch -from pacman_mirrors.config import configfn +from pacman_mirrors.functions import configFn from pacman_mirrors.pacman_mirrors import PacmanMirrors from . import mock_configuration as conf @@ -41,7 +41,7 @@ class TestCommandLineParse(unittest.TestCase): pass @patch("os.getuid") - @patch.object(configfn, "build_config") + @patch.object(configFn, "build_config") def test_arg_branch_unstable(self, mock_build_config, mock_os_getuid): """TEST: CLI config[branch] from ARG '-b unstable'""" mock_os_getuid.return_value = 0 @@ -51,12 +51,12 @@ class TestCommandLineParse(unittest.TestCase): "-b", "unstable"]): app = PacmanMirrors() app.config["config_file"] = conf.CONFIG_FILE - app.config = configfn.build_config() + app.config = configFn.build_config() app.command_line_parse() assert app.config["branch"] == "unstable" @patch("os.getuid") - @patch.object(configfn, "build_config") + @patch.object(configFn, "build_config") def test_arg_branch_testing(self, mock_build_config, mock_os_getuid): """TEST: CLI config[branch] from ARG '-b testing'""" mock_os_getuid.return_value = 0 @@ -66,12 +66,12 @@ class TestCommandLineParse(unittest.TestCase): "-b", "testing"]): app = PacmanMirrors() app.config["config_file"] = conf.CONFIG_FILE - app.config = configfn.build_config() + app.config = configFn.build_config() app.command_line_parse() assert app.config["branch"] == "testing" @patch("os.getuid") - @patch.object(configfn, "build_config") + @patch.object(configFn, "build_config") def test_arg_method(self, mock_build_config, mock_os_getuid): """TEST: CLI config[method] from ARG '-m random'""" mock_os_getuid.return_value = 0 @@ -81,12 +81,12 @@ class TestCommandLineParse(unittest.TestCase): "-m", "random"]): app = PacmanMirrors() app.config["config_file"] = conf.CONFIG_FILE - app.config = configfn.build_config() + app.config = configFn.build_config() app.command_line_parse() assert app.config["method"] == "random" @patch("os.getuid") - @patch.object(configfn, "build_config") + @patch.object(configFn, "build_config") def test_arg_onlycountry(self, mock_build_config, mock_os_getuid): """TEST: CLI config[only_country] from ARG '-c France,Germany'""" mock_os_getuid.return_value = 0 @@ -96,12 +96,12 @@ class TestCommandLineParse(unittest.TestCase): "-c", "France,Germany"]): app = PacmanMirrors() app.config["config_file"] = conf.CONFIG_FILE - app.config = configfn.build_config() + app.config = configFn.build_config() app.command_line_parse() assert app.config["country_pool"] == ["France", "Germany"] @patch("os.getuid") - @patch.object(configfn, "build_config") + @patch.object(configFn, "build_config") def test_arg_geoip(self, mock_build_config, mock_os_getuid): """TEST: CLI geoip is True from ARG '--geoip'""" mock_os_getuid.return_value = 0 @@ -111,12 +111,12 @@ class TestCommandLineParse(unittest.TestCase): "--geoip"]): app = PacmanMirrors() app.config["config_file"] = conf.CONFIG_FILE - app.config = configfn.build_config() + app.config = configFn.build_config() app.command_line_parse() assert app.geoip is True @patch("os.getuid") - @patch.object(configfn, "build_config") + @patch.object(configFn, "build_config") def test_arg_fasttrack(self, mock_build_config, mock_os_getuid): """TEST: CLI fasttrack is 5 from ARG '-f 5'""" mock_os_getuid.return_value = 0 @@ -126,12 +126,12 @@ class TestCommandLineParse(unittest.TestCase): "-f5"]): app = PacmanMirrors() app.config["config_file"] = conf.CONFIG_FILE - app.config = configfn.build_config() + app.config = configFn.build_config() app.command_line_parse() assert app.fasttrack == 5 @patch("os.getuid") - @patch.object(configfn, "build_config") + @patch.object(configFn, "build_config") def test_arg_interactive(self, mock_build_config, mock_os_getuid): """TEST: CLI interactive is true from ARG '-i'""" mock_os_getuid.return_value = 0 @@ -141,12 +141,12 @@ class TestCommandLineParse(unittest.TestCase): "-i"]): app = PacmanMirrors() app.config["config_file"] = conf.CONFIG_FILE - app.config = configfn.build_config() + app.config = configFn.build_config() app.command_line_parse() assert app.interactive is True @patch("os.getuid") - @patch.object(configfn, "build_config") + @patch.object(configFn, "build_config") def test_arg_max_wait_time(self, mock_build_config, mock_os_getuid): """TEST: CLI max_wait_time is 5 from ARG '-t 5'""" mock_os_getuid.return_value = 0 @@ -156,12 +156,12 @@ class TestCommandLineParse(unittest.TestCase): "-t5"]): app = PacmanMirrors() app.config["config_file"] = conf.CONFIG_FILE - app.config = configfn.build_config() + app.config = configFn.build_config() app.command_line_parse() assert app.max_wait_time == 5 @patch("os.getuid") - @patch.object(configfn, "build_config") + @patch.object(configFn, "build_config") def test_arg_quiet(self, mock_build_config, mock_os_getuid): """TEST: CLI quiet is True from ARG '-q'""" mock_os_getuid.return_value = 0 @@ -171,7 +171,7 @@ class TestCommandLineParse(unittest.TestCase): "-q"]): app = PacmanMirrors() app.config["config_file"] = conf.CONFIG_FILE - app.config = configfn.build_config() + app.config = configFn.build_config() app.command_line_parse() assert app.quiet is True diff --git a/tests/test_default_config.py b/tests/test_default_config.py index 3b8c13c199d6d31e38517404b1f564382ae65efb..7efe373bd66aeb1a3f777030371469682dffaed1 100644 --- a/tests/test_default_config.py +++ b/tests/test_default_config.py @@ -10,7 +10,7 @@ Tests for `pacman-mirrors` module. import unittest from unittest.mock import patch -from pacman_mirrors.config import configfn +from pacman_mirrors.functions import configFn from pacman_mirrors.pacman_mirrors import PacmanMirrors from . import mock_configuration as conf @@ -42,7 +42,7 @@ class TestDefaultConfig(unittest.TestCase): pass @patch("os.getuid") - @patch.object(configfn, "build_config") + @patch.object(configFn, "build_config") def test_default_branch(self, mock_build_config, mock_os_getuid): """TEST: config[branch] = stable""" mock_os_getuid.return_value = 0 @@ -52,11 +52,11 @@ class TestDefaultConfig(unittest.TestCase): "-f1"]): app = PacmanMirrors() app.config["config_file"] = conf.CONFIG_FILE - app.config = configfn.build_config() + app.config = configFn.build_config() assert app.config["branch"] == "stable" @patch("os.getuid") - @patch.object(configfn, "build_config") + @patch.object(configFn, "build_config") def test_default_method(self, mock_build_config, mock_os_getuid): """TEST: config[method] = rank""" mock_os_getuid.return_value = 0 @@ -66,11 +66,11 @@ class TestDefaultConfig(unittest.TestCase): "-f1"]): app = PacmanMirrors() app.config["config_file"] = conf.CONFIG_FILE - app.config = configfn.build_config() + app.config = configFn.build_config() assert app.config["method"] == "rank" @patch("os.getuid") - @patch.object(configfn, "build_config") + @patch.object(configFn, "build_config") def test_default_mirrordir(self, mock_build_config, mock_os_getuid): """TEST: config[mirror_dir] = tests/mock/var/""" mock_os_getuid.return_value = 0 @@ -79,11 +79,11 @@ class TestDefaultConfig(unittest.TestCase): ["pacman-mirrors", "-f1"]): app = PacmanMirrors() - app.config = configfn.build_config() + app.config = configFn.build_config() assert app.config["work_dir"] == "tests/mock/var/" @patch("os.getuid") - @patch.object(configfn, "build_config") + @patch.object(configFn, "build_config") def test_default_mirrorfile(self, mock_build_config, mock_os_getuid): """TEST: config[mirror_file] = tests/mock/usr/mirrors.json""" mock_os_getuid.return_value = 0 @@ -92,11 +92,11 @@ class TestDefaultConfig(unittest.TestCase): ["pacman-mirrors", "-f1"]): app = PacmanMirrors() - app.config = configfn.build_config() + app.config = configFn.build_config() assert app.config["mirror_file"] == "tests/mock/usr/mirrors.json" @patch("os.getuid") - @patch.object(configfn, "build_config") + @patch.object(configFn, "build_config") def test_default_mirrorlist(self, mock_build_config, mock_os_getuid): """TEST: config[mirror_list] = tests/mock/etc/mirrorlist""" mock_os_getuid.return_value = 0 @@ -105,11 +105,11 @@ class TestDefaultConfig(unittest.TestCase): ["pacman-mirrors", "-f1"]): app = PacmanMirrors() - app.config = configfn.build_config() + app.config = configFn.build_config() assert app.config["mirror_list"] == "tests/mock/etc/mirrorlist" @patch("os.getuid") - @patch.object(configfn, "build_config") + @patch.object(configFn, "build_config") def test_default_noupdate(self, mock_build_config, mock_os_getuid): """TEST: config[no_update] = False""" mock_os_getuid.return_value = 0 @@ -118,11 +118,11 @@ class TestDefaultConfig(unittest.TestCase): ["pacman-mirrors", "-f1"]): app = PacmanMirrors() - app.config = configfn.build_config() + app.config = configFn.build_config() assert app.config["no_update"] is False @patch("os.getuid") - @patch.object(configfn, "build_config") + @patch.object(configFn, "build_config") def test_default_onlycountry(self, mock_build_config, mock_os_getuid): """TEST: config[only_country] = []""" mock_os_getuid.return_value = 0 @@ -132,7 +132,7 @@ class TestDefaultConfig(unittest.TestCase): "-f1"]): app = PacmanMirrors() app.config["config_file"] = conf.CONFIG_FILE - app.config = configfn.build_config() + app.config = configFn.build_config() assert app.config["country_pool"] == [] def tearDown(self): diff --git a/tests/test_httpfn.py b/tests/test_httpfn.py index 049414b30244ac7ddbea525d52aa80bf2cdb608d..14453031df472b011c21938038c0ce50d9aaa5ca 100644 --- a/tests/test_httpfn.py +++ b/tests/test_httpfn.py @@ -10,28 +10,27 @@ Tests for `pacman-mirrors` module. import unittest from unittest.mock import patch -from pacman_mirrors.config import configfn -from pacman_mirrors.functions import httpfn +from pacman_mirrors.functions import httpFn, configFn from pacman_mirrors.pacman_mirrors import PacmanMirrors -from . import mock_configuration as conf +from . import mock_configuration as mock test_conf = { "branch": "stable", - "branches": conf.BRANCHES, - "config_file": conf.CONFIG_FILE, - "custom_file": conf.CUSTOM_FILE, + "branches": mock.BRANCHES, + "config_file": mock.CONFIG_FILE, + "custom_file": mock.CUSTOM_FILE, "method": "rank", - "work_dir": conf.WORK_DIR, - "mirror_file": conf.MIRROR_FILE, - "mirror_list": conf.MIRROR_LIST, + "work_dir": mock.WORK_DIR, + "mirror_file": mock.MIRROR_FILE, + "mirror_list": mock.MIRROR_LIST, "no_update": False, "country_pool": [], "protocols": [], - "repo_arch": conf.REPO_ARCH, - "status_file": conf.STATUS_FILE, + "repo_arch": mock.REPO_ARCH, + "status_file": mock.STATUS_FILE, "ssl_verify": True, - "url_mirrors_json": conf.URL_MIRROR_JSON, - "url_status_json": conf.URL_STATUS_JSON + "url_mirrors_json": mock.URL_MIRROR_JSON, + "url_status_json": mock.URL_STATUS_JSON } @@ -42,28 +41,28 @@ class TestHttpFn(unittest.TestCase): pass @patch("os.getuid") - @patch.object(httpfn, "get_geoip_country") - @patch.object(configfn, "build_config") + @patch.object(httpFn, "get_geoip_country") + @patch.object(configFn, "build_config") def test_geoip_available(self, mock_build_config, mock_get_geoip_country, mock_os_getuid): """TEST: Geoip country IS avaiable""" mock_os_getuid.return_value = 0 - mock_get_geoip_country.return_value = "France" mock_build_config.return_value = test_conf + mock_get_geoip_country.return_value = ["Denmark"] with unittest.mock.patch("sys.argv", ["pacman-mirrors", "--geoip"]): app = PacmanMirrors() - app.config = configfn.build_config() + app.config = configFn.build_config() app.command_line_parse() app.load_all_mirrors() - assert app.selected_countries == ["France"] + assert app.selected_countries == ["Denmark"] @patch("os.getuid") - @patch.object(httpfn, "get_geoip_country") - @patch.object(configfn, "build_config") + @patch.object(httpFn, "get_geoip_country") + @patch.object(configFn, "build_config") def test_geoip_not_available(self, mock_build_config, mock_get_geoip_country, @@ -76,7 +75,7 @@ class TestHttpFn(unittest.TestCase): ["pacman-mirrors", "--geoip"]): app = PacmanMirrors() - app.config = configfn.build_config() + app.config = configFn.build_config() app.command_line_parse() app.load_all_mirrors() assert app.selected_countries == app.mirrors.country_pool diff --git a/tests/test_pacman_mirrors.py b/tests/test_pacman_mirrors.py index 3a09d661a568ca077089517c1e563fb457ec69db..6d6acfae1badba9adc8e406df4025fb3ebe792a0 100644 --- a/tests/test_pacman_mirrors.py +++ b/tests/test_pacman_mirrors.py @@ -9,9 +9,8 @@ Tests for `pacman-mirrors` module. import unittest from unittest.mock import patch -from pacman_mirrors.config import configfn -from pacman_mirrors.functions import filefn -from pacman_mirrors.functions import httpfn +from pacman_mirrors.functions import fileFn, configFn +from pacman_mirrors.functions import httpFn from pacman_mirrors.pacman_mirrors import PacmanMirrors from . import mock_configuration as conf @@ -42,7 +41,7 @@ class TestPacmanMirrors(unittest.TestCase): pass @patch("os.getuid") - @patch.object(configfn, "build_config") + @patch.object(configFn, "build_config") def test_full_run_fasttrack(self, mock_build_config, mock_os_getuid): @@ -53,15 +52,15 @@ class TestPacmanMirrors(unittest.TestCase): ["pacman-mirrors", "-f5"]): app = PacmanMirrors() - app.config = configfn.build_config() - filefn.create_dir(test_conf["work_dir"]) + app.config = configFn.build_config() + fileFn.create_dir(test_conf["work_dir"]) app.command_line_parse() - httpfn.update_mirrors(app.config) + httpFn.update_mirrors(app.config) app.load_all_mirrors() app.build_fasttrack_mirror_list(app.fasttrack) @patch("os.getuid") - @patch.object(configfn, "build_config") + @patch.object(configFn, "build_config") def test_full_run_random(self, mock_build_config, mock_os_getuid): @@ -73,15 +72,15 @@ class TestPacmanMirrors(unittest.TestCase): "-c", "all", "-m", "random"]): app = PacmanMirrors() - app.config = configfn.build_config() - filefn.create_dir(test_conf["work_dir"]) + app.config = configFn.build_config() + fileFn.create_dir(test_conf["work_dir"]) app.command_line_parse() - httpfn.update_mirrors(app.config) + httpFn.update_mirrors(app.config) app.load_all_mirrors() app.build_common_mirror_list() @patch("os.getuid") - @patch.object(configfn, "build_config") + @patch.object(configFn, "build_config") def test_full_run_rank(self, mock_build_config, mock_os_getuid): @@ -92,10 +91,10 @@ class TestPacmanMirrors(unittest.TestCase): ["pacman-mirrors", "-c", "all"]): app = PacmanMirrors() - app.config = configfn.build_config() - filefn.create_dir(test_conf["work_dir"]) + app.config = configFn.build_config() + fileFn.create_dir(test_conf["work_dir"]) app.command_line_parse() - httpfn.update_mirrors(app.config) + httpFn.update_mirrors(app.config) app.load_all_mirrors() app.build_common_mirror_list()