source: CMIP6dreq/manage/step1.py @ 359

Subversion URL: http://proj.badc.rl.ac.uk/svn/exarch/CMIP6dreq/manage/step1.py@359
Revision 359, 2.0 KB checked in by mjuckes, 5 years ago (diff)

adapted 'step1.py' to handle alpha and beta

Line 
1""" Tag generation script.
2--------------------------
3
4USAGE
5-----
6
7python step1.py <version> "<comment on version>"  ## updates versionConfig.py and creates "step2.sh"
8bash step2.sh    ## checks trunk into repository, creates tagged version
9"""
10
11import sys, os, glob, string
12if os.path.isfile( 'step2.sh' ):
13  os.unlink( 'step2.sh' )
14
15svnBaseUrl = 'http://proj.badc.rl.ac.uk/svn/exarch/CMIP6dreq'
16
17ii = string.join( open( 'versionConfig.tmpl' ).readlines() )
18tags = glob.glob( '../tags/*' )
19f1 = lambda x: map( int, string.split(x, '.' ) )
20def f1( vs ):
21  bits = string.split(vs, '.' )
22  estr = 'Version string should be "nn.nn" or "nn.[alpha|beta].nn": %s' % vs
23  assert len(bits) in [2,3], estr
24  if len( bits ) == 3:
25    assert bits[1] in ['alpha','beta'], estr
26  assert len(bits[0]) == 2 and len(bits[-1]) == 2, estr
27  bits[0] = int( bits[0] )
28  bits[-1] = int( bits[-1] )
29  return bits
30
31def tcmp(t1,t2):
32  if len(t1) != len(t2):
33    if t1[0] == t2[0]:
34      return cmp( len(t1), len(t2) )
35    else:
36      return cmp( t1[0], t2[0] )
37  elif len(t1) == 2:
38    if t1[0] == t2[0]:
39      return cmp( t1[1], t2[1] )
40    else:
41      return cmp( t1[0], t2[0] )
42  elif len(t1) == 3:
43    if t1[0] == t2[0]:
44      if t1[1] == t2[1]:
45        return cmp( t1[2], t2[2] )
46      else:
47        return cmp( t1[1], t2[1] )
48    else:
49      return cmp( t1[0], t2[0] )
50   
51thistag, thiscomment = sys.argv[1:]
52thistn = tuple( f1( thistag ) )
53if len(tags) > 0:
54  tn = map( lambda x: tuple( f1(string.split(x,'/')[-1]) ),  tags )
55  tn.sort(tcmp)
56  assert thistn > tn[-1], 'Requested tag not greater than last tag: %s' % str(tn[-1])
57
58oo = open( '../trunk/src/versionConfig.py', 'w' )
59for l in string.split( ii % (thistag, thiscomment), '\n' ):
60  oo.write( '%s\n' % string.strip(l) )
61oo.close()
62
63bashtmpl = """
64tag=%(thistag)s
65comment='"%(thiscomment)s"'
66
67echo $tag, $comment
68cd ../trunk
69svn ci -m "Updated setup for tag %(thistag)s"
70svn copy %(svnBaseUrl)s/trunk %(svnBaseUrl)s/tags/%(thistag)s -m "%(thiscomment)s"
71"""
72
73oo = open( 'step2.sh', 'w' )
74oo.write( bashtmpl % locals() )
75oo.close()
Note: See TracBrowser for help on using the repository browser.