From efd4179b7e14f55fe6ed2c2cc5d46689f66e87ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Moreira?= Date: Mon, 20 Apr 2020 10:29:23 -0300 Subject: [PATCH] [improvement] internet availability checking code --- CHANGELOG.md | 5 ++++- bauh/commons/internet.py | 13 ++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f2bf026..48b321a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). -## [0.9.1] +## [0.9.1] 2020 +### Improvements +- Internet availability checking code + ### Fixes - Arch - wrong dialog titles diff --git a/bauh/commons/internet.py b/bauh/commons/internet.py index 9cd86324..e860d831 100644 --- a/bauh/commons/internet.py +++ b/bauh/commons/internet.py @@ -1,13 +1,12 @@ -import subprocess -import traceback -from subprocess import Popen +import http.client as http_client def is_available() -> bool: + conn = http_client.HTTPConnection("www.google.com", timeout=5) try: - res = Popen(['ping', '-q', '-w1', '-c1', 'google.com'], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL) - res.wait() - return res.returncode == 0 + conn.request("HEAD", "/") + conn.close() + return True except: - traceback.print_exc() + conn.close() return False