Changeset 273


Ignore:
Timestamp:
19/01/15 19:31:17 (5 years ago)
Author:
mjuckes
Message:

support for enumerations in attribute values (for esa-cci)

Location:
CCCC/trunk/ceda_cc
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • CCCC/trunk/ceda_cc/config/esacci_vocabs/sampleGlobalAts.txt

    r270 r273  
    3333standard_name_vocabulary (the name of the controlled vocabulary from which variable standard names are taken) 
    3434license (describe the restrictions to data access and distribution) 
    35 platform Envisat 
     35platform ERS-<1,2>, Envisat 
    3636sensor AATSR 
    3737spatial_resolution 1.1km at nadir 
  • CCCC/trunk/ceda_cc/config_c4.py

    r270 r273  
    180180               'version':utils.patternControl( 'version',  '^(fv[0-9]+(\.[0-9]+){0,1})$' ), \ 
    181181               'level':utils.listControl( 'level', lrdr.getSimpleList( 'procLevel01.txt', bit=0 ) ), \ 
    182                'platform':utils.listControl( 'platforms', lrdr.getSimpleList( 'platforms.txt', bit=0 ) ), \ 
     182               'platform':utils.listControl( 'platforms', lrdr.getSimpleList( 'platforms.txt', bit=0), enumeration=True, split=True, splitVal=',' ), \ 
    183183               'institution':utils.listControl( 'institution', lrdr.getSimpleList( 'institutions.txt', omt='last' ) ), \ 
    184184               'Conventions':utils.patternControl( 'Conventions', '^CF-1.[56789](,.*){0,1}$' ), \ 
  • CCCC/trunk/ceda_cc/unitTestsS1.py

    r269 r273  
    290290else: 
    291291  print 'OK: [%s]: detected bad global attributes (%s)' % (testId,gafile) 
     292 
     293 
     294ls = utils_c4.listControl('test',['a','b','c1','c2'],split=True,splitVal=',',enumeration=True) 
     295testId = '#05.001' 
     296res = ls.essplit.findall( 'a, b, c<1,2>') 
     297if res == ['a', 'b', 'c<1,2>']: 
     298  print 'OK: [%s] Split of list with enumeration passed' % (testId) 
     299else: 
     300  print 'Failed: [%s] Split of list with enumeration failed %s' % (testId,str(res)) 
     301 
     302testId = '#05.002' 
     303res = ls.check( 'a, c<1,2>' ) 
     304if res: 
     305  print 'OK: [%s] Valid value passed' % (testId) 
     306else: 
     307  print 'Failed: [%s] valid value rejected %s' % (testId,str(res)) 
     308 
     309testId = '#05.003' 
     310res = ls.check( 'a, c<1,3>' ) 
     311if res: 
     312  print 'Failed: [%s] Invalid value passed' % (testId) 
     313else: 
     314  print 'OK: [%s] Invalid value rejected %s' % (testId,str(res)) 
     315 
     316 
     317 
  • CCCC/trunk/ceda_cc/utils_c4.py

    r269 r273  
    971971     
    972972class listControl(object): 
    973   def __init__(self,tag,list,split=False,splitVal=None): 
     973  def __init__(self,tag,list,split=False,splitVal=None,enumeration=False): 
    974974    self.list = list 
    975975    self.tag = tag 
    976976    self.split = split 
    977977    self.splitVal = splitVal 
     978    self.enumeration = enumeration 
     979    self.etest = re.compile( '(.*)<([0-9]+(,[0-9]+)*)>' ) 
     980    self.essplit = re.compile(r'(?:[^\s,<]|<(?:\\.|[^>])*>)+') 
    978981 
    979982  def check(self,val): 
     
    986989      if self.splitVal == None: 
    987990        vs = string.split( val ) 
     991      elif self.enumeration: 
     992        vs = map( string.strip, self.essplit.findall( val ) ) 
    988993      else: 
    989         vs = string.split( val, self.spliVal ) 
    990       return all( map( lambda x: x in self.list, vs ) ) 
    991     else: 
    992       return val in self.list 
     994        vs = map( string.strip, string.split( val, self.splitVal ) ) 
     995    else: 
     996      vs = [val,] 
     997    if self.enumeration: 
     998      vs2 = [] 
     999      for v in vs: 
     1000        m = self.etest.findall( v ) 
     1001        if m in [None,[]]: 
     1002          vs2.append( v ) 
     1003        else: 
     1004          opts = string.split( m[0][1], ',' ) 
     1005          for o in opts: 
     1006            vs2.append( '%s%s' % (m[0][0],o) ) 
     1007      vs = vs2[:] 
     1008         
     1009    return all( map( lambda x: x in self.list, vs ) ) 
    9931010 
    9941011 
Note: See TracChangeset for help on using the changeset viewer.