-
Notifications
You must be signed in to change notification settings - Fork 90
/
fCheckPythonVersion.py
93 lines (91 loc) · 3.74 KB
/
fCheckPythonVersion.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
import platform, sys;
from faxListOutput import faxListOutput;
from foConsoleLoader import foConsoleLoader;
from mColorsAndChars import \
CHAR_ERROR, \
COLOR_ERROR, \
COLOR_INFO, \
COLOR_NORMAL, \
CONSOLE_UNDERLINE, \
COLOR_WARNING;
from mExitCodes import \
guExitCodeInternalError;
oConsole = foConsoleLoader();
def fCheckPythonVersion(sApplicationName, asTestedPythonVersions, sBugURL):
sPythonVersion = platform.python_version();
uMajorVersion, uMinorVersion, uMicroVersion = [int(s) for s in sPythonVersion.split(".")];
auTestedMajorVersions = set();
bRunningInTestedMajorVersion = False;
bRunningInTestedVersion = False;
bRunningInOlderVersion = False;
for sTestedPythonVersion in asTestedPythonVersions:
uTestedMajorVersion, uTestedMinorVersion, uTestedMicroVersion = [int(s) for s in sTestedPythonVersion.split(".")];
auTestedMajorVersions.add(uTestedMajorVersion);
if uMajorVersion == uTestedMajorVersion:
bRunningInTestedMajorVersion = True;
if uMinorVersion == uTestedMinorVersion:
if uMicroVersion == uTestedMicroVersion:
# We are running in a tested Python version.
bRunningInTestedVersion = True;
elif uMicroVersion < uTestedMicroVersion:
# This application was tested in a later version, so the version we are running in is outdated.
bRunningInOlderVersion = True;
elif uMinorVersion < uTestedMinorVersion:
# This application was tested in a later version, so the version we are running in is outdated.
bRunningInOlderVersion = True;
if not bRunningInTestedMajorVersion:
asTestedMayorVersions = sorted(str(u) for u in auTestedMajorVersions);
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " ", sApplicationName, " requires Python version ",
faxListOutput(asTestedMayorVersions, "or", asTestedMayorVersions, COLOR_INFO, COLOR_NORMAL),
COLOR_NORMAL, ".",
);
sys.exit(guExitCodeInternalError);
if not bRunningInTestedVersion:
oConsole.fLock();
try:
oConsole.fOutput("┌───[", COLOR_WARNING, " Warning ", COLOR_NORMAL, "]", sPadding = "─");
oConsole.fOutput(
"│ You are running a", "n older" if bRunningInOlderVersion else " newer", " version of Python (",
COLOR_INFO, sPythonVersion,
COLOR_NORMAL, ") in which this version of",
);
oConsole.fOutput(
"│ ",
COLOR_INFO, sApplicationName,
COLOR_NORMAL, " ", "was never tested" if bRunningInOlderVersion else "has not been tested yet",
".",
);
oConsole.fOutput(
"│ The following Python versions have been tested:",
);
oConsole.fOutput(
"│ ",
faxListOutput(asTestedPythonVersions, "and", asTestedPythonVersions, COLOR_INFO, COLOR_NORMAL),
COLOR_NORMAL, ".",
);
if bRunningInOlderVersion:
oConsole.fOutput(
"│ Please update Python to the latest version!",
);
else:
oConsole.fOutput(
"│ Please report this so ", sApplicationName, " can be tested with this version of Python at the following URL:",
);
oConsole.fOutput(
"│ ",
COLOR_INFO | CONSOLE_UNDERLINE, sBugURL,
);
oConsole.fOutput("└", sPadding = "─");
finally:
oConsole.fUnlock();
elif bRunningInOlderVersion:
oConsole.fLock();
try:
oConsole.fOutput("┌───[", COLOR_WARNING, " Warning ", COLOR_NORMAL, "]", sPadding = "─");
oConsole.fOutput("│ You are running Python ", COLOR_INFO, sPythonVersion, COLOR_NORMAL, ", which is outdated.");
oConsole.fOutput("│ Please update Python to the latest version!");
oConsole.fOutput("└", sPadding = "─");
finally:
oConsole.fUnlock();