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

network check so not run mirrortest if missing

parent d6906ade
No related branches found
No related tags found
No related merge requests found
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
"""Pacman-Mirrors Configuration""" """Pacman-Mirrors Configuration"""
# this is for runing in dev environment # this is for runing in dev environment
# TODO: CHANGE BELOW IN PRODUCTION
DEVELOPMENT = "" DEVELOPMENT = ""
DESCRIPTION = "unstable development" DESCRIPTION = "unstable development"
# if DEVELOPMENT: # if DEVELOPMENT:
......
...@@ -81,8 +81,8 @@ class CustomFn: ...@@ -81,8 +81,8 @@ class CustomFn:
try: try:
with open( with open(
filename) as cnf, tempfile.NamedTemporaryFile( filename) as cnf, tempfile.NamedTemporaryFile(
"w+t", dir=os.path.dirname( "w+t", dir=os.path.dirname(
filename), delete=False) as tmp: filename), delete=False) as tmp:
replaced = False replaced = False
for line in cnf: for line in cnf:
if "OnlyCountry" in line: if "OnlyCountry" in line:
......
...@@ -57,7 +57,7 @@ class FileFn: ...@@ -57,7 +57,7 @@ class FileFn:
filename = FALLBACK filename = FALLBACK
if not filename: if not filename:
print("\n{}.:! {}{}\n".format(txt.RS, print("\n{}.:! {}{}\n".format(txt.RS,
"Houston?! we have a problem", txt.HOUSTON,
txt.CE)) txt.CE))
exit(1) exit(1)
result = (filename, status) result = (filename, status)
...@@ -134,16 +134,4 @@ class FileFn: ...@@ -134,16 +134,4 @@ class FileFn:
""" """
workitem = mirror workitem = mirror
handle.write("## Country : {}\n".format(workitem["country"])) handle.write("## Country : {}\n".format(workitem["country"]))
# TODO: approval to remove useless lines
# Commented since the info after a short time
# is no longer valid
if workitem["resp_time"] == txt.SERVER_RES:
workitem["resp_time"] = "N/A"
handle.write("## Response time : {}\n".format(
workitem["resp_time"]))
if workitem["last_sync"] == txt.SERVER_BAD or \
workitem["last_sync"] == txt.LASTSYNC_NA:
workitem["last_sync"] = "N/A"
handle.write("## Last Upd hh:mm: {}\n".format(
workitem["last_sync"]))
handle.write("Server = {}\n\n".format(workitem["url"])) handle.write("Server = {}\n\n".format(workitem["url"]))
...@@ -150,4 +150,6 @@ class HttpFn: ...@@ -150,4 +150,6 @@ class HttpFn:
print(".: {} {} {}".format(txt.WRN_CLR, print(".: {} {} {}".format(txt.WRN_CLR,
txt.FALLING_BACK, txt.FALLING_BACK,
FALLBACK)) FALLBACK))
if not FileFn.check_file(FALLBACK):
print(".: {} {}".format(txt.ERR_CLR, txt.HOUSTON))
return False return False
...@@ -27,4 +27,14 @@ class MiscFn: ...@@ -27,4 +27,14 @@ class MiscFn:
@staticmethod @staticmethod
def debug(where, what, value): def debug(where, what, value):
"""Helper for printing debug messages"""
print("{} In function {} -> '{} = {}'".format(txt.DBG_CLR, where, what, value)) print("{} In function {} -> '{} = {}'".format(txt.DBG_CLR, where, what, value))
@staticmethod
def internet_connection_message(required=False):
"""Message when internet connection is down"""
print(".: {} {}".format(txt.INF_CLR, txt.INTERNET_DOWN))
if required:
print(".: {} {}".format(txt.INF_CLR, txt.INTERNET_REQUIRED))
else:
print(".: {} {}".format(txt.INF_CLR, txt.MIRROR_RANKING_NA))
...@@ -359,18 +359,20 @@ class PacmanMirrors: ...@@ -359,18 +359,20 @@ class PacmanMirrors:
print(".: {} {}".format(txt.INF_CLR, txt.USING_DEFAULT_FILE)) print(".: {} {}".format(txt.INF_CLR, txt.USING_DEFAULT_FILE))
print(".: {} {} - {}".format(txt.INF_CLR, txt.QUERY_MIRRORS, txt.TAKES_TIME)) print(".: {} {} - {}".format(txt.INF_CLR, txt.QUERY_MIRRORS, txt.TAKES_TIME))
for mirror in worklist: if self.network:
if not self.quiet: for mirror in worklist:
print(" ..... {:<15}: {}".format(mirror["country"], if not self.quiet:
mirror["url"]), end='') print(" ..... {:<15}: {}".format(mirror["country"],
# sys.stdout.flush() mirror["url"]), end='')
resp_time = HttpFn.get_mirror_response(mirror["url"], quiet=self.quiet) # sys.stdout.flush()
mirror["resp_time"] = resp_time resp_time = HttpFn.get_mirror_response(mirror["url"], quiet=self.quiet)
if resp_time == txt.SERVER_RES: mirror["resp_time"] = resp_time
continue if resp_time == txt.SERVER_RES:
if not self.quiet: continue
print("\r {:<5}{}{} ".format(txt.GS, resp_time, txt.CE)) if not self.quiet:
return worklist print("\r {:<5}{}{} ".format(txt.GS, resp_time, txt.CE))
return worklist
MiscFn.internet_connection_message()
def run(self): def run(self):
"""Run""" """Run"""
...@@ -385,8 +387,7 @@ class PacmanMirrors: ...@@ -385,8 +387,7 @@ class PacmanMirrors:
if self.network: if self.network:
self.build_fasttrack_mirror_list(self.fasttrack) self.build_fasttrack_mirror_list(self.fasttrack)
else: else:
print(".: {} {}".format(txt.INF_CLR, txt.NETWORK_DOWN)) MiscFn.internet_connection_message(True)
print(".: {} {}".format(txt.INF_CLR, txt.NETWORK_REQUIRED))
else: else:
if self.interactive: if self.interactive:
self.build_interactive_mirror_list() self.build_interactive_mirror_list()
......
...@@ -71,9 +71,10 @@ FALLING_BACK = _("Falling back to") ...@@ -71,9 +71,10 @@ FALLING_BACK = _("Falling back to")
IS_MISSING = _("is missing") IS_MISSING = _("is missing")
MIRROR_FILE = _("The mirror file") MIRROR_FILE = _("The mirror file")
MIRROR_LIST_SAVED = _("Mirrorlist generated and saved to") MIRROR_LIST_SAVED = _("Mirrorlist generated and saved to")
MIRROR_RANKING_NA = _("Mirror ranking is not available")
MUST_BE_ROOT = _("Must have root privileges") MUST_BE_ROOT = _("Must have root privileges")
NETWORK_DOWN = _("Internet connection appears to be down") INTERNET_DOWN = _("Internet connection appears to be down")
NETWORK_NEEDED = _("Internet access is required to proceed") INTERNET_REQUIRED = _("Internet access is required to proceed")
NO_CHANGE = _("The mirror list is not changed") NO_CHANGE = _("The mirror list is not changed")
NO_SELECTION = _("No mirrors in selection") NO_SELECTION = _("No mirrors in selection")
OPTION = _("Option") OPTION = _("Option")
...@@ -101,7 +102,7 @@ I_CONFIRM_SELECTION = _("Confirm selections") ...@@ -101,7 +102,7 @@ I_CONFIRM_SELECTION = _("Confirm selections")
I_USE_THESE_MIRRORS = _("I want to use these mirrors") I_USE_THESE_MIRRORS = _("I want to use these mirrors")
# NON TRANSLATABLE STRINGS # NON TRANSLATABLE STRINGS
HOUSTON = "Houston?! We have a problem."
# mirror status constants # mirror status constants
LASTSYNC_OK = "24:00" # last syncronize in the past 24 hours LASTSYNC_OK = "24:00" # last syncronize in the past 24 hours
LASTSYNC_NA = "98:00" # last syncronization not available LASTSYNC_NA = "98:00" # last syncronization not available
......
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