Skip to content

Commit

Permalink
Merge pull request #863 from Shopify/python_install_request
Browse files Browse the repository at this point in the history
Remove six lib from install script
  • Loading branch information
Tim Anema authored Dec 3, 2020
2 parents 7841f7a + 02d4935 commit cbbda88
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions docs/scripts/install.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
#!/usr/bin/env python
'''
File name: install.py
File name: install
Author: Tim Anema
Date created: Sep 29, 2016
Date last modified: Nov 19 2020
Date last modified: Dec 3 2020
Python Version: 2.x, 3.x
Description: Install script for themekit. It will download a release and make it executable
'''
import os, json, sys, hashlib

from six.moves.urllib.request import urlopen

class Installer(object):
LATEST_RELEASE_URL = "https://shopify-themekit.s3.amazonaws.com/releases/latest.json"
ARCH_MAPPING = {
Expand All @@ -27,7 +25,7 @@ def __init__(self, path="/usr/local/bin"):
self.bin_path = "%s/theme" % self.install_path
self.arch = self.__getArch()
print("Fetching release data")
self.release = json.loads(urlopen(Installer.LATEST_RELEASE_URL).read().decode("utf-8"))
self.release = json.loads(self.__req(Installer.LATEST_RELEASE_URL).decode("utf-8"))
print("Downloading version %s of Shopify Themekit" % self.release['version'])
self.__download()
print("Theme Kit has been installed at %s" % self.bin_path)
Expand All @@ -49,7 +47,7 @@ def __findReleasePlatform(self):

def __download(self):
platform = self.__findReleasePlatform()
data = urlopen(platform['url']).read()
data = self.__req(platform['url'])
if hashlib.md5(data).hexdigest() != platform['digest']:
sys.exit("Downloaded binary did not match checksum.")
else:
Expand All @@ -60,4 +58,12 @@ def __download(self):
themefile.write(data)
os.chmod(self.bin_path, 0o755)

def __req(self, url):
if sys.version_info[0] < 3:
import urllib
return urllib.urlopen(url).read()
else:
import urllib.request
return urllib.request.urlopen(url).read()

Installer()

0 comments on commit cbbda88

Please sign in to comment.