-
Notifications
You must be signed in to change notification settings - Fork 90
/
fOutputLicenseInformation.py
198 lines (190 loc) · 8.02 KB
/
fOutputLicenseInformation.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
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
import mProductDetails;
from faxListOutput import faxListOutput;
from foConsoleLoader import foConsoleLoader;
from mColorsAndChars import \
COLOR_ERROR, CHAR_ERROR, \
COLOR_OK, CHAR_OK, \
COLOR_WARNING, CHAR_WARNING, \
COLOR_HILITE, COLOR_INFO, COLOR_NORMAL;
oConsole = foConsoleLoader();
try:
from fOutputLogo import fOutputLogo as f0OutputLogo;
except ModuleNotFoundError as oException:
if oException.args[0] != "No module named 'fOutputLogo'":
raise;
f0OutputLogo = None;
CHAR_LIST = "\u2022";
def fOutputLicenseInformation(bUpdateIfNeeded = False):
# Read product details for rs and all modules it uses.
aoProductDetails = mProductDetails.faoGetProductDetailsForAllLoadedModules();
o0MainProductDetails = mProductDetails.fo0GetProductDetailsForMainModule();
oConsole.fLock();
try:
aoLicenses = [];
asProductNamesWithoutLicenseRequirement = [];
asLicensedProductNames = [];
asProductNamesInTrial = [];
asUnlicensedProductNames = [];
for oProductDetails in aoProductDetails:
if not oProductDetails.bRequiresLicense:
asProductNamesWithoutLicenseRequirement.append(oProductDetails.sProductName);
elif oProductDetails.o0License:
if oProductDetails.o0License not in aoLicenses:
aoLicenses.append(oProductDetails.o0License);
asLicensedProductNames.append(oProductDetails.sProductName);
elif oProductDetails.bHasTrialPeriod and oProductDetails.bInTrialPeriod:
asProductNamesInTrial.append(oProductDetails.sProductName);
else:
asUnlicensedProductNames.append(oProductDetails.sProductName);
if o0MainProductDetails and o0MainProductDetails.sb0LicenseServerURL is not None:
oLicenseServer = mProductDetails.cLicenseServer(o0MainProductDetails.sb0LicenseServerURL);
uCheckedLicenseCounter = 0;
aoUpdatedLicenses = [];
for oLicense in aoLicenses:
oConsole.fProgressBar(
uCheckedLicenseCounter * 1.0 / len(aoLicenses),
"Checking license %s with server..." % oLicense.sLicenseId,
);
sLicenseServerError = oLicense.fsCheckWithServerAndGetError(oLicenseServer, bForceCheck = True);
sServerURL = str(o0MainProductDetails.sb0LicenseServerURL, "ascii", "strict");
if sLicenseServerError:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " License check for ",
COLOR_INFO, oLicense.sLicenseId,
COLOR_NORMAL, " on server ",
COLOR_INFO, sServerURL,
COLOR_NORMAL, " failed:",
);
oConsole.fOutput(
" ",
COLOR_INFO, sLicenseServerError,
);
uCheckedLicenseCounter += 1;
if oLicense.bMayNeedToBeUpdated and bUpdateIfNeeded:
oConsole.fProgressBar(
uCheckedLicenseCounter * 1.0 / len(aoLicenses),
"Downloading updated license %s from server..." % oLicense.sLicenseId,
);
oUpdatedLicense = oLicenseServer.foDownloadUpdatedLicense(oLicense);
oConsole.fOutput(
COLOR_OK, CHAR_OK, COLOR_NORMAL, " Downloaded updated license ",
COLOR_INFO, oLicense.sLicenseId, COLOR_NORMAL, " from server ",
COLOR_INFO, str(oLicenseServer.sbServerURL, "ascii", "strict"),
COLOR_NORMAL, ".",
);
aoUpdatedLicenses.append(oUpdatedLicense);
if len(aoUpdatedLicenses) > 0:
for oProductDetails in aoProductDetails:
if oProductDetails.sb0LicenseServerURL is None:
continue; # No need for a license == do not store license
aoUpdatedLicensesForThisProduct = [
oUpdatedLicense
for oUpdatedLicense in aoUpdatedLicenses
if oProductDetails.sProductName in oUpdatedLicense.asProductNames
];
mProductDetails.fWriteLicensesToProductFolder(aoUpdatedLicensesForThisProduct, oProductDetails);
oConsole.fOutput(
COLOR_OK, CHAR_OK,
COLOR_NORMAL, " Saved ",
COLOR_INFO, str(len(aoUpdatedLicensesForThisProduct)),
COLOR_NORMAL, " updated license", "" if len(aoUpdatedLicensesForThisProduct) == 1 else "s", " for product ",
COLOR_INFO, oProductDetails.sProductName,
COLOR_NORMAL, " in folder ",
COLOR_INFO, oProductDetails.sInstallationFolderPath,
COLOR_NORMAL, ".",
);
if f0OutputLogo:
f0OutputLogo();
oConsole.fOutput(
"┌───[", COLOR_HILITE, " License information ", COLOR_NORMAL, "]", sPadding = "─",
);
if aoLicenses:
oConsole.fOutput(
"│ ",
COLOR_OK, CHAR_OK,
COLOR_NORMAL, " This system uses system id ",
COLOR_INFO, mProductDetails.fsGetSystemId(),
COLOR_NORMAL, " with the license server.",
);
oConsole.fOutput(
"├", sPadding = "─",
);
for oLicense in aoLicenses:
oConsole.fOutput(
"│ ",
COLOR_OK, CHAR_OK,
COLOR_NORMAL, " License ",
COLOR_INFO, oLicense.sLicenseId,
COLOR_NORMAL, " covers ",
COLOR_INFO, oLicense.sUsageTypeDescription,
COLOR_NORMAL, " by ",
COLOR_INFO, oLicense.sLicenseeName,
COLOR_NORMAL, " of ",
COLOR_INFO, oLicense.asProductNames[0],
COLOR_NORMAL, " on ",
COLOR_INFO, str(oLicense.uLicensedInstances),
COLOR_NORMAL, " machine", "s" if oLicense.uLicensedInstances != 1 else "", ".",
);
oConsole.fOutput(
"│ Covered products: ",
faxListOutput(oLicense.asProductNames, "and", oLicense.asProductNames, COLOR_INFO, COLOR_NORMAL, COLOR_NORMAL),
COLOR_NORMAL, ".",
);
oConsole.fOutput(
"│ License source: ",
COLOR_INFO, oLicense.sLicenseSource,
COLOR_NORMAL, ".",
);
if asProductNamesInTrial:
oConsole.fOutput(
"│ ",
COLOR_WARNING, CHAR_WARNING,
COLOR_NORMAL, " A ",
COLOR_INFO, "trial period",
COLOR_NORMAL, " is active for the following product", "s" if len(asProductNamesInTrial) > 1 else "", ":",
);
oConsole.fOutput(
"│ ",
faxListOutput(asProductNamesInTrial, "and", asProductNamesInTrial, COLOR_INFO, COLOR_NORMAL, COLOR_NORMAL),
COLOR_NORMAL, ".",
);
if asProductNamesWithoutLicenseRequirement:
oConsole.fOutput(
"│ ",
COLOR_OK, CHAR_OK, " ",
COLOR_INFO, "No license",
COLOR_NORMAL, " is required to use the following product", "s" if len(asProductNamesWithoutLicenseRequirement) > 1 else "", ":",
);
oConsole.fOutput(
"│ ",
faxListOutput(asProductNamesWithoutLicenseRequirement, "and", [], COLOR_INFO, COLOR_NORMAL, COLOR_NORMAL),
COLOR_NORMAL, ".",
);
if asUnlicensedProductNames:
oConsole.fOutput(
"│ ",
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " ",
COLOR_INFO, "No valid license",
COLOR_NORMAL, " was found and ",
COLOR_INFO, "the trial period has been exceeded",
COLOR_NORMAL, " for the following product", "s" if len(asUnlicensedProductNames) > 1 else "", ":",
);
oConsole.fOutput(
"│ ",
faxListOutput(asUnlicensedProductNames, "and", asUnlicensedProductNames, COLOR_INFO, COLOR_NORMAL, COLOR_NORMAL),
COLOR_NORMAL, ".",
);
(asLicenseErrors, asLicenseWarnings) = mProductDetails.ftasGetLicenseErrorsAndWarnings();
if asLicenseErrors:
oConsole.fOutput("├───[", COLOR_ERROR, " Software license error ", COLOR_NORMAL, "]", sPadding = "─");
for sLicenseError in asLicenseErrors:
oConsole.fOutput("│ ", COLOR_ERROR, CHAR_ERROR, COLOR_INFO, " ", sLicenseError);
if asLicenseWarnings:
oConsole.fOutput("├───[", COLOR_WARNING, " Software license warning ", COLOR_NORMAL, "]", sPadding = "─");
for sLicenseWarning in asLicenseWarnings:
oConsole.fOutput("│ ", COLOR_WARNING, CHAR_WARNING, COLOR_INFO, " ", sLicenseWarning);
oConsole.fOutput("└", sPadding = "─");
finally:
oConsole.fUnlock();