Skip to content
Snippets Groups Projects
Commit a1b89b77 authored by Frede H's avatar Frede H :speech_balloon:
Browse files

fix issue #111

parent 564e8c29
No related branches found
No related tags found
No related merge requests found
...@@ -20,13 +20,18 @@ Pacman-mirrors requires access to files which are read-only ...@@ -20,13 +20,18 @@ Pacman-mirrors requires access to files which are read-only
so it must be run with su or sudo. so it must be run with su or sudo.
To create a up-to-date mirrorlist using all default use, To create a up-to-date mirrorlist using all default use,
pacman-mirrors --fasttrack 10 --sync pacman-mirrors --fasttrack 10 && sudo pacman -Syy
The mirrorlist generation process can be refined through arguments The mirrorlist generation process can be refined through arguments
and arguments with options, for example, and arguments with options, for example,
pacman-mirrors --country Denmark --timeout 5 pacman-mirrors --country Denmark --timeout 5
## IMPORTANT
After all operations **ALWAYS** syncronize your pacman database with
sudo pacman -Syy
# OPTIONS # OPTIONS
Some options are mutual exclusive and will throw an arguments error: Some options are mutual exclusive and will throw an arguments error:
...@@ -57,12 +62,9 @@ The arguments can appear in any order except for arguments which takes ...@@ -57,12 +62,9 @@ The arguments can appear in any order except for arguments which takes
additional options in which case the options must follow additional options in which case the options must follow
immediately after the argument, for example immediately after the argument, for example
pacman-mirrors -ayidS unstable pacman-mirrors -aidS unstable
## METHODS ## METHODS
-g, \--generate
: Generate a new default mirrorlist using defaults
-f, \--fasttrack *NUMBER* -f, \--fasttrack *NUMBER*
: Generates an up-to-date mirrorlist for the users current branch, : Generates an up-to-date mirrorlist for the users current branch,
mirrors are randomly selected from <http://repo.manjaro.org/status.json>, mirrors are randomly selected from <http://repo.manjaro.org/status.json>,
...@@ -139,9 +141,6 @@ immediately after the argument, for example ...@@ -139,9 +141,6 @@ immediately after the argument, for example
-v, \--version -v, \--version
: Show the version of pacman-mirrors : Show the version of pacman-mirrors
-y, \--sync
: Instruct pacman-mirrors to syncronize the pacman database
## Exit status: ## Exit status:
0 : OK 0 : OK
...@@ -199,27 +198,27 @@ of editing your pacman-mirrors configuration. ...@@ -199,27 +198,27 @@ of editing your pacman-mirrors configuration.
*sudo pacman-mirrors -l* *sudo pacman-mirrors -l*
* I want to temporary change branch to unstable, * I want to temporary change branch to unstable,
use geolocation and syncronize pacman, use geolocation,
*sudo pacman-mirrors -yb unstable --geoip* *sudo pacman-mirrors -b unstable --geoip*
* I want to permanently change branch to unstable, * I want to permanently change branch to unstable,
use mirrors from Germany and France, use mirrors from Germany and France,
use only https and http protocol in that order and syncronize pacman use only https and http protocol in that order
*sudo pacman-mirrors -yac Germany,France -S unstable -P https http* *sudo pacman-mirrors -ac Germany,France -S unstable -P https http*
* Create a mirrorlist with German mirrors and syncronize pacman * Create a mirrorlist with German mirrors
*sudo pacman-mirrors -yc Germany* *sudo pacman-mirrors -c Germany*
* If you want more countries in your mirrorlist add them * If you want more countries in your mirrorlist add them
*sudo pacman-mirrors -yc Germany France Denmark* *sudo pacman-mirrors -c Germany France Denmark*
* Create a mirrorlist with 5 mirrors with current packages and syncronize pacman * Create a mirrorlist with 5 mirrors up-to-date on your branch
*sudo pacman-mirrors -yf 5* *sudo pacman-mirrors -f 5*
* I want to choose my mirrors * I want to choose my mirrors
......
...@@ -322,7 +322,7 @@ class PacmanMirrors: ...@@ -322,7 +322,7 @@ class PacmanMirrors:
apifn.write_protocols(self.config["protocols"], apifn.write_protocols(self.config["protocols"],
self.config["config_file"], self.config["config_file"],
quiet=self.quiet) quiet=self.quiet)
# Fifth API taks: Rebranch the mirrorlist # Fifth API task: Rebranch the mirrorlist
if re_branch: if re_branch:
if not set_branch: if not set_branch:
print(".: {} {}".format(txt.ERR_CLR, txt.API_ERROR_BRANCH)) print(".: {} {}".format(txt.ERR_CLR, txt.API_ERROR_BRANCH))
...@@ -403,21 +403,24 @@ class PacmanMirrors: ...@@ -403,21 +403,24 @@ class PacmanMirrors:
* Modify the configuration file to use the "custom" file. * Modify the configuration file to use the "custom" file.
* Outputs a pacman mirrorlist, * Outputs a pacman mirrorlist,
""" """
# TODO: build_interactive_mirror_list needs refactoring
worklist = mirrorfn.filter_mirror_country(self.mirrors.mirrorlist, worklist = mirrorfn.filter_mirror_country(self.mirrors.mirrorlist,
self.selected_countries) self.selected_countries)
# leave only the user selected protocols
if self.config["protocols"]: if self.config["protocols"]:
worklist = mirrorfn.filter_mirror_protocols( worklist = mirrorfn.filter_mirror_protocols(
worklist, self.config["protocols"]) worklist, self.config["protocols"])
# rank or shuffle the mirrorlist before showing the ui
if not self.default: if not self.default:
# filter not up-to-date mirrors for selected branch
# worklist = self.filter_user_branch(worklist)
if self.config["method"] == "rank": if self.config["method"] == "rank":
worklist = self.test_mirrors(worklist) worklist = self.test_mirrors(worklist)
worklist = sorted(worklist, key=itemgetter("resp_time")) worklist = sorted(worklist, key=itemgetter("resp_time"))
else: else:
shuffle(worklist) shuffle(worklist)
interactive_list = [] interactive_list = []
# create a list for display in ui
for mirror in worklist: for mirror in worklist:
# create an entry for all protocols related to a mirror
for protocol in enumerate(mirror["protocols"]): for protocol in enumerate(mirror["protocols"]):
pos = mirror["url"].find(":") pos = mirror["url"].find(":")
interactive_list.append({ interactive_list.append({
...@@ -426,6 +429,7 @@ class PacmanMirrors: ...@@ -426,6 +429,7 @@ class PacmanMirrors:
"last_sync": mirror["last_sync"], "last_sync": mirror["last_sync"],
"url": "{}{}".format(protocol[1], mirror["url"][pos:]) "url": "{}{}".format(protocol[1], mirror["url"][pos:])
}) })
# import the right ui
if self.no_display: if self.no_display:
from . import consoleui as ui from . import consoleui as ui
else: else:
...@@ -433,24 +437,37 @@ class PacmanMirrors: ...@@ -433,24 +437,37 @@ class PacmanMirrors:
interactive = ui.run(interactive_list, interactive = ui.run(interactive_list,
self.config["method"] == "random", self.config["method"] == "random",
self.default) self.default)
# process user choices
if interactive.is_done: if interactive.is_done:
mirror_list = [] # written to mirrorlist mirror_list = [] # written to mirrorlist
mirror_file = [] # written to custom-mirror.json mirror_file = [] # written to custom-mirror.json
custom_list = interactive.custom_list custom_list = interactive.custom_list
for item in custom_list: # TODO: refactor needed
ipos = item["url"].find(":") # loop custom list
iurl = item["url"][ipos:] for custom in custom_list:
for server in self.mirrors.mirrorlist: # get url without protocol
spos = server["url"].find(":") c_pos = custom["url"].find(":")
surl = server["url"][spos:] c_url = custom["url"][c_pos:]
if iurl == surl: # locate mirror in the full mirrorlist
for mirror in self.mirrors.mirrorlist:
m_pos = mirror["url"].find(":")
m_url = mirror["url"][m_pos:]
# compare urls
if c_url == m_url:
# mirror file
mirror_file.append({ mirror_file.append({
"country": server["country"], "country": mirror["country"],
"protocols": server["protocols"], "protocols": mirror["protocols"],
"url": server["url"] "url": mirror["url"]
}) })
server["protocols"] = self.config["protocols"] # mirror list
mirror_list.append(server) try:
_ = self.config["protocols"][0]
mirror["protocols"] = self.config["protocols"]
except IndexError:
pass
mirror_list.append(mirror)
# since no ranking/shuffling is done pre loading the ui do post unload
if self.default and mirror_list: if self.default and mirror_list:
if self.config["method"] == "rank": if self.config["method"] == "rank":
mirror_list = self.test_mirrors(mirror_list) mirror_list = self.test_mirrors(mirror_list)
...@@ -458,6 +475,7 @@ class PacmanMirrors: ...@@ -458,6 +475,7 @@ class PacmanMirrors:
key=itemgetter("resp_time")) key=itemgetter("resp_time"))
else: else:
shuffle(mirror_list) shuffle(mirror_list)
# mirror file list is not empty
if mirror_file: if mirror_file:
print("\n.: {} {}".format(txt.INF_CLR, print("\n.: {} {}".format(txt.INF_CLR,
txt.CUSTOM_MIRROR_LIST)) txt.CUSTOM_MIRROR_LIST))
...@@ -490,18 +508,14 @@ class PacmanMirrors: ...@@ -490,18 +508,14 @@ class PacmanMirrors:
def filter_user_branch(self, mirrorlist): def filter_user_branch(self, mirrorlist):
"""Filter mirrorlist on users branch and branch sync state""" """Filter mirrorlist on users branch and branch sync state"""
if self.config["branch"] == "stable": for idx, branch in enumerate(conf.BRANCHES):
selected_branch = 0 if branch == self.config["branch"]:
elif self.config["branch"] == "testing": filtered = []
selected_branch = 1 for mirror in mirrorlist:
else: if mirror["branches"][idx] == 1:
selected_branch = 2 filtered.append(mirror)
filtered = [] if len(filtered) > 0:
for mirror in mirrorlist: return filtered
if mirror["branches"][selected_branch] == 1:
filtered.append(mirror)
if len(filtered) > 0:
return filtered
return mirrorlist return mirrorlist
def output_country_list(self): def output_country_list(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment