-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrade_pip.py
executable file
·40 lines (35 loc) · 1.08 KB
/
upgrade_pip.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
import pkg_resources
import subprocess
import sys
from ssop import settings
def run(cmdl, execute):
"""
prints cmdl or passes it to subprocess.run if execute is True
returns str
"""
cmd = " ".join(cmdl)
if execute:
print(" running: " + cmd)
result = subprocess.run(cmdl, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
status = str(result.stdout)
if result.returncode != 0:
print("Non-zero returncode: " + str(result.returncode))
print(" result: " + str(result))
print(" status: " + str(status))
sys.exit(-1)
else:
print(" cmd: " + cmd)
status = 'SUCCESS'
return status
def basecmdl(pkgname):
"""
returns a basic commands suitable for subprocess.run()
"""
cmdl = ["pip3", "install", "--proxy", settings.HTTP_PROXY, "--upgrade", pkgname]
return cmdl
for dist in pkg_resources.working_set:
dist = str(dist)
print(str(dist))
packagename = str(dist).split()[0]
cmdlist = basecmdl(packagename)
runstatus = run(cmdlist, True)