Changeset 25b14be in flex_extract.git for source/python/classes/UioFiles.py


Ignore:
Timestamp:
Sep 23, 2018, 11:40:28 AM (6 years ago)
Author:
Anne Philipp <anne.philipp@…>
Branches:
master, ctbto, dev
Children:
4971f63
Parents:
5d42acd
Message:

changed whole tree structure of flex_extract to have better overview

File:
1 moved

Legend:

Unmodified
Added
Removed
  • source/python/classes/UioFiles.py

    r2fb99de r25b14be  
    5252# software specific module from flex_extract
    5353#import profiling
    54 from tools import silent_remove, get_list_as_string
     54from mods.tools import silent_remove, get_list_as_string
    5555
    5656# ------------------------------------------------------------------------------
     
    6060class UioFiles(object):
    6161    '''
    62     Class to manipulate files. At initialisation it has the attribute
    63     pattern which stores a regular expression pattern for the files associated
    64     with the instance of the class.
     62    Class to manipulate files. At initialisation it has the pattern
     63    which stores a regular expression pattern for the files, the path
     64    to the files and the files already.
    6565    '''
    6666    # --------------------------------------------------------------------------
     
    8888        self.path = path
    8989        self.pattern = pattern
    90         self.files = None
     90        self.files = []
    9191
    9292        self.__list_files__(self.path)
     
    9595
    9696    #@profiling.timefn
    97     def __list_files__(self, path, callid=0):
     97    def __list_files__(self, path):
    9898        '''
    9999        @Description:
     
    108108                Path to the files.
    109109
    110             callid: integer
    111                 Id which tells the function if its the first call
    112                 or a recursive call. Default and first call is 0.
    113                 Everything different from 0 is ment to be a recursive case.
    114 
    115110        @Return:
    116111            <nothing>
    117112        '''
    118 
    119         # initialize variable in first function call
    120         if callid == 0:
    121             self.files = []
    122 
    123113        # Get the absolute path
    124114        path = os.path.abspath(path)
    125115
    126         # get the file list of the path if its not a directory and
    127         # if it contains the pattern
    128         self.files.extend([os.path.join(path, k) for k in os.listdir(path)
    129                            if fnmatch.fnmatch(k, self.pattern)])
    130 
    131         # find possible sub-directories in the path
    132         subdirs = [s for s in os.listdir(path)
    133                    if os.path.isdir(os.path.join(path, s))]
    134 
    135         # do recursive calls for sub-direcorties
    136         if subdirs:
    137             for subdir in subdirs:
    138                 self.__list_files__(os.path.join(path, subdir), callid=1)
     116        # get all files in the dir and subdir as absolut path
     117        for root, dirnames, filenames in os.walk(path):
     118            for filename in fnmatch.filter(filenames, self.pattern):
     119                self.files.append(os.path.join(root, filename))
    139120
    140121        return
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG