-
Notifications
You must be signed in to change notification settings - Fork 2
/
onekey_install_finxos.py
102 lines (82 loc) · 3.27 KB
/
onekey_install_finxos.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# encoding: utf-8
import platform
import subprocess
import os
import sys
try:
input_func = raw_input
except NameError:
input_func = input
try:
import urllib.request as urllib_request # for Python 3
except ImportError:
import urllib2 as urllib_request # for Python 2
def download_snappy(py_ver, bit):
base_url = r'http://www.quantos.org/downloads/snappy/'
snappy_file = dict()
snappy_file['py2.7-32bit'] = 'python_snappy-0.5.1-cp27-cp27m-win32.whl'
snappy_file['py2.7-64bit'] = 'python_snappy-0.5.1-cp27-cp27m-win_amd64.whl'
snappy_file['py3.4-32bit'] = 'python_snappy-0.5.1-cp34-cp34m-win32.whl'
snappy_file['py3.4-64bit'] = 'python_snappy-0.5.1-cp34-cp34m-win_amd64.whl'
snappy_file['py3.5-32bit'] = 'python_snappy-0.5.1-cp35-cp35m-win32.whl'
snappy_file['py3.5-64bit'] = 'python_snappy-0.5.1-cp35-cp35m-win_amd64.whl'
snappy_file['py3.6-32bit'] = 'python_snappy-0.5.1-cp36-cp36m-win32.whl'
snappy_file['py3.6-64bit'] = 'python_snappy-0.5.1-cp36-cp36m-win_amd64.whl'
key = 'py' + py_ver + "-" + bit
file_name = snappy_file[key]
url = base_url + file_name
req = urllib_request.Request(url)
rep = urllib_request.urlopen(req)
body = rep.read()
with open(file_name, 'wb') as f:
f.write(body)
f.close()
return file_name
def decode_if_possible(b, encoding='utf-8'):
if b is not None and hasattr(b, 'decode'):
return b.decode(encoding)
def exec_cmd(command):
p = subprocess.Popen(command, stdout=subprocess.PIPE, bufsize=1)
while True:
line = p.stdout.readline()
if not line:
break
print(line)
p.wait()
def pip_install(name):
cmd = 'pip install ' + name
exec_cmd(cmd)
def main():
SUPPORTTED_PYTHON_VERSIONS = ('2.7', '3.4', '3.5', '3.6')
PACKAGE_NAME = 'finxos'
MASTER_BRANCH = 'https://github.com/PKUJohnson/finxos/archive/master.zip'
print("\nDetecting Python version...")
py_major_ver, py_minor_ver, py_patch_ver = platform.python_version_tuple()
py_ver = '.'.join([py_major_ver, py_minor_ver])
if py_ver not in SUPPORTTED_PYTHON_VERSIONS:
print("Unsupported Python version: {}".format(py_ver))
return -1
print("Python version: {}".format(py_ver))
print("\nDetecting System version...")
bit, system = platform.architecture()
print("System version: {} {}".format(bit, system))
print("\nDownloading python-snappy from server...")
file_name = download_snappy(py_ver, bit)
print("Download complete.")
print("\nInstalling python-snappy...")
pip_install(file_name)
print("Install complete.")
print("\nInstalling finxos...")
correct_input = False
while not correct_input:
user_input = input_func("Input 1 for stable version; 2 for latest version:\n")
if user_input == '1':
pip_install(PACKAGE_NAME)
correct_input = True
elif user_input == '2':
print("Start to download latest version from GitHub and instlall it. This may take several minutes...")
pip_install(MASTER_BRANCH)
correct_input = True
print("Install complete.")
if __name__ == "__main__":
main()