Skip to content

Commit

Permalink
Alert the user and don't try to run if no internet connection
Browse files Browse the repository at this point in the history
  • Loading branch information
laurelmay committed Dec 27, 2017
1 parent 62e02ae commit e522f88
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion roles/task-shortcuts/files/uug-ansible-wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import gi
import os
import platform
import socket
import subprocess
import sys
gi.require_version('Gtk', '3.0')
Expand All @@ -35,6 +36,7 @@
def main():
# Set the url, release, and user config ahead of showing the window so
# they can be displayed in labels

parse_user_config()
global url
url = get_remote_url()
Expand Down Expand Up @@ -152,8 +154,18 @@ def on_run_clicked(self, button):
"""Begins the process of running the command in the VTE and disables
the run and cancel buttons so that they cannot be used while the
command is running"""
if not is_online():
no_internet_msg = "It appears that you are not able to access" \
" the Internet. This tools requires that you" \
" be online please check your settings and try" \
" again"
show_dialog(self, Gtk.MessageType.ERROR, Gtk.ButtonsType.CANCEL,
"No Internet connection", no_internet_msg)
return

if not validate_branch(release, url):
invalid_branch(self, release, url)
return

gksudo_msg = "<b>Enter your password to configure your VM</b>" \
"\nTo configure your virtual machine, administrator" \
Expand Down Expand Up @@ -279,7 +291,7 @@ def invalid_branch(parent, release, url):
" release listed above" % (release, url, url)
show_dialog(parent, Gtk.MessageType.ERROR, Gtk.ButtonsType.CANCEL,
"Invalid Release", bad_branch_msg)
Gtk.main_quit()
return


def unable_to_detect_branch():
Expand All @@ -298,5 +310,19 @@ def unable_to_detect_branch():
release = "master"


def is_online():
# Since the user will probably be pulling a significant amount of data
# from this host, it should be a decent host to use to check connectivity
test_hostname = "packages.linuxmint.com"
try:
host = socket.gethostbyname(test_hostname)
s = socket.create_connection((host, 80), 2)
s.close()
return True
except: # noqa
pass
return False


if __name__ == "__main__":
main()

0 comments on commit e522f88

Please sign in to comment.