3 # update-lily.py -- lilypond autobuilder
5 # source file of the GNU LilyPond music typesetter
7 # download and rebuild latest lilypond or from specified url
12 * more flexible build/ftp/patches/releases paths
13 * flexible build command
30 gettext.bindtextdomain ('lilypond', '@localedir@')
31 gettext.textdomain('lilypond')
37 sys.path.append ('@datadir@/python')
39 gettext.bindtextdomain ('lilypond', '@localedir@')
40 gettext.textdomain('lilypond')
44 program_name = 'build-lily'
45 package_name = 'lilypond'
46 help_summary = _("Fetch and rebuild from latest source package")
47 build_root = os.path.join (os.environ ['HOME'], 'usr', 'src')
48 release_dir = build_root + '/releases'
49 patch_dir = build_root + '/patches'
55 [ -d %n-%v ] && exit 1 || true;
60 ln -s %n-%v building &&
62 ./configure --prefix=$HOME/usr && make all web
63 ) >> %n-%v/log.txt 2>&1 &&
69 url = 'file:/home/ftp/pub/gnu/LilyPond/development/lilypond-*.tar.gz'
70 url = 'ftp://appel.lilypond.org/pub/gnu/LilyPond/development/lilypond-*.tar.gz'
71 url = 'ftp://ftp.cs.uu.nl/pub/GNU/LilyPond/development/lilypond-*.tar.gz'
76 # lily_py.py -- options and stuff
78 # source file of the GNU LilyPond music typesetter
80 # BEGIN Library for these?
81 # cut-n-paste from ly2dvi
83 program_version = '@TOPLEVEL_VERSION@'
84 if program_version == '@' + 'TOPLEVEL_VERSION' + '@':
85 program_version = '1.3.142'
88 original_dir = os.getcwd ()
89 temp_dir = '%s.dir' % program_name
94 sys.stdout.write ('%s (GNU LilyPond) %s\n' % (program_name, program_version))
98 sys.stdout.write ('\n')
99 sys.stdout.write (_ ('Copyright (c) %s by' % ' 2001'))
100 sys.stdout.write ('\n')
101 sys.stdout.write (' Han-Wen Nienhuys')
102 sys.stdout.write (' Jan Nieuwenhuizen')
103 sys.stdout.write ('\n')
104 sys.stdout.write (_ (r'''
105 Distributed under terms of the GNU General Public License. It comes with
107 sys.stdout.write ('\n')
110 sys.stderr.write (s + '\n')
113 sys.stderr.write (_ ("warning: ") + s)
114 sys.stderr.write ('\n')
118 sys.stderr.write (_ ("error: ") + s)
119 sys.stderr.write ('\n')
120 raise _ ("Exiting ... ")
122 def getopt_args (opts):
123 '''Construct arguments (LONG, SHORT) for getopt from list of options.'''
138 def option_help_str (o):
139 '''Transform one option description (4-tuple ) into neatly formatted string'''
157 return ' ' + sh + sep + long + arg
160 def options_help_str (opts):
161 '''Convert a list of options into a neatly formatted string'''
167 s = option_help_str (o)
168 strs.append ((s, o[3]))
174 str = str + '%s%s%s\n' % (s[0], ' ' * (w - len(s[0]) + 3), s[1])
178 sys.stdout.write (_ ("Usage: %s [OPTION]... FILE") % program_name)
179 sys.stdout.write ('\n\n')
180 sys.stdout.write (help_summary)
181 sys.stdout.write ('\n\n')
182 sys.stdout.write (_ ("Options:"))
183 sys.stdout.write ('\n')
184 sys.stdout.write (options_help_str (option_definitions))
185 sys.stdout.write ('\n\n')
186 sys.stdout.write (_ ("Report bugs to %s") % 'bug-gnu-music@gnu.org')
187 sys.stdout.write ('\n')
193 if not keep_temp_dir_p:
194 temp_dir = tempfile.mktemp (program_name)
196 os.mkdir (temp_dir, 0777)
201 def system (cmd, ignore_error = 0):
203 progress (_ ("Invoking `%s\'") % cmd)
206 msg = ( _ ("error: ") + _ ("command exited with value %d") % st)
208 sys.stderr.write (msg + ' ' + _ ("(ignored)") + ' ')
216 if not keep_temp_dir_p:
218 progress (_ ("Cleaning %s...") % temp_dir)
219 system ('rm -rf %s' % temp_dir)
222 def set_setting (dict, key, val):
224 val = string.atof (val)
226 #warning (_ ("invalid value: %s") % `val`)
230 dict[key].append (val)
232 warning (_ ("no such setting: %s") % `key`)
237 option_definitions = [
238 ('DIR', 'b', 'build-root', _ ("unpack and build in DIR [%s]") % build_root),
239 ('COMMAND', 'c', 'command', _ ("execute COMMAND, subtitute:") \
240 + '\n ' + _ ("%b: build root") \
241 + '\n ' + _ ("%n: package name") \
242 + '\n ' + _ ("%r: release directory") \
243 + '\n ' + _ ("%t: tarball") \
244 + '\n ' + _ ("%v: package version") \
246 ('', 'h', 'help', _ ("this help")),
247 ('', 'k', 'keep', _ ("keep all output, and name the directory %s") % temp_dir),
248 ('EMAIL', 'n', 'notify', _ ("upon failure notify EMAIL[,EMAIL]")),
249 ('', 'r', 'remove-previous', _ ("remove previous build")),
250 ('', 'V', 'verbose', _ ("verbose")),
251 ('', 'v', 'version', _ ("print version number")),
252 ('URL', 'u', 'url', _ ("fetch and build URL [%s]") % url),
253 ('', 'w', 'warranty', _ ("show warranty and copyright")),
256 def list_file (user, passwd, host, dir, file):
258 for i in os.listdir (dir):
259 if fnmatch.fnmatch (i, file):
266 # ugh: use ftp module.
268 def list_ftp (user, passwd, host, dir, file):
272 passwd = program_name
279 ''' % (user, passwd, host, dir, file)
280 temp = tempfile.mktemp (program_name)
284 p = os.popen ('lftp -f %s' % temp, 'r')
287 return string.split (s[:-1], '\n')
290 m = re.match ('([^:/]*)(:)?(/*([^:]*):)?(/*([^@]*)@)?(//([^/]*))?(.*)/(.*)',
293 error ("can't parse url: %s " % url)
294 return (m.group (1), m.group (4), m.group (6), m.group (8),
295 m.group (9), m.group (10))
298 s = "list_%s ('%s', '%s', '%s', '%s', '%s')" % split_url (url)
301 def version_tuple_to_str (t):
303 my = '.%s%d' % (t[3], t[4])
306 return ('%d.%d.%d' % t[0:3]) + my
308 def version_str_to_tuple (s):
309 t = string.split (s, '.')
312 my_number = string.atoi (t[3][-1])
316 return (string.atoi (t[0]), string.atoi (t[1]), string.atoi (t[2]),
319 def split_package (p):
320 m = re.match ('(.*)-([0-9]*.*).tar.gz', p)
321 return (m.group (1), version_str_to_tuple (m.group (2)))
323 def join_package (t):
324 return t[0] + '-' + version_tuple_to_str (t[1])
326 def copy_file (user, passwd, host, dir, file):
327 os.system ('cp %s/%s .' % (dir, file))
331 def copy_ftp (user, passwd, host, dir, file):
335 passwd = program_name
342 ''' % (user, passwd, host, dir, file)
343 temp = tempfile.mktemp (program_name)
347 p = os.popen ('lftp -f %s' % temp, 'r')
351 def copy_url (url, dir):
353 s = "copy_%s ('%s', '%s', '%s', '%s', '%s')" % split_url (url)
357 def find_latest (url):
358 progress (_ ("listing %s...") % url)
359 list = map (split_package, list_url (url))
361 return join_package (list[-1])
364 tar_ball = p + '.tar.gz'
365 (tar_name, tar_version) = split_package (tar_ball)
371 '%v' : version_tuple_to_str (tar_version),
376 for i in expand.keys ():
377 c = re.sub (i, expand[i], c)
380 (sh, long) = getopt_args (__main__.option_definitions)
382 (options, files) = getopt.getopt (sys.argv[1:], sh, long)
393 elif o == '--help' or o == '-h':
395 elif o == '--buid-root' or o == '-b':
397 elif o == '--command' or o == '-c':
399 elif o == '--notify' or o == '-n':
401 elif o == '--remove-previous' or o == '-r':
402 remove_previous_p = 1
403 elif o == '--url' or o == '-u':
405 elif o == '--verbose' or o == '-V':
407 elif o == '--version' or o == '-v':
410 elif o == '--warranty' or o == '-w':
415 latest = find_latest (url)
417 if os.path.isdir ('%s/%s' % (build_root, latest)):
418 progress (_ ("latest is: %s") % latest)
419 progress (_ ("relax, %s is up to date" % package_name))
422 get_base = url[:string.rindex (url, '/')] + '/'
423 if os.path.isdir (patch_dir):
425 if not os.path.isfile (latest + '.diff.gz'):
426 get = get_base + latest + '.diff.gz'
427 progress (_ ("fetching %s...") % get)
430 if not os.path.isdir (build_root):
431 build_root = temp_dir
432 if not os.path.isdir (release_dir):
433 release_dir = temp_dir
436 os.chdir (release_dir)
437 if not os.path.isfile (latest + '.tar.gz'):
438 get = get_base + latest + '.tar.gz'
439 progress (_ ("fetching %s...") % get)
442 if os.path.isdir (os.path.join (build_root, package_name)):
443 os.chdir (os.path.join (build_root, package_name))
444 previous = os.getcwd ()
448 progress (_ ("building %s...") % latest)
449 os.chdir (build_root)
451 if previous and remove_previous_p:
452 system ('rm -rf %s' % os.path.join (build_root, previous))
455 system ('(date; uname -a) | mail -s "%s failed" %s' % (program_name, notify))
458 os.chdir (original_dir)
459 if release_dir != temp_dir: