Пример #1
0
import os, sys

# Augment the search path: pretend we are in the parent folder so we can load mProductDetails as a module:
sMainFolderPath = os.path.abspath(os.path.dirname(__file__))
sParentFolderPath = os.path.normpath(os.path.join(sMainFolderPath, ".."))
sys.path = [sParentFolderPath] + sys.path

import mProductDetails
from fsToOxfordComma import fsToOxfordComma

print "Unique system id: " + mProductDetails.fsGetSystemId()

print "Product version information:"
oMainProductDetails = mProductDetails.foGetProductDetailsForMainModule()
aoProductDetails = mProductDetails.faoGetProductDetailsForAllLoadedModules()
# Change order to put main product at the front:
aoProductDetails.remove(oMainProductDetails)
aoProductDetails.insert(0, oMainProductDetails)
for oProductDetails in aoProductDetails:
    print "+ \"%s\" version \"%s\" by \"%s\" installed in \"%s\"." % \
        (oProductDetails.sProductName, oProductDetails.oProductVersion, oProductDetails.sProductAuthor, oProductDetails.sInstallationFolderPath)
print

print "Checking licenses for loaded software products:"
oLicenseCollection = mProductDetails.foGetLicenseCollectionForAllLoadedProducts(
)
(asErrors, asWarnings) = oLicenseCollection.ftasGetLicenseErrorsAndWarnings()
if asErrors:
    print "Software license error%s:" % (len(asErrors) > 1 and "s" or "")
    for sError in asErrors:
        print "- " + sError
Пример #2
0
def fPrintVersionInformation(bCheckForUpdates, bCheckAndShowLicenses, bShowInstallationFolders):
  # Read product details for rs and all modules it uses.
  aoProductDetails = mProductDetails.faoGetProductDetailsForAllLoadedModules();
  oMainProductDetails = mProductDetails.foGetProductDetailsForMainModule();
  if bCheckForUpdates:
    uCheckedProductCounter = 0;
    for oProductDetails in aoProductDetails:
      oConsole.fProgressBar(
        uCheckedProductCounter * 1.0 / len(aoProductDetails),
        "Checking %s for updates..." % oProductDetails.sProductName,
      );
      try:
        oProductDetails.oLatestProductDetailsFromRepository;
      except Exception as oException:
        oConsole.fPrint(
          ERROR, u"- Version check for ", ERROR_INFO, oProductDetails.sProductName,
          ERROR, " failed: ", ERROR_INFO, str(oException),
        );
      uCheckedProductCounter += 1;
  oConsole.fLock();
  try:
    if bCheckAndShowLicenses:
      aoLicenses = [];
      asLicensedProductNames = [];
      asProductNamesInTrial = [];
      asUnlicensedProductNames = [];
      for oProductDetails in aoProductDetails:
        if oProductDetails.oLicense:
          if oProductDetails.oLicense not in aoLicenses:
            aoLicenses.append(oProductDetails.oLicense);
          asLicensedProductNames.append(oProductDetails.sProductName);
        elif oProductDetails.bHasTrialPeriod and oProductDetails.bInTrialPeriod:
          asProductNamesInTrial.append(oProductDetails.sProductName);
        else:
          asUnlicensedProductNames.append(oProductDetails.sProductName);

      oLicenseCheckServer = mProductDetails.cLicenseCheckServer(oMainProductDetails.sLicenseServerURL);
      uCheckedLicenseCounter = 0;
      for oLicense in aoLicenses:
        oConsole.fProgressBar(
          uCheckedLicenseCounter * 1.0 / len(aoLicenses),
          "Checking license %s with server..." % oLicense.sLicenseId,
        );
        sLicenseCheckServerError = oLicense.fsCheckWithServerAndGetError(oLicenseCheckServer, bForceCheck = True);
        if sLicenseCheckServerError:
          oConsole.fPrint(
            ERROR, u"- License check for ", ERROR_INFO, oLicense.sLicenseId,
            ERROR, " on server ", ERROR_INFO, oMainProductDetails.sLicenseServerURL,
            ERROR, " failed: ", ERROR_INFO, sLicenseCheckServerError,
          );
        uCheckedLicenseCounter += 1;
    
    oConsole.fPrint(
      u"\u250C\u2500 ", INFO, "Version information", NORMAL, " ", sPadding = u"\u2500"
    );
    # Output the BugId product information first, then its dependencies:
    fPrintProductDetails(oMainProductDetails, bIsMainProduct = True, bShowInstallationFolders = bShowInstallationFolders);
    for oProductDetails in aoProductDetails:
      if oProductDetails != oMainProductDetails:
        fPrintProductDetails(oProductDetails, bIsMainProduct = False, bShowInstallationFolders = bShowInstallationFolders);
    
    oConsole.fPrint(
      u"\u2502 \u2219 ", INFO, "Windows",
      NORMAL, " version: ", INFO, oSystemInfo.sOSName,
      NORMAL, " release ", INFO, oSystemInfo.sOSReleaseId,
      NORMAL, ", build ", INFO, oSystemInfo.sOSBuild,
      NORMAL, " ", INFO, oSystemInfo.sOSISA,
      NORMAL, ".",
    );
    oConsole.fPrint(
      u"\u2502 \u2219 ", INFO, "Python",
      NORMAL, " version: ", INFO, str(platform.python_version()),
      NORMAL, " ", INFO, fsGetPythonISA(),
      NORMAL, ".",
    );
    
    if bCheckAndShowLicenses:
      oConsole.fPrint(
        u"\u251C\u2500 ", INFO, "License information", NORMAL, " ", sPadding = u"\u2500",
      );
      if aoLicenses:
        oConsole.fPrint(
          NORMAL, u"\u2502 \u2219 This system is registered with id ", INFO, mProductDetails.fsGetSystemId(), NORMAL, " on the license server",
        );
      for oLicense in aoLicenses:
        oConsole.fPrint(
          u"\u2502 \u2219 License ", INFO, oLicense.sLicenseId,
          NORMAL, " for ", INFO, oLicense.asProductNames[0], 
          NORMAL, " covers ", INFO, oLicense.sUsageTypeDescription, 
          NORMAL, " by ", INFO, oLicense.sLicenseeName,
          NORMAL, " of the following products:",
        );
        oConsole.fPrint(u"\u2502     ", faxListOutput(oLicense.asProductNames, "and", INFO, NORMAL));
      if asProductNamesInTrial:
        oConsole.fPrint(*(
          [
            u"\u2502 \u2219 "
          ] + faxListOutput(asProductNamesInTrial, "and", WARNING_INFO, WARNING)  + [
            WARNING, " ", len(asProductNamesInTrial) == 1 and "is" or "are", " not covered by a valid, active license but ",
            len(asProductNamesInTrial) == 1 and "it is in its" or "they are in their", " trial period.",
          ]
        ));
      if asUnlicensedProductNames:
        oConsole.fPrint(*(
          [
            u"\u2502 \u2219 "
          ] + faxListOutput(asUnlicensedProductNames, "and", ERROR_INFO, ERROR)  + [
            ERROR, " ", len(asProductNamesInTrial) == 1 and "is" or "are", " not covered by a valid, active license and ",
            len(asProductNamesInTrial) == 1 and "has exceeded its" or "have exceeded their", " trial period.",
          ]
        ));
    oConsole.fPrint(
      u"\u2514", sPadding = u"\u2500",
    );
    oConsole.fPrint();
  finally:
    oConsole.fUnlock();

  (asLicenseErrors, asLicenseWarnings) = mProductDetails.ftasGetLicenseErrorsAndWarnings();
  if asLicenseErrors:
    oConsole.fLock();
    try:
      oConsole.fPrint(ERROR, u"\u250C\u2500", ERROR_INFO, " Software license error ", ERROR, sPadding = u"\u2500");
      for sLicenseError in asLicenseErrors:
        oConsole.fPrint(ERROR, u"\u2502 ", ERROR_INFO, sLicenseError);
      oConsole.fPrint(ERROR, u"\u2514", sPadding = u"\u2500");
    finally:
      oConsole.fUnlock();
  if asLicenseWarnings:
    oConsole.fLock();
    try:
      oConsole.fPrint(WARNING, u"\u250C\u2500", WARNING_INFO, " Software license warning ", WARNING, sPadding = u"\u2500");
      for sLicenseWarning in asLicenseWarnings:
        oConsole.fPrint(WARNING, u"\u2502 ", WARNING_INFO, sLicenseWarning);
      oConsole.fPrint(WARNING, u"\u2514", sPadding = u"\u2500");
    finally:
      oConsole.fUnlock();
Пример #3
0
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()