-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlibmgr.py
148 lines (127 loc) · 5.64 KB
/
libmgr.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import os
from os import path
import urllib.request
import subprocess
import platform
xargswin_URL = 'https://github.com/manasmbellani/xargswin/releases/download/initial/xargswin.exe'
xargswin_path = 'lib\\xargswin.exe'
pip_url = 'https://bootstrap.pypa.io/get-pip.py'
def find_pip(python_path: str) -> str:
if path.exists(path.join(python_path.replace('python.exe', ''), 'Scripts', 'pip3.exe')):
return path.join(python_path.replace('python.exe', ''), 'Scripts', 'pip3.exe')
else:
return ''
def find_python() -> str:
if not platform.system().casefold().find('windows') > -1:
return ''
else:
path_x64 = 'C:\\Program Files\\'
path_x86 = 'C:\\Program Files (x86)\\'
list_path_x64 = os.listdir(path_x64)
list_path_x86 = os.listdir(path_x86)
found_python_path = ''
for folder in list_path_x64:
if folder.casefold().find('python') > -1 and path.isdir(path.join(path_x64, folder)):
found_python_path = path.join(path_x64, folder)
break
else:
continue
if found_python_path == '':
for folder in list_path_x86:
if folder.casefold().find('python') > -1 and path.isdir(path.join(path_x86, folder)):
found_python_path = path.join(path_x86, folder)
break
else:
continue
if path.exists(path.join(found_python_path, 'python.exe')):
return path.join(found_python_path, 'python.exe')
else:
return ''
class libmgr():
certs_found = False
use_python_path = False
python_path = ''
use_pip_path = False
pip_path = ''
def get_libs(self):
print('Checking libraries..')
if not path.exists('lib'):
os.mkdir('lib')
if not path.exists(xargswin_path):
print('Downloading XargsWin...')
local_filename, headers = urllib.request.urlretrieve(xargswin_URL, xargswin_path)
self.get_pip()
self.get_psutil()
self.get_openssl()
self.get_pyGithub()
def get_pip(self):
print('Checking pip installation.')
# noinspection PyBroadException
try:
pip_install_check = subprocess.check_output(['pip3', '--version'], stderr=subprocess.DEVNULL, shell=True)
print('pip installation confirmed.')
except:
print('Pip not found in PATH.')
print('Installing pip now.')
local_filename, headers = urllib.request.urlretrieve(pip_url, 'pip.py')
try:
pip_install_result = subprocess.check_output('python pip.py', stderr=subprocess.DEVNULL, shell=True)
os.remove('pip.py')
except:
if not platform.system().casefold().find('windows') > -1:
print('Python not installed properly, please reinstall python, or make sure that the \'python\' command is valid')
exit(4)
print('Python is not in system PATH, attempting to predict a direct path...')
self.use_python_path = True
self.python_path = find_python()
if not self.python_path == '':
print('Python found successfully!')
else:
print(
'Python not found, despite our best efforts. Make sure you are running with Python 3.0.0 or greater.')
exit(2)
try:
print('Installing pip.')
pip_install_result = subprocess.check_output('"' + self.python_path + '" pip.py', stderr=subprocess.DEVNULL, shell=True)
except:
print('Error occurred while attempting to install pip. exiting')
exit(3)
finally:
print('Pip appears to be already installed. Finding installation path..')
self.pip_path = find_pip( self.python_path )
if not self.pip_path == '':
self.use_pip_path = True
print('Pip installation found, but not in PATH. Found at: \r\n'+self.pip_path)
print('Important: Be sure to add Pip and Python to your PATH environment variable.')
def get_psutil(self):
print('Checking for psutil.')
pip_command = self.pip_path if self.use_pip_path else 'pip3'
# noinspection PyBroadException
try:
subprocess.check_output([pip_command, 'show', 'psutil'], stderr=subprocess.DEVNULL,
shell=True)
print('Psutil installed.')
except:
print('Psutil not found, installing...')
subprocess.check_output([pip_command, 'install', 'psutil'],
shell=True)
def get_openssl(self):
print('Checking for OpenSSL.')
# noinspection PyBroadException
try:
subprocess.check_output(['pip3', 'show', 'pyOpenSSL'], stderr=subprocess.DEVNULL,
shell=True)
print('OpenSSL installed.')
except:
print('OpenSSL not found, installing...')
os.system('pip3 install pyOpenSSL')
def get_pyGithub(self):
print('Checking for pyGithub.')
# noinspection PyBroadException
try:
subprocess.check_output(['pip3', 'show', 'pyGithub'], stderr=subprocess.DEVNULL,
shell=True)
print('pyGithub installed.')
except:
print('pyGithub not found, installing...')
os.system('pip3 install pyGithub')