Changeset 507d47f in flex_extract.git


Ignore:
Timestamp:
Feb 5, 2018, 2:50:48 PM (22 months ago)
Author:
Anne Philipp <bscannephilipp@…>
Branches:
dev
Children:
9ac56ea
Parents:
a4b6cef
Message:

pep8 changes + docs added + todo on UIOTools.py

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/UIOTools.py

    rd69b677 r507d47f  
    1 #!/usr/bin/env python                                                                                                                                                                     
    2 #                                                                                                                                                                                         
     1#!/usr/bin/env python
     2#
    33# (C) Copyright 2014 UIO.
    44#
     
    99#
    1010
     11
     12#************************************************************************
     13# TODO AP
     14#
     15# - File name und Klassenname gleichsetzen?
     16# - checken welche regelmässigen methoden auf diese Files noch angewendet werden
     17# und dann hier implementieren
     18# - löschen?
     19#************************************************************************
     20
    1121import os
    1222import glob
    1323
    1424class UIOFiles:
    15     'class to manipulate files'
    16     def __init__(self,suffix):
    17 # type of files to manipulate such as ['.grib', 'grb', 'grib1', 'grib2', 'grb1','grb2']
    18         self.suffix=suffix
     25    '''
     26    Class to manipulate files. At initialisation it has the attribute
     27    suffix which stores a list of suffixes of the files associated
     28    with the instance of the class.
     29    '''
    1930
    20     def listFiles(self,pathname,pattern):
    21         ''' list files (suffix previously given) within this directory. '''
    22     # Get the absolute path of the pathname parameter
     31    def __init__(self, suffix):
     32        '''
     33        @Description:
     34            Assignes the suffixes of the files which should be
     35            associated with the instance of the class.
     36
     37        @Input:
     38            self: instance of UIOFiles
     39                Description see class documentation.
     40
     41            suffix: list of strings
     42                Types of files to manipulate such as
     43                ['.grib', 'grb', 'grib1', 'grib2', 'grb1','grb2']
     44
     45        @Return:
     46            <nothing>
     47        '''
     48        self.suffix = suffix
     49        return
     50
     51    def listFiles(self, pathname, pattern):
     52        '''
     53        @Description:
     54            Lists all files in the directory with the matching
     55            regular expression pattern. The suffixes are already stored
     56            in a list attribute "suffix".
     57
     58        @Input:
     59            self: instance of UIOFiles
     60                Description see class documentation.
     61
     62            pathname: string
     63                Directory where to list the files.
     64
     65            pattern: string
     66                Regular expression pattern. For example:
     67                '*OG_acc_SL*.'+c.ppid+'.*'
     68
     69        @Return:
     70            <nothing>
     71        '''
     72        # Get the absolute path of the pathname parameter
    2373        pathname = os.path.abspath(pathname)
    24  
    25     # Get a list of files in pathname
    26         filesInCurDir0 = glob.glob(pathname+'/'+pattern)
    27         filesInCurDir=[]
     74
     75        # Get a list of files in pathname
     76        filesInCurDir0 = glob.glob(pathname + '/' + pattern)
     77        filesInCurDir = []
    2878        for f in filesInCurDir0:
    2979            filesInCurDir.append(f.split('/')[-1])
    3080        self.counter = 0
    3181        self.files = []
    32     # Traverse through all files
     82        # Traverse through all files
    3383        for file in filesInCurDir:
    3484            curFile = os.path.join(pathname, file)
    35  
    36         # Check if it's a normal file or directory
     85
     86            # Check if it's a normal file or directory
    3787            if os.path.isfile(curFile):
    3888                # Get the file extension
    39                 fileNoExt,curFileExtension = os.path.splitext(curFile)
     89                fileNoExt, curFileExtension = os.path.splitext(curFile)
    4090                # Check if the file has an extension of typical video files
    4191                if curFileExtension in self.suffix:
     
    4494                    # add this filename in the list
    4595                    self.files.append(curFile)
    46                    
    4796            else:
    4897                # We got a directory, enter into it for further processing
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG