From 8e15877cc493d6834443976f802d0fe7583e0e95 Mon Sep 17 00:00:00 2001 From: Huluti <hugo.posnic@protonmail.com> Date: Fri, 3 Feb 2017 20:30:16 +0100 Subject: [PATCH] Revert 6e6c71ac0c80bda01bc20a4e806a6809bbeb94b1 --- docs/index.md | 2 +- pacman_mirrors/pacman_mirrors.py | 64 ++++++++++++++++---------------- pacman_mirrors/txt.py | 2 +- tests/test_pacman_mirrors.py | 8 ++-- 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/docs/index.md b/docs/index.md index 1b2087ce..636db274 100644 --- a/docs/index.md +++ b/docs/index.md @@ -23,7 +23,7 @@ Choose the branch to use: - testing - unstable -`-c [countries]`, `--countries [countries]` +`-c [country]`, `--country [country]` Choose the country to use: - all diff --git a/pacman_mirrors/pacman_mirrors.py b/pacman_mirrors/pacman_mirrors.py index 2c76275c..27179e54 100755 --- a/pacman_mirrors/pacman_mirrors.py +++ b/pacman_mirrors/pacman_mirrors.py @@ -111,9 +111,9 @@ class PacmanMirrors: type=str, choices=["stable", "testing", "unstable"], help=txt.HLP_ARG_BRANCH) - parser.add_argument("-c", "--countries", + parser.add_argument("-c", "--country", type=str, - help=txt.HLP_ARG_COUNTRIES) + help=txt.HLP_ARG_COUNTRY) parser.add_argument("--geoip", action="store_true", help=txt.HLP_ARG_GEOIP_P1 + txt.OPT_COUNTRY + @@ -176,16 +176,16 @@ class PacmanMirrors: if args.geoip: self.geolocation = True - if args.countries: - countries = args.countries.split(",") - if countries == ["Custom"]: - self.config["only_countries"] = countries - elif countries == ["all"]: - self.config["only_countries"] = [] + if args.country: + country = args.country.split(",") + if country == ["Custom"]: + self.config["only_country"] = country + elif country == ["all"]: + self.config["only_country"] = [] else: try: - self.validate_country_list(countries, self.available_countries) - self.config["only_countries"] = countries + self.validate_country_list(country, self.available_countries) + self.config["only_country"] = country except argparse.ArgumentTypeError as err: parser.error(err) @@ -215,7 +215,7 @@ class PacmanMirrors: config = { "branch": "stable", "method": "rank", - "only_countries": [], + "only_country": [], "mirror_dir": "/etc/pacman.d/mirrors", "mirror_list": "/etc/pacman.d/mirrorlist", "no_update": False, @@ -238,7 +238,7 @@ class PacmanMirrors: elif key == "Branch": config["branch"] = value elif key == "OnlyCountry": - config["only_countries"] = value.split(",") + config["only_country"] = value.split(",") elif key == "MirrorlistsDir": config["mirror_dir"] = value elif key == "OutputMirrorlist": @@ -296,8 +296,8 @@ class PacmanMirrors: print(txt.NEWLINE + txt.DCS + txt.INF_INTERACTIVE_LIST) print("--------------------------") - # restore self.config["only_countries"] to "Custom" - self.config["only_countries"] = ["Custom"] + # restore self.config["only_country"] to "Custom" + self.config["only_country"] = ["Custom"] self.output_custom_mirror_file(server_list) self.output_mirror_list(server_list, write_file=True) # modify configuration to use custom @@ -309,40 +309,40 @@ class PacmanMirrors: """ Generate a list of servers - It will only use mirrors defined in only_countries, and if empty will + It will only use mirrors defined in only_country, and if empty will use all mirrors. """ - if self.config["only_countries"]: - if self.config["only_countries"] == ["Custom"]: + if self.config["only_country"]: + if self.config["only_country"] == ["Custom"]: if os.path.isfile(self.custom_mirror_file): - self.config["only_countries"] = [self.custom_mirror_file] + self.config["only_country"] = [self.custom_mirror_file] else: print(txt.WARN + txt.SEP + txt.INF_CUSTOM_MIRROR_FILE + " '{path}' ".format(path=self.custom_mirror_file) + txt.INF_DOES_NOT_EXIST) print(txt.NEWLINE) - self.config["only_countries"] = [] - elif self.config["only_countries"] == ["all"]: - self.config["only_countries"] = [] + self.config["only_country"] = [] + elif self.config["only_country"] == ["all"]: + self.config["only_country"] = [] - if not self.config["only_countries"]: + if not self.config["only_country"]: if self.geolocation: geoip_country = self.get_geoip_country() if geoip_country and geoip_country in self.available_countries: - self.config["only_countries"] = [geoip_country] + self.config["only_country"] = [geoip_country] else: - self.config["only_countries"] = self.available_countries + self.config["only_country"] = self.available_countries else: - self.config["only_countries"] = self.available_countries + self.config["only_country"] = self.available_countries if self.config["method"] == "rank": - self.query_servers(self.config["only_countries"]) + self.query_servers(self.config["only_country"]) elif self.config["method"] == "random": - self.random_servers(self.config["only_countries"]) + self.random_servers(self.config["only_country"]) def modify_config(self): """Modify configuration""" - if self.config["only_countries"] == self.available_countries: + if self.config["only_country"] == self.available_countries: # default self.config_set_default(self.config_file) # remove obsolete custom mirror file @@ -352,7 +352,7 @@ class PacmanMirrors: else: # custom self.config_set_custom( - self.config_file, self.config["only_countries"]) + self.config_file, self.config["only_country"]) def output_custom_mirror_file(self, servers): """Write a custom mirror file in custom mirror dir""" @@ -524,13 +524,13 @@ class PacmanMirrors: shuffle(self.bad_servers) @staticmethod - def config_set_custom(config_file, config_only_countries): + def config_set_custom(config_file, config_only_country): """Use custom configuration""" - for country in config_only_countries: + for country in config_only_country: if "Custom" in country: # country is full path country = "Custom" # must change to Custom country_list = ("OnlyCountry = {list}\n").format( - list=",".join(config_only_countries)) + list=",".join(config_only_country)) try: with open(config_file) as cnf, tempfile.NamedTemporaryFile( "w+t", dir=os.path.dirname(config_file), diff --git a/pacman_mirrors/txt.py b/pacman_mirrors/txt.py index 537c7f7c..3c1dcf48 100644 --- a/pacman_mirrors/txt.py +++ b/pacman_mirrors/txt.py @@ -43,7 +43,7 @@ FILE = _("FILE") SECONDS = _("SECONDS") # help messages HLP_ARG_BRANCH = _("Branch name") -HLP_ARG_COUNTRIES = _( +HLP_ARG_COUNTRY = _( "Comma separated list of countries, from which mirrors will be used") HLP_ARG_FILE = _("Output file") HLP_ARG_GENERATE = _("Generate mirrorlist") diff --git a/tests/test_pacman_mirrors.py b/tests/test_pacman_mirrors.py index 9ac37368..11df6fe8 100755 --- a/tests/test_pacman_mirrors.py +++ b/tests/test_pacman_mirrors.py @@ -44,7 +44,7 @@ class TestPacmanMirrors(unittest.TestCase): app = pacman_mirrors.PacmanMirrors() app.command_line_parse() app.load_server_lists() - assert app.config["only_countries"] == ["Germany"] + assert app.config["only_country"] == ["Germany"] @patch("os.getuid") @patch.object(pacman_mirrors.PacmanMirrors, "get_geoip_country") @@ -61,7 +61,7 @@ class TestPacmanMirrors(unittest.TestCase): app = pacman_mirrors.PacmanMirrors() app.command_line_parse() app.load_server_lists() - assert app.config["only_countries"] == ["France"] + assert app.config["only_country"] == ["France"] @patch("os.getuid") @patch.object(pacman_mirrors.PacmanMirrors, "get_geoip_country") @@ -76,10 +76,10 @@ class TestPacmanMirrors(unittest.TestCase): "-m", "random", "-d", "data/mirrors"]): app = pacman_mirrors.PacmanMirrors() - app.config["only_countries"] = [] + app.config["only_country"] = [] app.command_line_parse() app.load_server_lists() - assert app.config["only_countries"] == app.available_countries + assert app.config["only_country"] == app.available_countries def tearDown(self): pass -- GitLab