diff options
-rw-r--r-- | src/backend/checkenv.py | 13 | ||||
-rw-r--r-- | src/backend/setbranch.py | 23 | ||||
-rw-r--r-- | src/backend/update.py | 51 |
3 files changed, 63 insertions, 24 deletions
diff --git a/src/backend/checkenv.py b/src/backend/checkenv.py index c8152bf..124ba76 100644 --- a/src/backend/checkenv.py +++ b/src/backend/checkenv.py @@ -3,6 +3,19 @@ import os import subprocess import sisyphus.getenv +import urllib.request + + +def connectivity(): + is_online = int() + + try: + urllib.request.urlopen("http://www.google.com", timeout=5) + is_online = int(1) + except urllib.error.URLError: + is_online = int(0) + + return is_online def root(): diff --git a/src/backend/setbranch.py b/src/backend/setbranch.py index ca349f9..7ebd6f7 100644 --- a/src/backend/setbranch.py +++ b/src/backend/setbranch.py @@ -101,15 +101,22 @@ def brch_s_warn(branch, remote): def start(branch, remote): + is_online = sisyphus.checkenv.connectivity() + if sisyphus.checkenv.root(): - sisyphus.purgeenv.branch() - sisyphus.purgeenv.metadata() - ins_g_repo(branch, remote) - ins_r_repo(branch, remote) - ins_p_cfg_repo(branch, remote) - sisyphus.setjobs.start() - sisyphus.setprofile.start() - brch_s_warn(branch, remote) + if is_online == 1: + sisyphus.purgeenv.branch() + sisyphus.purgeenv.metadata() + ins_g_repo(branch, remote) + ins_r_repo(branch, remote) + ins_p_cfg_repo(branch, remote) + sisyphus.setjobs.start() + sisyphus.setprofile.start() + brch_s_warn(branch, remote) + else: + print(sisyphus.getcolor.brigt_red + + "\nNo internet connection; Aborting!\n" + sisyphus.getcolor.reset) + sys.exit() else: print(sisyphus.getcolor.bright_red + "\nYou need root permissions to do this!\n" + sisyphus.getcolor.reset) diff --git a/src/backend/update.py b/src/backend/update.py index 0c25068..40c2ce8 100644 --- a/src/backend/update.py +++ b/src/backend/update.py @@ -31,20 +31,11 @@ def start(gfx_ui=False): actv_brch = sisyphus.getenv.sys_brch() bhst_addr = sisyphus.getenv.bhst_addr() is_sane = sisyphus.checkenv.sanity() + is_online = sisyphus.checkenv.connectivity() - if is_sane == 1: - sync_evrth() - else: - if "packages-next" in bhst_addr: - print(sisyphus.getcolor.green + "\n\nActive branch:" + " " + sisyphus.getcolor.reset + "'" + actv_brch + "'" + " " + "(stable)" + - " " + sisyphus.getcolor.green + "\nActive binhost:" + " " + sisyphus.getcolor.reset + "'" + bhst_addr + "'" + " " + "(testing)") - else: - print(sisyphus.getcolor.green + "\n\nActive branch:" + " " + sisyphus.getcolor.reset + "'" + actv_brch + "'" + " " + "(testing)" + - " " + sisyphus.getcolor.green + "\nActive binhost:" + " " + sisyphus.getcolor.reset + "'" + bhst_addr + "'" + " " + "(stable)") - + if is_online != 1: if gfx_ui: - print("\n\nInvalid configuration!") - print("Use 'sisyphus branch --help' for help\n") + print("\nNo internet connection; Aborting!\n") t = 10 while t > 0: mins, secs = divmod(t, 60) @@ -53,10 +44,38 @@ def start(gfx_ui=False): time.sleep(1) t -= 1 - print('Time is up!') + print("Time is up!") sys.exit() - else: - print(sisyphus.getcolor.bright_red + "\n\nInvalid configuration!" + sisyphus.getcolor.reset + sisyphus.getcolor.bright_yellow + "\nUse" + - sisyphus.getcolor.reset + " " + "'" + "sisyphus branch --help" + "'" + " " + sisyphus.getcolor.bright_yellow + "for help" + sisyphus.getcolor.reset) + print(sisyphus.getcolor.brigt_red + + "\nNo internet connection; Aborting!\n" + sisyphus.getcolor.reset) sys.exit() + else: + if is_sane == 1: + sync_evrth() + else: + if "packages-next" in bhst_addr: + print(sisyphus.getcolor.green + "\n\nActive branch:" + " " + sisyphus.getcolor.reset + "'" + actv_brch + "'" + " " + "(stable)" + + " " + sisyphus.getcolor.green + "\nActive binhost:" + " " + sisyphus.getcolor.reset + "'" + bhst_addr + "'" + " " + "(testing)") + else: + print(sisyphus.getcolor.green + "\n\nActive branch:" + " " + sisyphus.getcolor.reset + "'" + actv_brch + "'" + " " + "(testing)" + + " " + sisyphus.getcolor.green + "\nActive binhost:" + " " + sisyphus.getcolor.reset + "'" + bhst_addr + "'" + " " + "(stable)") + + if gfx_ui: + print("\n\nInvalid configuration!") + print("Use 'sisyphus branch --help' for help\n") + t = 10 + while t > 0: + mins, secs = divmod(t, 60) + timer = '{:02d}:{:02d}'.format(mins, secs) + print(timer, end='\r') + time.sleep(1) + t -= 1 + + print("Time is up!") + sys.exit() + + else: + print(sisyphus.getcolor.bright_red + "\n\nInvalid configuration!" + sisyphus.getcolor.reset + sisyphus.getcolor.bright_yellow + "\nUse" + + sisyphus.getcolor.reset + " " + "'" + "sisyphus branch --help" + "'" + " " + sisyphus.getcolor.bright_yellow + "for help" + sisyphus.getcolor.reset) + sys.exit() |