Ignore:
Timestamp:
Jan 15, 2008, 8:57:07 PM (16 years ago)
Author:
ole
Message:

Work on data IP auditing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/utilities/data_audit.py

    r4939 r4941  
    11"""Track IP of data files included in this distribution.
    2 
    3 
    42"""
    53
    64from os import remove, walk, sep
    7 from os.path import join
     5from os.path import join, splitext
    86
    9 def identify_data_files(distro_dir):
    10     """ Identify potential data files that might violate IP
     7
     8def IP_verified(directory):
     9    """Find and audit potential data files that might violate IP
     10
     11    This is the public function to be used to ascertain that
     12    all data in the specified directory tree has been audited according
     13    to the GA data IP tracking process.
     14
     15    if IP_verified is False:
     16        # Stop and take remedial action
     17        ...
     18    else:
     19        # Proceed boldly with confidence
     20       
     21
    1122    """
    1223
     
    1829    dirwidth = 72
    1930    print '---------------------------------------------'
    20     print 'Directory'.ljust(dirwidth), 'File'
     31    print 'File'.ljust(dirwidth), 'Status'
    2132    print '---------------------------------------------'
    2233
     34    # Identify data files
     35    all_files_accounted_for = True
     36    for dirpath, datafile in identify_datafiles(directory):
     37        print join(dirpath, datafile) + ': ',
     38
     39        basename, ext = splitext(datafile)
     40
     41        # Look for a XML license file with the .lic
     42        try:
     43            fid = open(join(dirpath, basename + '.lic'))
     44        except IOError:
     45            print 'NO LICENSE FILE'
     46            all_files_accounted_for = False
     47        else:
     48            if license_file_is_valid(fid):
     49                print 'OK'
     50            else:
     51                print 'LICENSE FILE NOT VALID'
     52                all_files_accounted_for = False
     53            fid.close()
     54
     55    # Return result       
     56    return all_files_accounted_for
     57
     58
     59def identify_datafiles(root):
     60    """ Identify files that might contain data
     61    """
     62
    2363    # Ignore source code files
    24     extensions_to_ignore = ['.py','.c','.h', '.f'] #,'gif']
     64    extensions_to_ignore = ['.py','.c','.h', '.f'] #, '.gif', '.jpg', '.png']
     65
     66    # Ignore generated stuff
     67    extensions_to_ignore += ['.pyc', '.o', '.so', '~']
     68    extensions_to_ignore += ['.aux', '.log', '.idx', 'ilg', '.ind',
     69                             '.bbl', '.blg']
     70
     71    # Ignore license files themselves
     72    extensions_to_ignore += ['.lic']   
     73   
    2574
    2675    # Ignore certain other files
    2776    files_to_ignore = ['README.txt']
    2877
    29     for dirpath, dirnames, filenames in walk(distro_dir):
     78    # Ignore directories
     79    directories_to_ignore = ['anuga_work', 'pymetis', 'obsolete_code',
     80                             'anuga_parallel', 'anuga_viewer',
     81                             'planning', 'coding_standards',
     82                             'experimentation',
     83                             '.svn', 'misc', '.metadata']
     84
     85    for dirpath, dirnames, filenames in walk(root):
     86
     87        for ignore in directories_to_ignore:
     88            if ignore in dirnames:
     89                dirnames.remove(ignore)  # don't visit ignored directories
    3090
    3191        #print 'Searching dir', dirpath
    32    
     92        
    3393
    3494        for filename in filenames:
     
    45105
    46106            if ignore is False:
    47                 subdirs = dirpath.split(sep)
    48                
    49                 print join(subdirs[3:],sep).ljust(dirwidth), filename
    50        
     107                yield dirpath, filename
    51108
    52109
    53 # FIXME (Ole): Here we could put in a check testing if
    54 # all the files above have a .license file associated with them
    55 # explaining their origins.
     110def license_file_is_valid(fid):
     111    """Check that XML license file is valid
     112    """
    56113
     114    # TODO
     115
     116    print fid.read()
     117    import sys
     118    from xml.dom import minidom
     119    doc =  minidom.parse(fid)
Note: See TracChangeset for help on using the changeset viewer.