Ignore:
Timestamp:
05/05/09 10:21:19 (11 years ago)
Author:
cbyrom
Message:

Tighten up package definition to allow overlap with ndg.security +
adjust resource finding for this scenario + improve fileutilities
cleandir method, using python code rather than system ops to do work +
relax equality method for abstract records slightly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ndgCommon/trunk/ndg/common/src/lib/fileutilities.py

    r5058 r5246  
    8686    ''' 
    8787    logging.info("Cleaning dir " + dir) 
    88     commandline = "find " + dir + "  -type f -print | xargs -i rm \{\}" 
    89     logging.debug("Executing : " + commandline) 
     88    # add in a little safety check here - we don't want to delete large chunks 
     89    # of the filesystem by accident... 
     90    if dir.strip().startswith('/') and len(dir) < 5: 
     91        raise ValueError("Top level directory specified (or something close to this) - will not delete the entire system") 
    9092 
    91     status = os.system(commandline) 
    92     if status != 0: 
    93         sys.exit("Failed at cleaning out directory, %s" %dir) 
    94      
     93    for root, dirs, files in os.walk(dir, topdown=False): 
     94        for name in files: 
     95            os.remove(os.path.join(root, name)) 
     96        for name in dirs: 
     97            os.rmdir(os.path.join(root, name)) 
    9598    logging.info("Directory cleaned successfully") 
    9699 
Note: See TracChangeset for help on using the changeset viewer.