diff --git a/pygeckodriver/__init__.py b/pygeckodriver/__init__.py index 966bb74..c1528c9 100755 --- a/pygeckodriver/__init__.py +++ b/pygeckodriver/__init__.py @@ -9,25 +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' + file_name = 'geckodriver_macos' + elif sys == 'Windows': + file_name = 'geckodriver_win{}.exe'.format(arch) + elif sys == 'Linux': + file_name = 'geckodriver_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)) + path = os.path.join(_BASE_DIR, file_name) if not os.path.exists(path): raise FileNotFoundError('GeckoDriver for {}({}) ' 'is not found.'.format(sys, arch)) 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())