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