VirtualBox

Ignore:
Timestamp:
Mar 8, 2022 2:57:25 PM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
150378
Message:

testmanager: pylint 2.9.6 adjustments (mostly about using sub-optimal looping and 'with' statements).

Location:
trunk/src/VBox/ValidationKit/testmanager/core
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/testmanager/core/build.py

    r93115 r94129  
    739739        asOsAgnosticArch = [];
    740740        asOsNoArch       = [];
    741         for i in range(len(oBuildEx.oCat.asOsArches)):
    742             asParts = oBuildEx.oCat.asOsArches[i].split('.');
     741        for sOsArch in oBuildEx.oCat.asOsArches:
     742            asParts = sOsArch.split('.');
    743743            if len(asParts) != 2 or not asParts[0] or not asParts[1]:
    744744                raise self._oDb.integrityException('Bad build asOsArches value: %s (idBuild=%s idBuildCategory=%s)'
    745                                                    % (oBuildEx.asOsArches[i], oBuildEx.idBuild, oBuildEx.idBuildCategory));
     745                                                   % (sOsArch, oBuildEx.idBuild, oBuildEx.idBuildCategory));
    746746            asOsNoArch.append(asParts[0] + '.noarch');
    747747            asOsNoArch.append('os-agnostic.' + asParts[1]);
  • trunk/src/VBox/ValidationKit/testmanager/core/report.py

    r93115 r94129  
    12221222            #
    12231223            for oSeries in oCollection.aoSeries:
    1224                 for i in range(len(oSeries.aiRevisions)):
    1225                     oSeries.aoRevInfo.append(self.oCache.getVcsRevInfo(sCurRepository, oSeries.aiRevisions[i]));
     1224                for iRevision in oSeries.aiRevisions:
     1225                    oSeries.aoRevInfo.append(self.oCache.getVcsRevInfo(sCurRepository, iRevision));
    12261226            aoRet.append(oCollection);
    12271227
  • trunk/src/VBox/ValidationKit/testmanager/core/restdispatcher.py

    r93115 r94129  
    220220        if not os.path.exists(os.path.dirname(sFile)):
    221221            os.makedirs(os.path.dirname(sFile), 0o755);
    222         oFile = open(sFile, 'ab');
    223 
    224         # Check the size.
    225         fSizeOk = True;
    226         if not fIgnoreSizeCheck:
    227             oStat = os.fstat(oFile.fileno());
    228             fSizeOk = oStat.st_size / (1024 * 1024) < config.g_kcMbMaxMainLog;
    229 
    230         # Write the text.
    231         if fSizeOk:
    232             if sys.version_info[0] >= 3:
    233                 oFile.write(bytes(sText, 'utf-8'));
    234             else:
    235                 oFile.write(sText);
    236 
    237         # Done
    238         oFile.close();
     222
     223        with open(sFile, 'ab') as oFile:
     224            # Check the size.
     225            fSizeOk = True;
     226            if not fIgnoreSizeCheck:
     227                oStat = os.fstat(oFile.fileno());
     228                fSizeOk = oStat.st_size / (1024 * 1024) < config.g_kcMbMaxMainLog;
     229
     230            # Write the text.
     231            if fSizeOk:
     232                if sys.version_info[0] >= 3:
     233                    oFile.write(bytes(sText, 'utf-8'));
     234                else:
     235                    oFile.write(sText);
     236
    239237        return fSizeOk;
    240238
  • trunk/src/VBox/ValidationKit/testmanager/core/schedulerbeci.py

    r93115 r94129  
    7575        #
    7676        cMaxItems = len(oData.aoArgsVariations) * 64;
    77         if cMaxItems > 1048576:
    78             cMaxItems = 1048576;
     77        cMaxItems = min(cMaxItems, 1048576);
    7978
    8079        aoItems   = list();
  • trunk/src/VBox/ValidationKit/testmanager/core/testboxcontroller.py

    r93115 r94129  
    327327        if not os.path.exists(os.path.dirname(sFile)):
    328328            os.makedirs(os.path.dirname(sFile), 0o755);
    329         oFile = open(sFile, 'ab');
    330 
    331         # Check the size.
    332         fSizeOk = True;
    333         if not fIgnoreSizeCheck:
    334             oStat = os.fstat(oFile.fileno());
    335             fSizeOk = oStat.st_size / (1024 * 1024) < config.g_kcMbMaxMainLog;
    336 
    337         # Write the text.
    338         if fSizeOk:
    339             if sys.version_info[0] >= 3:
    340                 oFile.write(bytes(sText, 'utf-8'));
    341             else:
    342                 oFile.write(sText);
    343 
    344         # Done
    345         oFile.close();
     329
     330        with open(sFile, 'ab') as oFile:
     331            # Check the size.
     332            fSizeOk = True;
     333            if not fIgnoreSizeCheck:
     334                oStat = os.fstat(oFile.fileno());
     335                fSizeOk = oStat.st_size / (1024 * 1024) < config.g_kcMbMaxMainLog;
     336
     337            # Write the text.
     338            if fSizeOk:
     339                if sys.version_info[0] >= 3:
     340                    oFile.write(bytes(sText, 'utf-8'));
     341                else:
     342                    oFile.write(sText);
     343
    346344        return fSizeOk;
    347345
  • trunk/src/VBox/ValidationKit/testmanager/core/testcase.py

    r93115 r94129  
    902902            dErrors = {};
    903903
    904             for iVar in range(len(self.aoTestCaseArgs)):
    905                 oVar = copy.copy(self.aoTestCaseArgs[iVar]);
     904            for iVar, oVar in enumerate(self.aoTestCaseArgs):
     905                oVar = copy.copy(oVar);
    906906                oVar.idTestCase = self.idTestCase;
    907907                dCurErrors = oVar.validateAndConvert(oDb, ModelDataBase.ksValidateFor_Other);
     
    915915                aoNewValues.append(oVar);
    916916
    917             for iVar in range(len(self.aoTestCaseArgs)):
    918                 sArgs = self.aoTestCaseArgs[iVar].sArgs;
     917            for iVar, oVar in enumerate(self.aoTestCaseArgs):
     918                sArgs = oVar.sArgs;
    919919                for iVar2 in range(iVar + 1, len(self.aoTestCaseArgs)):
    920920                    if self.aoTestCaseArgs[iVar2].sArgs == sArgs:
  • trunk/src/VBox/ValidationKit/testmanager/core/testset.py

    r93115 r94129  
    194194        sFile1 = os.path.join(config.g_ksFileAreaRootDir, self.sBaseFilename + '-' + sFilename);
    195195        try:
    196             oFile = open(sFile1, sMode);
     196            oFile = open(sFile1, sMode);                        # pylint: disable=consider-using-with
    197197            return (oFile, os.fstat(oFile.fileno()).st_size, False);
    198198        except Exception as oXcpt1:
     
    200200            sFile2 = os.path.join(config.g_ksZipFileAreaRootDir, self.sBaseFilename + '.zip');
    201201            try:
    202                 oZipFile    = zipfile.ZipFile(sFile2, 'r');
    203                 oFile       = oZipFile.open(sFilename, sMode if sMode != 'rb' else 'r');
     202                oZipFile    = zipfile.ZipFile(sFile2, 'r');                              # pylint: disable=consider-using-with
     203                oFile       = oZipFile.open(sFilename, sMode if sMode != 'rb' else 'r'); # pylint: disable=consider-using-with
    204204                cbFile      = oZipFile.getinfo(sFilename).file_size;
    205205                return (oFile, cbFile, True);
     
    230230            if not os.path.exists(os.path.dirname(sFile1)):
    231231                os.makedirs(os.path.dirname(sFile1), 0o755);
    232             oFile = open(sFile1, sMode);
     232            oFile = open(sFile1, sMode);                        # pylint: disable=consider-using-with
    233233        except Exception as oXcpt1:
    234234            return str(oXcpt1);
  • trunk/src/VBox/ValidationKit/testmanager/core/webservergluebase.py

    r93115 r94129  
    138138        self._oDbgFile         = sys.stderr;
    139139        if config.g_ksSrvGlueDebugLogDst is not None and config.g_kfSrvGlueDebug is True:
    140             self._oDbgFile = open(config.g_ksSrvGlueDebugLogDst, 'a');
     140            self._oDbgFile = open(config.g_ksSrvGlueDebugLogDst, 'a');  # pylint: disable=consider-using-with
    141141            if config.g_kfSrvGlueCgiDumpArgs:
    142142                self._oDbgFile.write('Arguments: %s\nEnvironment:\n' % (sys.argv,));
     
    303303        """
    304304        if self._fHeaderWrittenOut is False:
    305             for sKey in self._dHeaderFields:
    306                 self._writeHeader('%s: %s\n' % (sKey, self._dHeaderFields[sKey]));
     305            for sKey, sValue in self._dHeaderFields.items():
     306                self._writeHeader('%s: %s\n' % (sKey, sValue,));
    307307            self._fHeaderWrittenOut = True;
    308308            self._writeHeader('\n'); # End of header indicator.
     
    462462
    463463        try:
    464             oFile = open(sLogFile, 'w');
    465             oFile.write(sError + '\n\n');
    466             if aXcptInfo[0] is not None:
    467                 oFile.write(' B a c k t r a c e\n');
    468                 oFile.write('===================\n');
    469                 oFile.write(cgitb.text(aXcptInfo, 5));
    470                 oFile.write('\n\n');
    471 
    472             oFile.write(' D e b u g   I n f o\n');
    473             oFile.write('=====================\n\n');
    474             self._fHtmlDebugOutput = False;
    475             self.debugDumpStuff(oFile.write);
    476 
    477             oFile.close();
     464            with open(sLogFile, 'w') as oFile:
     465                oFile.write(sError + '\n\n');
     466                if aXcptInfo[0] is not None:
     467                    oFile.write(' B a c k t r a c e\n');
     468                    oFile.write('===================\n');
     469                    oFile.write(cgitb.text(aXcptInfo, 5));
     470                    oFile.write('\n\n');
     471
     472                oFile.write(' D e b u g   I n f o\n');
     473                oFile.write('=====================\n\n');
     474                self._fHtmlDebugOutput = False;
     475                self.debugDumpStuff(oFile.write);
    478476        except:
    479477            fRc = False;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette