4 # lily-python.py -- implement general LilyPond-wide python stuff
6 # source file of the GNU LilyPond music typesetter
8 # (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
22 version_re
= regex
.compile('\\version *\"\(.*\)\"')
23 # now used as shell script in configure too!
24 # make_assign_re = regex.compile('^\([A-Z_]*\) *= *\(.*\)$')
25 make_assign_re
= regex
.compile('^\([A-Z_]*\)=\(.*\)$')
29 return os
.environ
['MAILADDRESS']
31 return '(address unknown)'
33 def version_tuple(file):
34 lines
= file.readlines()
40 if make_assign_re
.search(l
) <> -1:
41 nm
= make_assign_re
.group(1)
42 val
= make_assign_re
.group(2)
43 # if nm == 'TOPLEVEL_MAJOR_VERSION':
44 if nm
== 'MAJOR_VERSION':
46 # elif nm == 'TOPLEVEL_MINOR_VERSION':
47 elif nm
== 'MINOR_VERSION':
49 # elif nm == 'TOPLEVEL_PATCH_LEVEL':
50 elif nm
== 'PATCH_LEVEL':
52 # elif nm == 'TOPLEVEL_MY_PATCH_LEVEL':
53 elif nm
== 'MY_PATCH_LEVEL':
57 def next_version(tup
):
58 return (tup
[0], tup
[1], tup
[2] + 1, tup
[3]);
60 def prev_version(tup
):
63 t3name
= regsub
.sub('[0-9]*$', '', t
[3])
64 t3level
= atoi(regsub
.sub('[^0-9]*', '', t
[3]))
65 if t3level
and t3level
- 1 > 0:
66 return (tup
[0], tup
[1], tup
[2], t3name
+ `t3level
- 1`
);
68 return (tup
[0], tup
[1], tup
[2], '');
70 return (tup
[0], tup
[1] -1, tup
[2], '');
72 return (tup
[0], tup
[1], tup
[2] - 1, '');
75 return 'lilypond-' + version_tuple_to_str(v
)
78 return dirname(v
) + '.tar.gz'
80 def released_tarball(v
):
81 return lilydirs
.release_dir
+ tarball(v
)
83 def tuple_to_list(tup
):
89 def version_str_to_tuple(str):
96 return (atoi(t
[0]), atoi(t
[1]), atoi(t
[2]), mypatch
)
98 def guess_mudela_version(filename
):
100 lines
= f
.readlines()
103 if version_re
.search(l
) <> -1:
104 return version_re
.group(1)
108 def version_tuple_to_str(tup
):
111 mypatch
= '.' + tup
[3]
113 return ('%d.%d.%d' % tup
[0:3]) + mypatch
118 self
.topdir
= os
.environ
['LILYPOND_SOURCEDIR'] + '/'
121 print 'Please set LILYPOND_SOURCEDIR to the toplevel source, eg LILYPOND_SOURCEDIR=/home/foobar/lilypond-1.2.3/'
125 self
.groupdir
= os
.environ
['LILYPOND_GROUPDIR'] + '/'
127 self
.groupdir
= self
.topdir
+ '../'
129 self
.release_dir
= self
.groupdir
+ '/releases/'
130 self
.patch_dir
= self
.groupdir
+ '/patches/'
132 def version_tuple(self
):
133 f
= open (self
.topdir
+ 'VERSION')
140 lilydirs
= Lilydirs()
142 if __name__
== '__main__':
143 v
= lilydirs
.version_tuple()
144 print v
, prev_version(v
), next_version(v
)
145 mv
= guess_mudela_version(lilydirs
.topdir
+ 'init/symbol.ly')
147 print version_tuple_to_str(pv
), prev_version(pv
), next_version(pv
)
148 print version_tuple_to_str((0,1,1,''))
149 print mv
, version_str_to_tuple(mv
)
166 header_regex
= regex
.compile('\\header[ \t\n]*{\([^}]*\)}')
167 header_entry_regex
= regex
.compile('[\n\t ]*\([^\n\t ]+\)[\n\t ]*=[\n \t]*\([^;]+\)[\n \t]*;')
170 # FIXME breaks on multiple strings.
172 def read_mudela_header (fn
):
174 s
= regsub
.gsub('%.*$', '', s
)
175 s
= regsub
.gsub('\n', ' ', s
)
178 if header_regex
.search(s
) <> -1:
179 h
= header_regex
.group(1)
183 while regex
.search('=', h
) <> -1:
185 if header_entry_regex
.search (h
) == -1:
189 h
= regsub
.sub(header_entry_regex
, '', h
)
190 left
= header_entry_regex
.group(1)
191 right
= header_entry_regex
.group(2)
193 right
= regsub
.gsub('\([^\\]\)\"', '\\1', right
)
194 right
= regsub
.gsub('^"', '', right
)
195 left
= regsub
.gsub('\([^\\]\)\"', '', left
)
196 left
= regsub
.gsub('^"', '', left
)