Changeset 361 for CMIP6dreqbuild/trunk/src
- Timestamp:
- 30/07/15 10:37:13 (7 years ago)
- Location:
- CMIP6dreqbuild/trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
CMIP6dreqbuild/trunk/src/framework/dreq.py
r353 r361 15 15 self.mdInit( xmlMiniDom ) 16 16 17 18 17 def dictInit( self, dict ): 19 18 for a in self.attributes: … … 31 30 else: 32 31 self.__dict__[a] = self.defaults.get( a, self.globalDefault ) 33 34 32 35 33 class config(object): 36 34 37 35 def __init__(self): 38 self.vdef = 'out/ parVocabDefn.xml'36 self.vdef = 'out/dreqDefn.xml' 39 37 self.vsamp = 'out/vocabSample.xml' 40 38 self.vsamp = '../workbook/trial.xml' 41 39 self.vsamp = '../workbook/trial_20150724.xml' 42 40 self.nts = collections.namedtuple( 'sectdef', ['tag','label','title','id','itemLabelMode'] ) 43 self.nti = collections.namedtuple( 'itemdef', ['tag','label','title','type' ] )41 self.nti = collections.namedtuple( 'itemdef', ['tag','label','title','type','rClass','techNote'] ) 44 42 self.ntt = collections.namedtuple( 'sect', ['header','attributes'] ) 45 43 … … 127 125 else: 128 126 ty = "xs:string" 129 return self.nti( i.nodeName, l,t,ty ) 127 if i.hasAttribute( 'class' ): 128 cls = i.getAttribute( 'class' ) 129 else: 130 cls = None 131 if i.hasAttribute( 'techNote' ): 132 tn = i.getAttribute( 'techNote' ) 133 else: 134 tn = None 135 return self.nti( i.nodeName, l,t,ty,cls,tn ) 130 136 131 137 c = config() -
CMIP6dreqbuild/trunk/src/framework/ptxt.py
r360 r361 4 4 ptxt.py [-f srcFile] [samp|defn] 5 5 ''' 6 import string, re, collections, sys 6 import string, re, collections, sys, uuid 7 7 8 8 if len(sys.argv) == 1: … … 27 27 re_atdef = re.compile( '^(?P<n>\S+)\s*((\[(?P<b>.*?)\]|\{(?P<a>.*?)\}|\<(?P<c>.*?)\>)\s*){0,3}$' ) 28 28 29 nt__itematt = collections.namedtuple( 'itematt', ['name','type','title','clss'] ) 29 ### tuble to define attributes of an item 30 nt__itematt = collections.namedtuple( 'itematt', ['name','type','title','clss','techn'] ) 30 31 31 32 vocab_elTmpl = '''<table label="%(label)s" title="%(title)s" id="%(id)s" itemLabelMode="%(ilm)s"> … … 33 34 </table> 34 35 ''' 35 ial_elTmpl = ' <rowAttribute label="%(label)s"%(wrappedType)s%(wrappedTitle)s%(wrappedClass)s />'36 ial_elTmpl = ' <rowAttribute label="%(label)s"%(wrappedType)s%(wrappedTitle)s%(wrappedClass)s%(wrappedTechn)s/>' 36 37 37 38 expl_Tmpl = '''<%(label)s class="vocab" title="%(title)s" id="%(id)s"> … … 54 55 self.kk = kk 55 56 self.msg( '[%s] %s {%s:%s}' % (self.label, self.title, self.id, self.ilt) ) 56 self.itematts = [ nt__itematt( 'label','xs:string',None,None ),57 nt__itematt( 'title','xs:string',None,None ) ]57 self.itematts = [ nt__itematt( 'label','xs:string',None,None,None ), 58 nt__itematt( 'title','xs:string',None,None,None ) ] 58 59 59 60 def tmpl(self,oo=None,mode="defn"): … … 61 62 ss = [] 62 63 for i in self.itematts: 63 print i64 64 if i.clss != None: 65 65 wrappedClass = ' class="%s"' % i.clss 66 66 else: 67 67 wrappedClass = '' 68 69 if i.techn != None: 70 wrappedTechn = ' techNote="%s"' % i.techn 71 else: 72 wrappedTechn = '' 68 73 69 74 if i.title != None: … … 102 107 value = "noType" 103 108 if i.type == "xs:string": 104 value = 'dummyAt' 109 if i.name == 'uuid': 110 value = str( uuid.uuid1() ) 111 else: 112 value = 'dummyAt' 105 113 elif i.type == "xs:integer": 106 114 value = '25' … … 132 140 bits = map( string.strip, string.split(line[3:], ';' ) ) 133 141 for b in bits: 134 bn = string.split(b, ' ')[0] 135 x = self.pb(b) 136 self.itematts.append( nt__itematt( bn, x[0], x[1], x[2] ) ) 137 self.msg( '%s, %s, %s, %s' % (bn, x[0], x[1], x[2]) ) 142 if string.strip(b) != '': 143 bn = string.split(b, ' ')[0] 144 x = self.pb(b) 145 self.itematts.append( nt__itematt( bn, x[0], x[1], x[2], x[3] ) ) 146 self.msg( '%s, %s, %s, %s, %s' % (bn, x[0], x[1], x[2], x[3]) ) 138 147 139 148 def pb(self, b): … … 151 160 itemType = ee['b'] 152 161 itemClass = ee['c'] 162 itemTechNote = None 153 163 if itemType == None: 154 164 itemType = 'xs:string' 165 if type(itemClass) == type('x'): 166 if string.find(itemClass, '|' ) != -1: 167 bits = string.split( itemClass, '|' ) 168 assert len(bits) == 2, 'ERROR.001.0001: failed to parse attribute definition: %s' % b 169 itemClass = bits[0] 170 itemTechNote = bits[1] 155 171 156 172 #if len(x) > 0: … … 163 179 #else: 164 180 #itemType = 'xs:string' 165 return [itemType, itemTitle,itemClass ]181 return [itemType, itemTitle,itemClass,itemTechNote] 166 182 167 183 class main(object): -
CMIP6dreqbuild/trunk/src/workbook/importShDreq.py
r356 r361 1 1 """Import data request from shelves and put onto compliant XML document. 2 2 ------------------------------------------------------------------------ 3 A new uuid is generat d for elements of the "revisedtabitem" section/table (because it is not present in the shelve).3 A new uuid is generated for elements of the "revisedtabitem" section/table (because it is not present in the shelve). 4 4 5 5 NOTES … … 34 34 self.src=src 35 35 self.repl = collections.defaultdict( list ) 36 self.err0010 = collections.defaultdict( int ) 36 37 self.replItems = {} 37 38 self.importRepl() … … 64 65 print xsn 65 66 print ff.keys() 66 67 68 self.eern = collections.defaultdict( list ) 69 self.eern2 = {} 70 ixrn = 5 71 dups = [] 72 for k in rq.rqvg.keys(): 73 if k[0] != '_': 74 kk = ['uid', 'mip', 'tab', 'objective', 'grid', 'gridreq', 'comment', 'ref', 'refNote', 'refid'] 75 kk = ['uuid', 'mip', 'label', 'title', 'ref', 'refNote'] 76 i = rq.rqvg[k] 77 78 self.eern[i[ixrn]].append( i[0] ) 79 k2 = '%s__%s' % (i[ixrn-1],i[ixrn]) 80 if self.eern2.has_key( k2 ): 81 dups.append( k2 ) 82 self.eern2[k2] = i[0] 83 assert i[0] == k, 'Bad key/uuid' 84 85 assert len( dups ) == 0, 'Duplicate refs: %s' % str(dups) 86 67 87 for k in [ 'var','ovar','groupitem', 'revisedtabitem', 'requestlink', 'requestitem','requestvargroup' ]: 68 88 ##for k in [ 'var']: … … 165 185 ## - table; mip; uuid; priority 166 186 kk = ['var', 'table', 'mip', 'vid', 'priority'] 187 kvg = 'rev__%s.%s' % ( ll[2],ll[1] ) 188 if self.eern2.has_key(kvg): 189 vgid = self.eern2[kvg] 190 else: 191 vgid = '__none__' 192 self.err0010[kvg] += 1 167 193 thisuuid = str( uuid.uuid1() ) 168 194 thisl = string.strip(str( ll[0] ) ) … … 172 198 item.setAttribute( 'title', thisl ) 173 199 item.setAttribute( 'uuid', thisuuid ) 200 item.setAttribute( 'vgid', vgid ) 174 201 if self.insert.has_key(thisl): 175 202 thisold = item.getAttribute( 'vid' ) … … 193 220 thisl = string.strip(str( '%s-%s-%s' % (ll[0],ll[1],ll[2]) ) ) 194 221 for j in range(len(kk)): 195 item.setAttribute( kk[j], str( ll[j] ) ) 222 if kk[j] == 'ny': 223 thisv = str( int(ll[j]) ) 224 else: 225 thisv = str( ll[j] ) 226 item.setAttribute( kk[j], thisv ) 196 227 item.setAttribute( 'title', '%s, %s, %s' % (ll[0],ll[1],ll[2]) ) 197 228 item.setAttribute( 'uuid', str(i) ) … … 199 230 elif k == 'requestvargroup': 200 231 kk = ['uuid', 'mip', 'label', 'title', 'ref', 'refNote'] 232 thisl = string.replace( str( ll[2] ), '.', '-' ) 201 233 for j in range(len(kk)): 202 234 item.setAttribute( kk[j], str( ll[j] ) ) … … 270 302 self.insert[bits[1]] = bits[3] 271 303 272 sampleXml = '../framework/out/ parVocabSample.xml'304 sampleXml = '../framework/out/dreqSample.xml' 273 305 from scansh import rq 274 306 m = main(sampleXml, rq)
Note: See TracChangeset
for help on using the changeset viewer.