Houston, we have a trunk.
[debian/gnuradio] / dtools / python / release_tools.py
1 #
2 # Copyright 2005 Free Software Foundation, Inc.
3
4 # This file is part of GNU Radio
5
6 # GNU Radio is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
9 # any later version.
10
11 # GNU Radio is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Radio; see the file COPYING.  If not, write to
18 # the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 # Boston, MA 02111-1307, USA.
20
21
22 import re
23 import os
24
25 def get_release(configure_ac_filename):
26     f = open(configure_ac_filename,'r')
27     contents = f.read()
28     pat = re.compile('^AM_INIT_AUTOMAKE\((.*),(\d+)\.(\d+)(.*)\)', re.M)
29     mo = pat.search(contents)
30     if mo:
31         return mo.groups()
32
33 def set_release(configure_ac_filename, new_release):
34     f = open(configure_ac_filename,'r')
35     contents = f.read()
36     pat = re.compile('^AM_INIT_AUTOMAKE\(((.*),(\d+)\.(\d+)(.*))\)', re.M)
37     repl = ''.join(('AM_INIT_AUTOMAKE(',
38                     new_release[0],
39                     ',',
40                     new_release[1],
41                     '.',
42                     new_release[2],new_release[3],')'))
43     new = pat.sub(repl, contents)
44     return new
45
46 def incr_release(configure_ac_filename, final=False):
47     cur = get_release(configure_ac_filename)
48     if cur is None:
49         raise ValueError, "%s: couldn't find version" % (configure_ac_filename,)
50     new = set_release(configure_ac_filename, up_rev(cur, final))
51     os.rename(configure_ac_filename, configure_ac_filename + '.bak')
52     f = open(configure_ac_filename,'w')
53     f.write(new)
54     f.close()
55
56 def up_rev(current_rev, final=False):
57     """
58     X.Y -> X.Ycvs
59     if final:
60       X.Ycvs -> X.(Y+1)rc1
61     else:
62       X.Ycvs -> X.(Y+1)
63     if final:
64       X.YrcN -> X.Y
65     else
66       X.YrcN -> X.Yrc(N+1)
67     """
68     pkg, major, minor, suffix = current_rev
69
70     if len(suffix) == 0:
71         if final:
72             raise RuntimeError, ("Can't go from current to final.  current = " + str(current_rev))
73         return (pkg, major, minor, "cvs")
74     if suffix == "cvs":
75         if final:
76             return (pkg, major, str(int(minor)+1), "")
77         return (pkg, major, str(int(minor)+1), "rc1")
78     elif suffix.startswith('rc'):
79         if final:
80             return (pkg, major, minor, "")
81         return (pkg, major, minor, "rc" + (str(int(suffix[2:]) + 1)))
82
83 def make_tag(current_rev):
84     pkg, major, minor, suffix = current_rev
85     if suffix == "cvs":
86         raise ValueError, "You tried to tag a X.Ycvs release..."
87     return 'REL_%s_%s%s' % (major, minor, suffix)