From c13fd993b0fc6003ef88381048a3d94fd9fda176 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 1 Oct 2017 18:05:36 +0200 Subject: [PATCH] Added checking internet connection --- ChangeLog.txt | 3 +++ slpkg/downloader.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index b41d9319..84bd1d76 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -2,6 +2,9 @@ Fixed: TypeError: stat() argument 1 must be encoded string without null bytes, not str #100 +Added: +- Checkng for the internet connection before downloading files + 3.2.9 - 24/09/2017 Fixed: - Strange dependency problem #97 diff --git a/slpkg/downloader.py b/slpkg/downloader.py index cf75c5b2..611fd301 100644 --- a/slpkg/downloader.py +++ b/slpkg/downloader.py @@ -23,6 +23,7 @@ import os +import urllib2 import tarfile import subprocess @@ -45,6 +46,7 @@ class Download(object): self.dir_prefix = "" self.downder = self.meta.downder self.downder_options = self.meta.downder_options + self._internet_check() def start(self): """Download files using wget or other downloader. @@ -120,3 +122,16 @@ class Download(object): self.downder_options += certificate if not self.msg.answer() in ["y", "Y"]: 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()