VirtualBox

Changeset 61988 in vbox


Ignore:
Timestamp:
Jul 1, 2016 5:59:44 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
108435
Message:

common/utils.py,testboxscript_real.py: List the content of the scratch directory after wiping it so that we can see which files remain in bad-testbox cases.

Location:
trunk/src/VBox/ValidationKit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/common/utils.py

    r61980 r61988  
    5454# Python 3 hacks:
    5555if sys.version_info[0] >= 3:
     56    unicode = str;  # pylint: disable=redefined-builtin,invalid-name
    5657    xrange = range; # pylint: disable=redefined-builtin,invalid-name
    5758    long = int;     # pylint: disable=redefined-builtin,invalid-name
     
    298299
    299300
     301def dirEnumerateTree(sDir, fnCallback, fIgnoreExceptions = True):
     302    # type: (string, (string, stat) -> bool) -> bool
     303    """
     304    Recursively walks a directory tree, calling fnCallback for each.
     305
     306    fnCallback takes a full path and stat object (can be None).  It
     307    returns a boolean value, False stops walking and returns immediately.
     308
     309    Returns True or False depending on fnCallback.
     310    Returns None fIgnoreExceptions is True and an exception was raised by listdir.
     311    """
     312    def __worker(sCurDir):
     313        """ Worker for """
     314        try:
     315            asNames = os.listdir(sCurDir);
     316        except:
     317            if not fIgnoreExceptions:
     318                raise;
     319            return None;
     320        rc = True;
     321        for sName in asNames:
     322            if sName not in [ '.', '..' ]:
     323                sFullName = os.path.join(sCurDir, sName);
     324                try:    oStat = os.lstat(sFullName);
     325                except: oStat = None;
     326                if fnCallback(sFullName, oStat) is False:
     327                    return False;
     328                if oStat is not None and stat.S_ISDIR(oStat.st_mode):
     329                    rc =  __worker(sFullName);
     330                    if rc is False:
     331                        break;
     332        return rc;
     333
     334    # Ensure unicode path here so listdir also returns unicode on windows.
     335    ## @todo figure out unicode stuff on non-windows.
     336    if sys.platform == 'win32':
     337        sDir = unicode(sDir);
     338    return __worker(sDir);
     339
     340
     341
     342def formatFileMode(uMode):
     343    # type: (int) -> string
     344    """
     345    Format a st_mode value 'ls -la' fasion.
     346    Returns string.
     347    """
     348    if   stat.S_ISDIR(uMode):   sMode = 'd';
     349    elif stat.S_ISREG(uMode):   sMode = '-';
     350    elif stat.S_ISLNK(uMode):   sMode = 'l';
     351    elif stat.S_ISFIFO(uMode):  sMode = 'p';
     352    elif stat.S_ISCHR(uMode):   sMode = 'c';
     353    elif stat.S_ISBLK(uMode):   sMode = 'b';
     354    elif stat.S_ISSOCK(uMode):  sMode = 's';
     355    else:                       sMode = '?';
     356    ## @todo sticky bits.
     357    sMode += 'r' if uMode & stat.S_IRUSR else '-';
     358    sMode += 'w' if uMode & stat.S_IWUSR else '-';
     359    sMode += 'x' if uMode & stat.S_IXUSR else '-';
     360    sMode += 'r' if uMode & stat.S_IRGRP else '-';
     361    sMode += 'w' if uMode & stat.S_IWGRP else '-';
     362    sMode += 'x' if uMode & stat.S_IXGRP else '-';
     363    sMode += 'r' if uMode & stat.S_IROTH else '-';
     364    sMode += 'w' if uMode & stat.S_IWOTH else '-';
     365    sMode += 'x' if uMode & stat.S_IXOTH else '-';
     366    sMode += ' ';
     367    return sMode;
     368
     369
     370def formatFileStat(oStat):
     371    # type: (stat) -> string
     372    """
     373    Format a stat result 'ls -la' fasion (numeric IDs).
     374    Returns string.
     375    """
     376    return '%s %3s %4s %4s %10s %s' \
     377          % (formatFileMode(oStat.st_mode), oStat.st_nlink, oStat.st_uid, oStat.st_gid, oStat.st_size,
     378             time.strftime('%Y-%m-%d %H:%M', time.localtime(oStat.st_mtime)), );
     379
     380
    300381#
    301382# SubProcess.
  • trunk/src/VBox/ValidationKit/testboxscript/testboxscript_real.py

    r61829 r61988  
    718718                    fnLog('Error deleting "%s": %s' % (sFullName, oXcpt));
    719719                    oRc.fRc = False;
     720
     721        # Display files left behind.
     722        def dirEnumCallback(sName, oStat):
     723            """ callback for dirEnumerateTree """
     724            fnLog(u'%s %s' % (utils.formatFileStat(oStat) if oStat is not None else '????????????', sName));
     725        utils.dirEnumerateTree(self._oOptions.sScratchRoot, dirEnumCallback);
    720726
    721727        #
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