Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some refactoring to fix Linux support #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions pygeckodriver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions update.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ 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:
tf.extract(f, path=DOWNLOAD_DIR)
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())
Expand Down