Skip to content

Commit

Permalink
Remove six lib from install script
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Anema committed Dec 3, 2020
1 parent 01726fb commit fb9e2ec
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 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
Python Version: 2.x, 3.x
Date last modified: Sep 14 2018
Python Version: 2.7
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 fb9e2ec

Please sign in to comment.