6 # packagepython.py -- implement general StepMake-wide python stuff
8 # source file of the GNU LilyPond music typesetter
10 # (c) 1997--2006 Han-Wen Nienhuys <hanwen@stack.nl>
11 # Jan Nieuwenhuizen <janneke@gnu.org>
20 make_assign_re = re.compile ('^([A-Z_]*)=(.*)$')
22 def read_makefile (fn):
24 lines = file.readlines()
31 m = make_assign_re.search (l)
39 def __init__ (self, dirname):
40 dict = read_makefile (dirname + '/VERSION')
42 for x in [ 'MAJOR_VERSION', 'MINOR_VERSION', 'PATCH_LEVEL']:
43 version_list.append (string.atoi (dict[x]))
44 version_list.append (dict['MY_PATCH_LEVEL'])
46 self.groupdir = self.topdir + '/..'
47 self.patch_dir = self.groupdir + '/patches/'
48 self.release_dir = self.groupdir + '/releases/'
49 self.test_dir = self.groupdir + '/test/'
50 self.version = tuple(version_list)
51 self.Name = dict['PACKAGE_NAME']
52 self.name = string.lower (self.Name)
53 if self.name == 'lilypond':
54 self.nickname = 'lelie'
56 self.nickname = self.name
57 self.NAME = string.upper (self.Name)
63 m= os.environ['MAILADDRESS']
65 m= '(address unknown)'
68 m= os.environ['WEBMASTER']
74 def full_version_tup(tup):
83 def split_my_patchlevel (str):
84 m = re.match ('(.*?)([0-9]*)$', str)
85 return (m.group (1), string.atoi (m.group (2)))
87 def next_version(tup):
88 l = list(full_version_tup (tup))
91 (t3name,t3num)= split_my_patchlevel (l[3])
93 t3num = '%d' % (t3num + 1)
99 return tuple(l[0:3] + [t3name + t3num])
101 def prev_version(tup):
102 l = list(full_version_tup (tup))
105 (t3name, t3num) = split_my_patchlevel (l[3])
106 if t3num and t3num - 1 > 0:
107 t3num = '%d' %(t3num - 1)
114 return tuple(l[0:3] + [t3name + t3num])
116 def version_tuple_to_str(tup):
117 tup = full_version_tup (tup)
122 return ('%d.%d.%d' % tup[0:3]) + my
124 def version_str_to_tuple(str):
125 t = string.split(str, '.')
128 mypatch = string.join (t[3:], '.')
129 return (string.atoi(t[0]), string.atoi(t[1]), string.atoi(t[2]), mypatch)
131 def version_compare (ltup, rtup):
132 rtup = full_version_tup (ltup)
133 rtup = full_version_tup (rtup)
135 if ltup[i] - rtup[i]: return ltup[i] - rtup[i]
136 if ltup[3] and rtup[3]:
137 (lname, lnum) = split_my_patchlevel (ltup[i])
138 (rname, rnum) = split_my_patchlevel (rtup[3])
141 return sign (lnum - rnum)
147 if __name__ == '__main__':
150 print v, prev_version(v), next_version(v)
152 print version_tuple_to_str(pv), prev_version(pv), next_version(pv)
153 print version_tuple_to_str((0,1,1,''))
154 print full_version_tup ((0,1))