source: CMIP6dreqbuild/trunk/src/framework/compare.py @ 1345

Subversion URL: http://proj.badc.rl.ac.uk/svn/exarch/CMIP6dreqbuild/trunk/src/framework/compare.py
Revision 1345, 3.2 KB checked in by mjuckes, 4 months ago (diff)

march 24

Line 
1
2from dreqPy import dreq
3import os
4import collections
5
6refVersion = '01.00.31'
7mode = "file"
8if mode == "http":
9  import urllib2
10  ref = 'http://proj.badc.rl.ac.uk/svn/exarch/CMIP6dreq/tags/%s/dreqPy/docs/dreq.xml' % refVersion
11  refi = 'http://proj.badc.rl.ac.uk/svn/exarch/CMIP6dreq/tags/%s/dreqPy/docs/dreq2Defn.xml' % refVersion
12  reqi = urllib2.Request(refi)
13  response = urllib2.urlopen(reqi)
14  the_pagei = response.read()
15
16  req = urllib2.Request(ref)
17  response = urllib2.urlopen(req)
18  the_page = response.read()
19  strings = True
20
21else:
22  strings = False
23  the_page = '/data/svn/exarch/CMIP6dreq/tags/%s/dreqPy/docs/dreq.xml' % refVersion
24  the_pagei = '/data/svn/exarch/CMIP6dreq/tags/%s/dreqPy/docs/dreq2Defn.xml' % refVersion
25
26
27print( the_page )
28print( the_pagei )
29dq = dreq.loadDreq( dreqXML=the_page, configdoc=the_pagei, strings=strings, manifest=None )
30print( "Current" )
31dqc = dreq.loadDreq()
32
33print( 'Comparing version %s with current' % refVersion )
34
35s0 = set( dqc.coll.keys() )
36s1 = set( dq.coll.keys() )
37if len( s1.difference( s0 ) ) > 0:
38  print( 'Sections omitted in current: %s' % str( s1.difference( s0 ) ) )
39else:
40  print( 'No sections removed' )
41if len( s0.difference( s1 ) ) > 0:
42  print( 'Sections new in current: %s' % str( s0.difference( s1 ) ) )
43else:
44  print( 'No sections added' )
45
46ss = s0.intersection( s1 )
47dtdall = dict()
48for s in sorted( list(ss) ):
49  lchange = len( dqc.coll[s].items ) - len( dq.coll[s].items )
50  new = {i for i in dqc.coll[s].items if i.uid not in dq.inx.uid}
51  dlab = set()
52  dtd = set()
53  dother = set()
54  for i in dqc.coll[s].items:
55    if i.uid in dq.inx.uid:
56      i1 = dq.inx.uid[i.uid]
57      if i.label != i1.label:
58        dlab.add( i.uid )
59      if i.title != i1.title or ('description' in i.__dict__ and i.description != i1.description):
60        if 'description' in i.__dict__:
61          dtd.add( (i.label,i.title,i.description,i1.label,i1.title,i1.description,'%s%s%s' % (i.label==i1.label,i.title==i1.title,i.description==i1.description) ) )
62        else:
63          dtd.add( (i.label,i.title,"",i1.label,i1.title,"",'%s%s' % (i.label==i1.label,i.title==i1.title) ) )
64      for k in i._a.keys():
65         if i.__dict__.get(k,None) != i1.__dict__.get(k,None):
66           dother.add( i.uid )
67     
68  lnew = len( list( new ) )
69  ldlab = len( list( dlab ) )
70  ltd = len( list( dtd ) )
71  if ltd > 0:
72    dtdall[s] = dtd
73  lother = len( list( dother ) )
74  print( 'Section %16s: changes:: length %4s; records %4s; label %4s; t/d %4s; other %4s' % (s,lchange,lnew,ldlab,ltd,lother) )
75  for i in new:
76    print( '%s: %s [%s]' % (i.uid, i.label, i.title) )
77  ##if len( dq.coll[s].items ) == len( dqc.coll[s].items ):
78    ##print( "Section %s: length unchanged -- %s" % (s,len( dqc.coll[s].items ) )
79  ##elif len( dq.coll[s].items ) < len( dqc.coll[s].items ):
80    ##print( "Section %s: expanded %s to %s" % (s,len( dq.coll[s].items ), len( dqc.coll[s].items ))
81  ##else:
82    ##print "Section %s: shrunk %s to %s" % (s,len( dq.coll[s].items ), len( dqc.coll[s].items ))
83
84
85if len(dtdall.keys()) > 0:
86  oo = open('title_description_changes.csv', 'w' )
87  for k in sorted( dtdall.keys() ):
88     for t in dtdall[k]:
89       oo.write( '\t'.join( t ) + '\n' )
90  oo.close()
91   
92
93
Note: See TracBrowser for help on using the repository browser.