Added checking internet connection

This commit is contained in:
Dimitris Zlatanidis 2017-10-01 18:05:36 +02:00
parent 2aaaac8497
commit c13fd993b0
2 changed files with 18 additions and 0 deletions

View file

@ -2,6 +2,9 @@
Fixed: TypeError: stat() argument 1 must be encoded string without null bytes, Fixed: TypeError: stat() argument 1 must be encoded string without null bytes,
not str #100 not str #100
Added:
- Checkng for the internet connection before downloading files
3.2.9 - 24/09/2017 3.2.9 - 24/09/2017
Fixed: Fixed:
- Strange dependency problem #97 - Strange dependency problem #97

View file

@ -23,6 +23,7 @@
import os import os
import urllib2
import tarfile import tarfile
import subprocess import subprocess
@ -45,6 +46,7 @@ class Download(object):
self.dir_prefix = "" self.dir_prefix = ""
self.downder = self.meta.downder self.downder = self.meta.downder
self.downder_options = self.meta.downder_options self.downder_options = self.meta.downder_options
self._internet_check()
def start(self): def start(self):
"""Download files using wget or other downloader. """Download files using wget or other downloader.
@ -120,3 +122,16 @@ class Download(object):
self.downder_options += certificate self.downder_options += certificate
if not self.msg.answer() in ["y", "Y"]: if not self.msg.answer() in ["y", "Y"]:
raise SystemExit() raise SystemExit()
def _internet_check(self):
"""Check for internet connection
"""
url = "".join(self.url)
try:
f = urllib2.urlopen(url)
return f.read()
except (urllib2.URLError, ValueError):
print("\n{0}slpkg: Error: unable to resolve the internet connection"
"{1}\n".format(self.meta.color["RED"],
self.meta.color["ENDC"]))
raise SystemExit()