-
Notifications
You must be signed in to change notification settings - Fork 0
/
pip_auto_update.py
58 lines (44 loc) · 1.73 KB
/
pip_auto_update.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
#!/usr/bin/python3.7
# UTF8
# Date: Tue 27 Aug 2019 14:27:23 CEST
# Author: Nicolas Flandrois
# Description:
# This tool will automatically check your python's pip list in your system,
# and update all packages to their newest versions.
# Then it will display a summary, with double checking points
# (number of packages before update compared to after update;
# and the number of packages that have been updated). Then it will display
# the list of updated packages: New Versions vs. Old versions.
import os
import pkg_resources
import platform
from subprocess import call
import time
def clean():
if platform.system() == "Windows":
os.system("cls")
else:
os.system("clear")
def autoupdate():
packages = [dist.project_name for dist in pkg_resources.working_set]
call("pip install --upgrade " + ' '.join(packages), shell=True)
os.system("pip list > piplist_before.txt")
autoupdate()
print('\n\nUpdate Completed. Please Wait for checkpoint.\
\t(Estimated Waiting Time: 00:00:30)')
time.sleep(30)
os.system("pip list > piplist_after.txt")
with open('piplist_before.txt', 'r') as f:
before = set(f.read().lower().replace(" ", "").split('\n'))
with open('piplist_after.txt', 'r') as f:
after = set(f.read().lower().replace(" ", "").split('\n'))
delta1 = sorted(list(after.difference(before)))
delta2 = sorted(list(before.difference(after)))
clean()
print(f'lenght of pip list Before:\t{len(before)}')
print(f'lenght of pip list After:\t{len(after)}')
print(f'lenght of pip list delta(after/before):\t{len(delta1)}')
print(f'lenght of pip list delta(before/after):\t{len(delta2)}')
print('\n\nNew Versions\t||\tOld Versions\n')
for i in range(len(delta1)):
print(f'{delta1[i]}\t ||\t {delta2[i]}')