Changeset 5020


Ignore:
Timestamp:
Feb 11, 2008, 6:20:45 PM (16 years ago)
Author:
ole
Message:

More work on data auditing and added an example license file for
output_ch5-7-9.xls and output_ch5-7-9.txt

Files:
1 added
3 edited

Legend:

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

    r5018 r5020  
    8181        else:
    8282            try:
    83                 license_file_is_valid(fid, dirpath, verbose=verbose)
     83                license_file_is_valid(fid, datafile, dirpath,
     84                                      verbose=verbose)
    8485            except audit_exceptions, e:
    8586                all_files_accounted_for = False                               
     
    151152
    152153
    153 def license_file_is_valid(fid, dirpath='.', verbose=False):
    154     """Check that XML license file is valid.
     154def license_file_is_valid(fid, filename_to_verify,
     155                          dirpath='.', verbose=False):
     156    """Check that XML license file for given filename_to_verify is valid.
     157
     158    Input:
     159        fid: Open file object for XML license file
     160        file_name_to_verify: The data filename that is being audited
     161        dir_path: Where the files live
     162        verbose: Optional verbosity
     163       
    155164
    156165    Check for each datafile listed that
    157166
    158     * Datafile tags are there
     167    * Datafile tags are there and match the one specified
    159168    * Fields are non empty
    160169    * Datafile exists
     
    167176
    168177    license_filename = fid.name
    169    
     178
    170179    doc = xml2object(fid)
    171180    #print doc
     
    224233        datafile = [datafile]
    225234
     235
     236    # Check that filename to verify is listed in license file
     237    found = False
     238    for data in datafile:   
     239        if data['filename'] == filename_to_verify:
     240            found = True
     241    if not found:
     242        msg = 'Specified filename to verify %s ' %filename_to_verify
     243        msg += 'did not appear in license file %s' %license_filename
     244        raise FilenameMismatch, msg               
     245           
     246       
     247    # Check contents
    226248    for data in datafile:
    227249        if verbose: print
     
    231253            msg = 'Missing filename'
    232254            raise FilenameMismatch, msg           
    233         else:   
     255        else:
    234256            filename = join(dirpath, data['filename'])
    235257            if verbose: print 'Filename: "%s"' %filename
  • anuga_core/source/anuga/utilities/test_data_audit.py

    r5015 r5020  
    7676
    7777        try:
    78             license_file_is_valid(licfid)
     78            license_file_is_valid(licfid, tmp_name)
    7979        except CRCMismatch:
    8080            pass
     
    148148
    149149        try:
    150             license_file_is_valid(licfid)
     150            license_file_is_valid(licfid, tmp_name)
    151151        except NotPublishable:
    152152            pass
     
    222222
    223223        try:
    224             license_file_is_valid(licfid)
     224            license_file_is_valid(licfid, basename + '.no_exist')
    225225        except FilenameMismatch:
    226226            pass
     
    290290
    291291        licfid = open(license_filename)
    292         license_file_is_valid(licfid)#, verbose=True)
     292        license_file_is_valid(licfid, data_filename)
    293293        licfid.close()
    294294       
     
    364364
    365365        licfid = open(license_filename)
    366         license_file_is_valid(licfid)#, verbose=True)
     366        license_file_is_valid(licfid, data_filename1)
     367        license_file_is_valid(licfid, data_filename2)       
    367368        licfid.close()
    368369               
  • anuga_core/source/anuga/utilities/xml_tools.py

    r5014 r5020  
    236236        fid = xml
    237237
    238     dom = parse(fid)
     238    try:
     239        dom = parse(fid)
     240    except Exception, e:
     241        # Throw filename into dom exception
     242        msg = 'XML file "%s" could not be parsed: ' %fid.name
     243        msg += str(e)
     244        raise Exception, msg
    239245
    240246    return dom2object(dom)
Note: See TracChangeset for help on using the changeset viewer.