Commit b5ab58fc authored by Hugo Posnic's avatar Hugo Posnic Committed by GitHub

Merge pull request #48 from fhdk/fhdk-bugfix

Fhdk bugfix
parents d373169d 9dbb383c
......@@ -40,9 +40,8 @@ from random import shuffle
from socket import timeout
from urllib.error import URLError
from urllib.request import urlopen
from .custom_help_formatter import CustomHelpFormatter
from pacman_mirrors import __version__
from .custom_help_formatter import CustomHelpFormatter
from . import i18n
from . import txt
......@@ -246,10 +245,9 @@ class PacmanMirrors:
elif key == "NoUpdate":
config["no_update"] = value
except (PermissionError, OSError) as err:
print(txt.ERROR + txt.SEP + txt.ERR_FILE_READ + txt.SEP +
"{filename}" + txt.SEP +
"{error}".format(filename=err.filename,
error=err.strerror))
print("{}{}{}{}{}{}{}".format(
txt.ERROR, txt.SEP, txt.ERR_FILE_READ, txt.SEP,
err.filename, txt.SEP, err.strerror))
return config
def generate_mirror_list_common(self):
......@@ -294,16 +292,22 @@ class PacmanMirrors:
if not interactive.is_done:
return
print(txt.NEWLINE + txt.DCS + txt.INF_INTERACTIVE_LIST)
print("--------------------------")
# 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
self.modify_config() # function do self check
print(txt.DCS + txt.INF_INTERACTIVE_LIST_SAVED + txt.SEP +
"{path}".format(path=self.custom_mirror_file))
if server_list:
print(txt.NEWLINE + txt.DCS + txt.INF_INTERACTIVE_LIST)
print("--------------------------")
# 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
self.modify_config() # function do self check
print(txt.DCS + txt.INF_INTERACTIVE_LIST_SAVED + txt.SEP +
"{path}".format(path=self.custom_mirror_file))
else:
print("{}{}{}".format(
txt.INFO, txt.SEP, txt.INF_NO_SELECTION))
print("{}{}{}".format(
txt.INFO, txt.SEP, txt.INF_NO_CHANGES))
def load_server_lists(self):
"""
......@@ -364,9 +368,9 @@ class PacmanMirrors:
for server in servers:
self.write_mirror_list_entry(output, server)
except OSError as err:
print(txt.ERROR + txt.SEP + txt.ERR_FILE_WRITE + txt.SEP +
"{filename}" + txt.SEP +
"{error}".format(filename=err.filename, error=err.strerror))
print("{}{}{}{}{}{}{}".format(
txt.ERROR, txt.SEP, txt.ERR_FILE_WRITE, txt.SEP,
err.filename, txt.SEP, err.strerror))
exit(1)
def output_mirror_list(self, servers, write_file=False):
......@@ -394,10 +398,10 @@ class PacmanMirrors:
"{output_file}"
.format(output_file=self.config["mirror_list"]))
except OSError as err:
print(txt.ERROR + txt.SEP + txt.ERR_FILE_WRITE + txt.SEP +
"{filename}" + txt.SEP +
"{error}".format(
filename=err.filename, error=err.strerror))
print("{}{}{}{}{}{}{}".format(
txt.ERROR, txt.SEP, txt.ERR_FILE_WRITE, txt.SEP,
err.filename, txt.SEP, err.strerror))
exit(1)
def query_servers(self, countries):
......@@ -480,10 +484,9 @@ class PacmanMirrors:
point_in_time, branch_timestamp)
self.append_to_server_list(server, server["last_sync"])
except OSError as err:
print(txt.ERROR + txt.SEP + txt.ERR_FILE_READ + txt.SEP +
"{filename}" + txt.SEP +
"{error}".format(filename=err.filename,
error=err.strerror))
print("{}{}{}{}{}{}{}".format(
txt.ERROR, txt.SEP, txt.ERR_FILE_READ, txt.SEP,
err.filename, txt.SEP, err.strerror))
continue
self.good_servers = sorted(self.good_servers,
key=itemgetter("response_time"))
......@@ -516,10 +519,10 @@ class PacmanMirrors:
"url": m_url}
self.append_to_server_list(server, txt.SERVER_RES)
except OSError as err:
print(txt.ERROR + txt.SEP + txt.ERR_FILE_READ + txt.SEP +
"{filename}" + txt.SEP +
"{error}".format(filename=err.filename,
error=err.strerror))
print("{}{}{}{}{}{}{}".format(
txt.ERROR, txt.SEP, txt.ERR_FILE_READ, txt.SEP,
err.filename, txt.SEP, err.strerror))
continue
shuffle(self.bad_servers)
......@@ -549,10 +552,10 @@ class PacmanMirrors:
os.chmod(config_file, 0o644)
except OSError as err:
print(txt.ERROR + txt.SEP + txt.ERR_FILE_UPDATE + txt.SEP +
"{filename}" + txt.SEP +
"{error}".format(filename=err.filename,
error=err.strerror))
print("{}{}{}{}{}{}{}".format(
txt.ERROR, txt.SEP, txt.ERR_FILE_READ, txt.SEP,
err.filename, txt.SEP, err.strerror))
exit(1)
@staticmethod
......@@ -669,7 +672,7 @@ class PacmanMirrors:
return line[9:]
@staticmethod
def query_mirror_state(url, branch, timeout, quiet):
def query_mirror_state(url, branch, _timeout, quiet):
"""
Get statefile
......@@ -679,7 +682,7 @@ class PacmanMirrors:
content = ""
url = url.replace("$branch/$repo/$arch", branch)
try:
res = urlopen(url + "/state", timeout=timeout)
res = urlopen(url + "/state", timeout=_timeout)
content = res.read().decode("utf8")
except URLError as err:
if hasattr(err, "reason") and not quiet:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment