Changeset 3815


Ignore:
Timestamp:
23/04/08 09:54:16 (12 years ago)
Author:
cbyrom
Message:

Improve the FileUtilities? - using 'find' to get the various required filenames in a more
effective manner + add logging support and improve output.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI01-discovery/branches/ingestAutomation-upgrade/OAIBatch/FileUtilities.py

    r3810 r3815  
    1 import os, sys 
    2 from Logger import Logger 
     1import os, sys, logging 
    32 
    43class FileUtilities: 
     
    76    C Byrom Apr 08 
    87    ''' 
    9     logger = None 
    10     def __init__(self, inLogger): 
     8    def __init__(self): 
    119        ''' 
    12         Constructor - to set up the utils with a default logger 
    13         @param logger: logger to use; if none specified, use default logger.  NB, logger must  
    14                 support a 'printOutput' method 
     10        Constructor 
    1511        ''' 
    16         if inLogger is not None: 
    17             self.logger = inLogger 
    18         else: 
    19             self.logger = Logger(True) 
    2012 
    2113 
     
    3628        from os.path import normpath,dirname,exists,abspath 
    3729     
    38         self.logger.printOutput("INFO: Creating dir: " + path)  
     30        logging.info("Creating dir: " + path)  
    3931        dpath = normpath(dirname(path)) 
    4032        if not exists(dpath): 
     
    4840        @param dir: directory to set up/clean 
    4941        ''' 
    50         self.logger.printOutput("Setting up directory, " + dir) 
     42        logging.info("Setting up directory, " + dir) 
    5143        if os.path.isdir(dir): 
    5244            self.cleanDir(dir) 
     
    6355        @param dir: directory to clean  
    6456        ''' 
    65         self.logger.printOutput("INFO: Cleaning dir " + dir) 
    66         commandline = "ls -1 " + dir + " | xargs -i rm " + dir + "{\}" 
    67         self.logger.printOutput("INFO: Executing : " + commandline) 
    68          
     57        logging.info("Cleaning dir " + dir) 
     58        commandline = "find " + dir + "  -type f -print | xargs -i rm \{\}" 
     59        logging.debug("Executing : " + commandline) 
     60 
    6961        status = os.system(commandline) 
    7062        if status !=0: 
     
    7870        @param backup_dir: dir to backup to   
    7971        ''' 
    80         self.logger.printOutput("Creating backup directory (" + original_dir + \ 
     72        logging.info("Creating backup directory (" + original_dir + \ 
    8173                                " --> " + backup_dir + ")") 
    8274        commandline = "mkdir " + backup_dir 
    83         self.logger.printOutput("INFO: Executing : " + commandline) 
     75        logging.debug("Executing : " + commandline) 
    8476        status = os.system(commandline) 
    8577        if status !=0: 
    8678            sys.exit("Failed at creating backup directory %s" %backup_dir) 
    8779     
    88             commandline = "ls -1 " + original_dir + " | xargs -i cp " + original_dir + "{\} " + backup_dir 
    89             self.logger.printOutput("INFO: Executing : " + commandline) 
     80#            commandline = "ls -1 " + original_dir + " | xargs -i cp " + original_dir + "{\} " + backup_dir 
     81            commandline = "find " + original_dir + " -type f -print | xargs -i cp \{\} " + backup_dir 
     82            logging.info("Executing : " + commandline) 
    9083            status = os.system(commandline) 
    9184            if status !=0: 
Note: See TracChangeset for help on using the changeset viewer.