Changeset 4944


Ignore:
Timestamp:
Jan 16, 2008, 2:44:05 PM (17 years ago)
Author:
ole
Message:

IP tracking work

Location:
anuga_core/source/anuga/utilities
Files:
3 added
1 edited

Legend:

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

    r4941 r4944  
    44from os import remove, walk, sep
    55from os.path import join, splitext
     6
     7from anuga.utilities.xml_tools import parse, print_tree, get_elements, get_text
     8
     9# Audit exceptions
     10class NotPublishable(Exception): pass
     11class Invalid(Exception): pass
     12class WrongTags(Exception): pass
    613
    714
     
    112119    """
    113120
    114     # TODO
    115 
    116     print fid.read()
    117     import sys
    118     from xml.dom import minidom
    119     doc =  minidom.parse(fid)
     121    doc = parse(fid)
     122    #print_tree(doc)
     123
     124    # Check that file is valid (e.g. all elements there)
     125    # FIXME (Ole): Todo
     126   
     127
     128    if doc.nodeName != '#document':
     129        msg = 'License file %s does not appear' %fid.name
     130        msg += 'to be a valid XML document'
     131        msg += 'The root node has name %s' %doc.nodeName
     132        msg += 'but it should be %s' %'#document'
     133        raise Invalid, msg       
     134
     135    if len(doc.childNodes) != 2:
     136        msg = 'License file %s must have two elements' %fid.name
     137        msg += ' at the root level. They are\n '
     138        msg += '<?xml version="1.0" encoding="iso-8859-1"?>\n'
     139        msg += '<ga_license_file>'
     140        raise Invalid, msg
     141   
     142
     143    # Start looking at document in earnest
     144    root_node = doc.childNodes[1]
     145    if root_node.nodeName != 'ga_license_file':
     146        msg = 'License file %s must have two elements' %fid.name
     147        msg += ' at the root level. They are\n '
     148        msg += '<?xml version="1.0" encoding="iso-8859-1"?>\n'
     149        msg += '<ga_license_file>\n'
     150        msg += 'The second element was found to be %s' %root_node.nodeName
     151        raise WrongTags, msg
     152   
     153
     154    # Validate elements: source, datafile, datafile, ...
     155    elements = get_elements(root_node.childNodes)
     156    if elements[0].nodeName != 'source':
     157        msg = 'The first element under %s must be "source"'\
     158              %root_node.nodeName
     159        msg += 'The element found was %s' %elements[0].nodeName
     160        raise WrongTags, msg
     161
     162    for node in elements[1:]:
     163        if node.nodeName != 'datafile':
     164            msg = 'All elements, except the first, under %s must '\
     165                  %root_node.nodeName           
     166            msg += 'be "datafile"'
     167            msg += 'The element found was %s' %node.nodeName
     168            raise WrongTags, msg       
     169
     170    print
     171    # Extract information for source section
     172    for node in get_elements(elements[0].childNodes):
     173        if node.nodeName == 'author':
     174            # Do something
     175            print 'Author is', get_text(node.childNodes)
     176
     177        if node.nodeName == 'svn_keywords':
     178            # Do something
     179            pass
     180       
     181    # Extract information for datafile sections
     182    for datanode in elements[1:]:
     183        print   
     184   
     185        for node in get_elements(datanode.childNodes):
     186            #print 'Node', node.nodeName, node.childNodes
     187            #continue
     188           
     189            if node.nodeName == 'filename':
     190                # FIXME Check correctness
     191                print 'Filename is "%s"' %get_text(node.childNodes)
     192
     193            if node.nodeName == 'accountable':
     194                print 'Accountable is "%s"' %get_text(node.childNodes)
     195
     196            if node.nodeName == 'location':
     197                print 'Location is "%s"' %get_text(node.childNodes)
     198
     199            if node.nodeName == 'IP_owner':
     200                print 'IP owner is "%s"' %get_text(node.childNodes)
     201
     202            if node.nodeName == 'IP_info':
     203                print 'IP info is "%s"' %get_text(node.childNodes)                               
     204               
     205
     206            if node.nodeName == 'publishable':
     207                value = get_text(node.childNodes)
     208                if value.upper() != 'YES':
     209                    msg = 'Data file %s is not flagged as publishable'\
     210                          %fid.name
     211                    print msg
     212                    #raise NotPublishable, msg
     213                else:
     214                    print 'Data file %s is flagged publishable' %fid.name               
     215       
     216   
     217    #for node in elements:
     218    #    print node
     219    #print
     220
     221
     222
     223    # Check that file is deemed publishable
     224    items = doc.getElementsByTagName('publishable')
     225    for i in items:
     226        print i
     227        #i.getAttribute()
Note: See TracChangeset for help on using the changeset viewer.