VirtualBox

Changeset 94125 in vbox for trunk


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

ValKit/testboxscript: pylint 2.9.6 adjustments (mostly about using 'with' statements).

Location:
trunk/src/VBox/ValidationKit/testboxscript
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/testboxscript/testboxcommand.py

    r93115 r94125  
    129129
    130130        # Kick off the task and ACK the command.
    131         self._oCurTaskLock.acquire();
    132         try:
     131        with self._oCurTaskLock:
    133132            self._oCurTask = TestBoxExecTask(self._oTestBoxScript, idResult = idResult, sScriptZips = sScriptZips,
    134133                                             sScriptCmdLine = sScriptCmdLine, cSecTimeout = cSecTimeout);
    135         finally:
    136             self._oCurTaskLock.release();
    137134        oConnection.sendAckAndClose(constants.tbresp.CMD_EXEC);
    138135        return True;
     
    327324            return (-1, '', False);
    328325
    329         self._oCurTaskLock.acquire();
    330         self._oCurTask = oTask;
    331         self._oCurTaskLock.release();
     326        with self._oCurTaskLock:
     327            self._oCurTask = oTask;
    332328
    333329        return (oTask.idTestBox, oTask.sTestBoxName, True);
     
    351347    def _getCurTask(self):
    352348        """ Gets the current task in a paranoidly safe manny. """
    353         self._oCurTaskLock.acquire();
    354         oCurTask = self._oCurTask;
    355         self._oCurTaskLock.release();
     349        with self._oCurTaskLock:
     350            oCurTask = self._oCurTask;
    356351        return oCurTask;
    357352
  • trunk/src/VBox/ValidationKit/testboxscript/testboxscript_real.py

    r93115 r94125  
    182182            constants.tbreq.SIGNON_PARAM_SCRATCH_SIZE:     { self.VALUE: None,     self.FN: self._getFreeScratchSpace },
    183183        }
    184         for sItem in self._ddSignOnParams:
     184        for sItem in self._ddSignOnParams:                      # pylint: disable=consider-using-dict-items
    185185            if self._ddSignOnParams[sItem][self.FN] is not None:
    186186                self._ddSignOnParams[sItem][self.VALUE] = self._ddSignOnParams[sItem][self.FN]()
     
    189189        testboxcommons.log('Test Manager URL: %s' % self._oOptions.sTestManagerUrl,)
    190190        testboxcommons.log('Scratch root path: %s' % self._oOptions.sScratchRoot,)
    191         for sItem in self._ddSignOnParams:
     191        for sItem in self._ddSignOnParams:                      # pylint: disable=consider-using-dict-items
    192192            testboxcommons.log('Sign-On value %18s: %s' % (sItem, self._ddSignOnParams[sItem][self.VALUE]));
    193193
     
    323323            if sType == 'cifs':
    324324                ## @todo This stuff doesn't work on wei01-x4600b.de.oracle.com running 11.1. FIXME!
    325                 oPasswdFile = tempfile.TemporaryFile();
     325                oPasswdFile = tempfile.TemporaryFile();     # pylint: disable=consider-using-with
    326326                oPasswdFile.write(sPassword + '\n');
    327327                oPasswdFile.flush();
     
    795795        # Assemble SIGN-ON request parameters and send the request.
    796796        dParams = {};
    797         for sParam in self._ddSignOnParams:
     797        for sParam in self._ddSignOnParams:                     # pylint: disable=consider-using-dict-items
    798798            dParams[sParam] = self._ddSignOnParams[sParam][self.VALUE];
    799799        oResponse = TestBoxConnection.sendSignOn(self._oOptions.sTestManagerUrl, dParams);
     
    848848        # Refresh sign-on parameters, changes triggers sign-on.
    849849        fNeedSignOn = not self._fSignedOn or self._fNeedReSignOn;
    850         for item in self._ddSignOnParams:
    851             if self._ddSignOnParams[item][self.FN] is None:
     850        for sItem in self._ddSignOnParams:                      # pylint: disable=consider-using-dict-items
     851            if self._ddSignOnParams[sItem][self.FN] is None:
    852852                continue
    853853
    854             sOldValue = self._ddSignOnParams[item][self.VALUE]
    855             self._ddSignOnParams[item][self.VALUE] = self._ddSignOnParams[item][self.FN]()
    856             if sOldValue != self._ddSignOnParams[item][self.VALUE]:
     854            sOldValue = self._ddSignOnParams[sItem][self.VALUE]
     855            self._ddSignOnParams[sItem][self.VALUE] = self._ddSignOnParams[sItem][self.FN]()
     856            if sOldValue != self._ddSignOnParams[sItem][self.VALUE]:
    857857                fNeedSignOn = True
    858                 testboxcommons.log('Detected %s parameter change: %s -> %s' %
    859                                    (item, sOldValue, self._ddSignOnParams[item][self.VALUE]))
     858                testboxcommons.log('Detected %s parameter change: %s -> %s'
     859                                   % (sItem, sOldValue, self._ddSignOnParams[sItem][self.VALUE],))
    860860
    861861        if fNeedSignOn:
  • trunk/src/VBox/ValidationKit/testboxscript/testboxtasks.py

    r93115 r94125  
    184184        """
    185185        fRc = True;
    186         self._oBackLogFlushLock.acquire();
    187 
    188         # Grab the current back log.
    189         self._oBackLogLock.acquire();
    190         asBackLog = self._asBackLog;
    191         self._asBackLog  = [];
    192         self._cchBackLog = 0;
    193         self._secTsBackLogFlush = utils.timestampSecond();
    194         self._oBackLogLock.release();
    195 
    196         # If there is anything to flush, flush it.
    197         if asBackLog:
    198             sBody = '';
    199             for sLine in asBackLog:
    200                 sBody += sLine + '\n';
    201 
    202             oConnection = None;
    203             try:
    204                 if oGivenConnection is None:
    205                     oConnection = self._oTestBoxScript.openTestManagerConnection();
    206                     oConnection.postRequest(constants.tbreq.LOG_MAIN, {constants.tbreq.LOG_PARAM_BODY: sBody});
    207                     oConnection.close();
    208                 else:
    209                     oGivenConnection.postRequest(constants.tbreq.LOG_MAIN, {constants.tbreq.LOG_PARAM_BODY: sBody});
    210             except Exception as oXcpt:
    211                 testboxcommons.log('_logFlush error: %s' % (oXcpt,));
    212                 if len(sBody) < self.kcchMaxBackLog * 4:
    213                     self._oBackLogLock.acquire();
    214                     asBackLog.extend(self._asBackLog);
    215                     self._asBackLog = asBackLog;
    216                     # Don't restore _cchBackLog as there is no point in retrying immediately.
    217                     self._oBackLogLock.release();
    218                 if oConnection is not None: # Be kind to apache.
    219                     try:    oConnection.close();
    220                     except: pass;
    221                 fRc = False;
    222 
    223         self._oBackLogFlushLock.release();
     186
     187        with self._oBackLogFlushLock:
     188            # Grab the current back log.
     189            with self._oBackLogLock:
     190                asBackLog = self._asBackLog;
     191                self._asBackLog  = [];
     192                self._cchBackLog = 0;
     193                self._secTsBackLogFlush = utils.timestampSecond();
     194
     195            # If there is anything to flush, flush it.
     196            if asBackLog:
     197                sBody = '';
     198                for sLine in asBackLog:
     199                    sBody += sLine + '\n';
     200
     201                oConnection = None;
     202                try:
     203                    if oGivenConnection is None:
     204                        oConnection = self._oTestBoxScript.openTestManagerConnection();
     205                        oConnection.postRequest(constants.tbreq.LOG_MAIN, {constants.tbreq.LOG_PARAM_BODY: sBody});
     206                        oConnection.close();
     207                    else:
     208                        oGivenConnection.postRequest(constants.tbreq.LOG_MAIN, {constants.tbreq.LOG_PARAM_BODY: sBody});
     209                except Exception as oXcpt:
     210                    testboxcommons.log('_logFlush error: %s' % (oXcpt,));
     211                    if len(sBody) < self.kcchMaxBackLog * 4:
     212                        with self._oBackLogLock:
     213                            asBackLog.extend(self._asBackLog);
     214                            self._asBackLog = asBackLog;
     215                            # Don't restore _cchBackLog as there is no point in retrying immediately.
     216                    if oConnection is not None: # Be kind to apache.
     217                        try:    oConnection.close();
     218                        except: pass;
     219                    fRc = False;
     220
    224221        return fRc;
    225222
     
    248245            sFullMsg = sMessage;
    249246
    250         self._oBackLogLock.acquire();
    251         self._asBackLog.append(sFullMsg);
    252         cchBackLog = self._cchBackLog + len(sFullMsg) + 1;
    253         self._cchBackLog = cchBackLog;
    254         secTsBackLogFlush = self._secTsBackLogFlush;
    255         self._oBackLogLock.release();
     247        with self._oBackLogLock:
     248            self._asBackLog.append(sFullMsg);
     249            cchBackLog = self._cchBackLog + len(sFullMsg) + 1;
     250            self._cchBackLog = cchBackLog;
     251            secTsBackLogFlush = self._secTsBackLogFlush;
    256252
    257253        testboxcommons.log(sFullMsg);
     
    642638        """
    643639        try:
    644             oFile = open(sPath, "rb");
    645             sStr = oFile.read();
     640            with open(sPath, "rb") as oFile:
     641                sStr = oFile.read();
    646642            sStr = sStr.decode('utf-8');
    647             oFile.close();
    648643            return sStr.strip();
    649644        except Exception as oXcpt:
     
    662657        try:
    663658            os.remove(sScriptCmdLine);
    664             oFile = open(sScriptCmdLine, 'wb');
    665             oFile.close();
     659            open(sScriptCmdLine, 'wb').close();                 # pylint: disable=consider-using-with
    666660        except Exception as oXcpt:
    667661            self._log('Error truncating "%s": %s' % (sScriptCmdLine, oXcpt));
     
    781775        """
    782776        try:
    783             oFile = open(sPath, "wb");
    784             oFile.write(sContent.encode('utf-8'));
    785             oFile.flush();
    786             try:     os.fsync(oFile.fileno());
    787             except:  pass;
    788             oFile.close();
     777            with open(sPath, "wb") as oFile:
     778                oFile.write(sContent.encode('utf-8'));
     779                oFile.flush();
     780                try:     os.fsync(oFile.fileno());
     781                except:  pass;
    789782        except Exception as oXcpt:
    790783            raise Exception('Failed to write "%s": %s' % (sPath, oXcpt));
  • trunk/src/VBox/ValidationKit/testboxscript/testboxupgrade.py

    r93115 r94125  
    4040
    4141# Validation Kit imports.
     42from common        import utils;
    4243import testboxcommons
    4344from testboxscript import TBS_EXITCODE_SYNTAX;
    44 from common import utils;
    4545
    4646# Figure where we are.
     
    127127    if sys.executable:
    128128        asArgs.insert(0, sys.executable);
    129     oChild = subprocess.Popen(asArgs, shell = False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT);
     129    oChild = subprocess.Popen(asArgs, shell = False,                                        # pylint: disable=consider-using-with
     130                              stdout=subprocess.PIPE, stderr=subprocess.STDOUT);
    130131
    131132    asBuf = []
     
    300301    #       We'll remove them next time we upgrade.
    301302    #
    302     oZip = zipfile.ZipFile(sZipFile, 'r');
     303    oZip = zipfile.ZipFile(sZipFile, 'r');                  # No 'with' support in 2.6 class: pylint: disable=consider-using-with
    303304    asMembers = _doUpgradeCheckZip(oZip);
    304305    if asMembers is None:
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