From 3e07405476ed815ea181504a5d183317c2b1c2f5 Mon Sep 17 00:00:00 2001 From: Valeriy Ryaboshapko Date: Tue, 4 Jan 2022 16:32:44 +0300 Subject: [PATCH 1/3] some refactoring to fix Linux support --- pygeckodriver/__init__.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/pygeckodriver/__init__.py b/pygeckodriver/__init__.py index 966bb74..cda0de8 100755 --- a/pygeckodriver/__init__.py +++ b/pygeckodriver/__init__.py @@ -9,24 +9,21 @@ _BASE_DIR = os.path.dirname(os.path.abspath(__file__)) + def _get_filename(): path = os.path.join(_BASE_DIR, 'geckodriver_') + arch = '64' if platform.machine().endswith('64') else '32' + sys = platform.system() - arch = platform.machine() - file_extension = None if sys == 'Darwin': path += 'macos' + elif sys == 'Windows': + path += 'win{}.exe'.format(arch) + elif sys == 'Linux': + path += 'linux{}'.format(arch) else: - if sys == 'Windows': - path += 'win' - file_extension = ".exe" - elif sys == 'Linux': - path += 'linux' - else: - raise Exception('OS not supported') - path += '64' if arch.endswith('64') else '32' - path += file_extension + raise Exception('OS {} not supported'.format(sys)) if not os.path.exists(path): raise FileNotFoundError('GeckoDriver for {}({}) ' From 8f500104d8992490ce2ef199de72df64bcbf8a93 Mon Sep 17 00:00:00 2001 From: Valeriy Ryaboshapko Date: Tue, 4 Jan 2022 19:33:12 +0300 Subject: [PATCH 2/3] make executable name a bit more explicit --- pygeckodriver/__init__.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pygeckodriver/__init__.py b/pygeckodriver/__init__.py index cda0de8..c1528c9 100755 --- a/pygeckodriver/__init__.py +++ b/pygeckodriver/__init__.py @@ -11,20 +11,19 @@ def _get_filename(): - path = os.path.join(_BASE_DIR, 'geckodriver_') - arch = '64' if platform.machine().endswith('64') else '32' sys = platform.system() if sys == 'Darwin': - path += 'macos' + file_name = 'geckodriver_macos' elif sys == 'Windows': - path += 'win{}.exe'.format(arch) + file_name = 'geckodriver_win{}.exe'.format(arch) elif sys == 'Linux': - path += 'linux{}'.format(arch) + file_name = 'geckodriver_linux{}'.format(arch) else: raise Exception('OS {} not supported'.format(sys)) + path = os.path.join(_BASE_DIR, file_name) if not os.path.exists(path): raise FileNotFoundError('GeckoDriver for {}({}) ' 'is not found.'.format(sys, arch)) From bf551d30cadb2c4f03c9ed0885c86d729491dde6 Mon Sep 17 00:00:00 2001 From: Valeriy Ryaboshapko Date: Tue, 4 Jan 2022 20:55:46 +0300 Subject: [PATCH 3/3] ignore .tar.gz.asc files --- update.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/update.py b/update.py index 0b3f7a4..8989621 100755 --- a/update.py +++ b/update.py @@ -85,7 +85,7 @@ def download_geckodriver(version): or 'win64' in filename: filename += '.exe' - if '.tar.gz' in asset['name']: + if asset['name'].endswith('.tar.gz'): tf = tarfile.open(fileobj=BytesIO(requests.get(url).content)) for f in tf.getnames(): if 'geckodriver' in f: @@ -93,7 +93,7 @@ def download_geckodriver(version): os.rename(os.path.join(DOWNLOAD_DIR, f), \ os.path.join(DOWNLOAD_DIR, filename)) os.chmod(os.path.join(DOWNLOAD_DIR, filename), 0o755) - elif '.gz' in asset['name']: + elif asset['name'].endswith('.gz'): gf = gzip.GzipFile(fileobj=BytesIO(requests.get(url).content)) with open(os.path.join(DOWNLOAD_DIR, filename), 'wb') as f: f.write(gf.read())