-
Notifications
You must be signed in to change notification settings - Fork 1
/
GLpipcheck
executable file
·208 lines (160 loc) · 6.77 KB
/
GLpipcheck
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#! /usr/bin/python3
# -*- coding: utf-8 -*-
"""
GLpipcheck - To check Pip version status of GeigerLog requirements
"""
###############################################################################
# This file is part of GeigerLog.
#
# GeigerLog is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GeigerLog is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GeigerLog. If not, see <http://www.gnu.org/licenses/>.
###############################################################################
__author__ = "ullix"
__copyright__ = "Copyright 2016, 2017, 2018, 2019, 2020"
__credits__ = [""]
__license__ = "GPL3"
"""
Using pip as an imported module: (not recommended, see at bottom of:
https://pip.pypa.io/en/stable/user_guide/
... if you decide that you do want to run pip from within your program. The most
... reliable approach, and the one that is fully supported, is to run pip in a
... subprocess. This is easily done using the standard subprocess module
from pip._internal import main as pipmain
def install(package):
# test for presence of 'main' (older versions) or use pip._internal.main()
if hasattr(pip, 'main'):
pip.main(['install', package])
else:
pip._internal.main(['install', package])
pipmain(["list"])
<package name> = e.g. pip, pyserial, ...
pipmain(["show", <package name>])
pipmain(["install","--upgrade", <package name>])
"""
import sys, subprocess
def removeSpaces(text):
"""no more than single space allowed"""
while True:
text2 = text.replace(" ", " ")
if len(text2) < len(text):
text = text2
else:
return text2
def showPipList():
"""Executes 'pip list' and prints all"""
print("Listing of all Pip-found packages:")
nreqs = piplist.decode('UTF-8').split("\n")
for nr in nreqs:
print(" ", nr)
def showInstalledPackages():
"""call pip list and find packages required by GeigerLog with their version"""
print("\nGeigerLog required packages and their currently installed versions:")
nreqs = piplist.decode('UTF-8').strip().split("\n")
#print ("nreqs:", nreqs)
print(" Package Version")
for nr in nreqs:
snr = removeSpaces(nr).split(" ", 1)
#print("snr: ", snr)
p = snr[0].strip()
v = snr[1].strip()
#print("nr: >{}< >{}<".format(p, v))
if p in installs:
print(" installed: {:18s} {:20s}".format(p, v))
installs[p][2] = True
else:
pass
#~print("installed but not needed: {:28s} {:20s}".format(p, v))
def showMissingPackages():
"""Packages needed by GeigerLog but not installed"""
print("\nGeigerLog required packages missing:")
counter = 0
for pkg in installs:
#print(" pkg: {:28s}".format(pkg), pkg)
if installs[pkg][2] == False: # False or True is set by showInstalledPackages
print(" missing: {:18s}".format(pkg))
counter += 1
else:
pass
#print(" found: {:28s}".format(pkg))
if counter == 0: print(" None")
def showVersionFromPipOutdatedList():
"""Call 'pip list --outdated' """
print("\nGeigerLog required packages having Upgrades available:")
reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'list', '--outdated'])
nreqs = reqs.decode('UTF-8').strip().split("\n") # e.g.: 'bottle 0.12.7 0.12.17 wheel',
#print("nreqs:", len(nreqs), nreqs)
counter = 0
print(" Package Version Latest Type")
for nr in nreqs:
if len(nr) == 0: continue
#print("nr: ", len(nr), nr)
snr = removeSpaces(nr).split(" ", 3)
#print(snr)
p = snr[0].strip()
v = snr[1].strip()
w = snr[2].strip()
x = snr[3].strip()
#~print("nr: >{}< >{}< >{}<".format(p, v, w))
if p in installs:
print(" installed: {:18s} {:11s} {:11s} {:20s}".format(p, v, w, x))
counter += 1
else:
pass
#~print("installed but not needed: {:28s} {:20s}".format(p,v))
if counter == 0: print(" None")
###############################################################################
def main():
global installs, piplist
print("\n------------------------ GLpipcheck ----------------------------")
print("Python Executable: ", sys.executable)
print("Python Version: ", sys.version.replace('\n', " "))
print()
# October 9, 2020
#~GeigerLog required packages and their currently installed versions:
#~Package Version
#~installed: matplotlib 3.3.2
#~installed: numpy 1.19.2
#~installed: paho-mqtt 1.5.1
#~installed: pip 20.2.3
#~installed: pip-check 2.6
#~installed: PyQt5 5.15.1
#~installed: PyQt5-sip 12.8.1
#~installed: pyserial 3.4
#~installed: scipy 1.5.2
#~installed: setuptools 50.3.0
#~installed: sounddevice 0.4.1
#~installed: SoundFile 0.10.3.post1
# optional for pip: pip install "SomeProject >=1,<2"
installs = {
"pip" : ["latest" , "pypi", False],
"setuptools" : ["latest" , "pypi", False],
"PyQt5" : ["latest" , "pypi", False],
"PyQt5-sip" : ["latest" , "pypi", False],
"numpy" : ["latest" , "pypi", False],
"scipy" : ["latest" , "pypi", False],
"matplotlib" : ["latest" , "pypi", False],
"pyserial" : ["latest" , "pypi", False],
"paho-mqtt" : ["latest" , "pypi", False],
"sounddevice" : ["latest" , "pypi", False],
"SoundFile" : ["latest" , "pypi", False],
"pip-check" : ["latest" , "pypi", False],
}
# create the 'pip list'
piplist = subprocess.check_output([sys.executable, '-m', 'pip', 'list'])
showPipList()
showInstalledPackages()
showMissingPackages()
showVersionFromPipOutdatedList()
print()
if __name__ == '__main__':
main()