# source file of the GNU LilyPond music typesetter
#
# download and rebuild latest lilypond or from specified url
-#
+#
+
'''
TODO:
+
+ * use urllib iso ftplib
+
* more flexible build/ftp/patches/releases paths
- * flexible build command
- * show only?
+
+
+ show only: --command='echo "latest is: %n-%v"'
'''
-import os
+import ftplib
import fnmatch
+import getopt
+import re
+import operator
+import os
+import tempfile
import stat
import string
-import re
-import getopt
import sys
import __main__
-import operator
-import tempfile
-try:
- import gettext
- gettext.bindtextdomain ('lilypond', '@localedir@')
- gettext.textdomain('lilypond')
- _ = gettext.gettext
-except:
- def _ (s):
- return s
-sys.path.append ('@datadir@/python')
-import gettext
-gettext.bindtextdomain ('lilypond', '@localedir@')
-gettext.textdomain('lilypond')
-_ = gettext.gettext
+# if set, LILYPONDPREFIX must take prevalence
+# if datadir is not set, we're doing a build and LILYPONDPREFIX
+datadir = '@datadir@'
+if os.environ.has_key ('LILYPONDPREFIX') \
+ or '@datadir@' == '@' + 'datadir' + '@':
+ datadir = os.environ['LILYPONDPREFIX']
+else:
+ datadir = '@datadir@'
+sys.path.append (os.path.join (datadir, 'python'))
+sys.path.append (os.path.join (datadir, 'python/out'))
program_name = 'build-lily'
-package_name = 'lilypond'
-help_summary = _("Fetch and rebuild from latest source package")
-build_root = os.path.join (os.environ ['HOME'], 'usr', 'src')
-release_dir = build_root + '/releases'
-patch_dir = build_root + '/patches'
-notify = 0
-
-build_command = '''
-set -x
-cd %b &&
-[ -d %n-%v ] && exit 1 || true;
-mkdir -p %n-%v
-(
-tar xzf %r/%t &&
-rm -f building &&
-ln -s %n-%v building &&
-cd %n-%v &&
-./configure --prefix=$HOME/usr && make all web
-) >> %n-%v/log.txt 2>&1 &&
-rm -f %n &&
-ln -s %n%-%v %n
-'''
-
-
-url = 'file:/home/ftp/pub/gnu/LilyPond/development/lilypond-*.tar.gz'
-url = 'ftp://appel.lilypond.org/pub/gnu/LilyPond/development/lilypond-*.tar.gz'
-url = 'ftp://ftp.cs.uu.nl/pub/GNU/LilyPond/development/lilypond-*.tar.gz'
-
-remove_previous_p = 0
-
-
-# lily_py.py -- options and stuff
-#
-# source file of the GNU LilyPond music typesetter
-
-# BEGIN Library for these?
-# cut-n-paste from ly2dvi
-
program_version = '@TOPLEVEL_VERSION@'
-if program_version == '@' + 'TOPLEVEL_VERSION' + '@':
- program_version = '1.3.142'
-
original_dir = os.getcwd ()
-temp_dir = '%s.dir' % program_name
+temp_dir = os.path.join (original_dir, '%s.dir' % program_name)
+errorport = sys.stderr
keep_temp_dir_p = 0
verbose_p = 0
+remove_previous_p = 0
-def identify ():
- sys.stdout.write ('%s (GNU LilyPond) %s\n' % (program_name, program_version))
-
-def warranty ():
- identify ()
- sys.stdout.write ('\n')
- sys.stdout.write (_ ('Copyright (c) %s by' % ' 2001'))
- sys.stdout.write ('\n')
- sys.stdout.write (' Han-Wen Nienhuys')
- sys.stdout.write (' Jan Nieuwenhuizen')
- sys.stdout.write ('\n')
- sys.stdout.write (_ (r'''
-Distributed under terms of the GNU General Public License. It comes with
-NO WARRANTY.'''))
- sys.stdout.write ('\n')
-
-def progress (s):
- sys.stderr.write (s + '\n')
-
-def warning (s):
- sys.stderr.write (_ ("warning: ") + s)
- sys.stderr.write ('\n')
-
-
-def error (s):
- sys.stderr.write (_ ("error: ") + s)
- sys.stderr.write ('\n')
- raise _ ("Exiting ... ")
-
-def getopt_args (opts):
- '''Construct arguments (LONG, SHORT) for getopt from list of options.'''
- short = ''
- long = []
- for o in opts:
- if o[1]:
- short = short + o[1]
- if o[0]:
- short = short + ':'
- if o[2]:
- l = o[2]
- if o[0]:
- l = l + '='
- long.append (l)
- return (short, long)
-
-def option_help_str (o):
- '''Transform one option description (4-tuple ) into neatly formatted string'''
- sh = ' '
- if o[1]:
- sh = '-%s' % o[1]
-
- sep = ' '
- if o[1] and o[2]:
- sep = ','
-
- long = ''
- if o[2]:
- long= '--%s' % o[2]
-
- arg = ''
- if o[0]:
- if o[2]:
- arg = '='
- arg = arg + o[0]
- return ' ' + sh + sep + long + arg
-
-
-def options_help_str (opts):
- '''Convert a list of options into a neatly formatted string'''
- w = 0
- strs =[]
- helps = []
-
- for o in opts:
- s = option_help_str (o)
- strs.append ((s, o[3]))
- if len (s) > w:
- w = len (s)
-
- str = ''
- for s in strs:
- str = str + '%s%s%s\n' % (s[0], ' ' * (w - len(s[0]) + 3), s[1])
- return str
-
-def help ():
- sys.stdout.write (_ ("Usage: %s [OPTION]... FILE") % program_name)
- sys.stdout.write ('\n\n')
- sys.stdout.write (help_summary)
- sys.stdout.write ('\n\n')
- sys.stdout.write (_ ("Options:"))
- sys.stdout.write ('\n')
- sys.stdout.write (options_help_str (option_definitions))
- sys.stdout.write ('\n\n')
- sys.stdout.write (_ ("Report bugs to %s") % 'bug-gnu-music@gnu.org')
- sys.stdout.write ('\n')
- sys.exit (0)
-
+url = 'file:/home/ftp/pub/gnu/LilyPond/development/lilypond-*.tar.gz'
+url = 'ftp://appel.lilypond.org/pub/gnu/LilyPond/development/lilypond-*.tar.gz'
+url = 'ftp://ftp.cs.uu.nl/pub/GNU/LilyPond/development/lilypond-*.tar.gz'
-def setup_temp ():
- global temp_dir
- if not keep_temp_dir_p:
- temp_dir = tempfile.mktemp (program_name)
- try:
- os.mkdir (temp_dir, 0777)
- except OSError:
- pass
-
-
-def system (cmd, ignore_error = 0):
- if verbose_p:
- progress (_ ("Invoking `%s\'") % cmd)
- st = os.system (cmd)
- if st:
- msg = ( _ ("error: ") + _ ("command exited with value %d") % st)
- if ignore_error:
- sys.stderr.write (msg + ' ' + _ ("(ignored)") + ' ')
- else:
- error (msg)
- return st
+build_root = os.path.join (os.environ ['HOME'], 'usr', 'src')
+release_dir = build_root + '/releases'
+patch_dir = build_root + '/patches'
-def cleanup_temp ():
- if not keep_temp_dir_p:
- if verbose_p:
- progress (_ ("Cleaning %s...") % temp_dir)
- system ('rm -rf %s' % temp_dir)
+try:
+ import gettext
+ gettext.bindtextdomain ('lilypond', '@localedir@')
+ gettext.textdomain ('lilypond')
+ _ = gettext.gettext
+except:
+ def _ (s):
+ return s
-def set_setting (dict, key, val):
- try:
- val = string.atof (val)
- except ValueError:
- #warning (_ ("invalid value: %s") % `val`)
- pass
+# Attempt to fix problems with limited stack size set by Python!
+# Sets unlimited stack size. Note that the resource module only
+# is available on UNIX.
+try:
+ import resource
+ resource.setrlimit (resource.RLIMIT_STACK, (-1, -1))
+except:
+ pass
- try:
- dict[key].append (val)
- except KeyError:
- warning (_ ("no such setting: %s") % `key`)
- dict[key] = [val]
-# END Library
+help_summary = _ ("Fetch and rebuild from latest source package")
option_definitions = [
('DIR', 'b', 'build-root', _ ("unpack and build in DIR [%s]") % build_root),
('', 'w', 'warranty', _ ("show warranty and copyright")),
]
+from lilylib import *
+
+
+notify = 0
+
+build_command = '''
+set -x
+cd %b &&
+[ -d %n-%v ] && exit 1 || true;
+mkdir -p %n-%v
+(
+tar xzf %r/%t &&
+rm -f building &&
+ln -s %n-%v building &&
+cd %n-%v &&
+./configure --prefix=$HOME/usr && make all web
+) >> %n-%v/log.txt 2>&1 &&
+rm -f %n &&
+ln -s %n-%v %n
+'''
+
+
def list_file (user, passwd, host, dir, file):
match = []
for i in os.listdir (dir):
list_ = list_file
-#
-# ugh: use ftp module.
-#
def list_ftp (user, passwd, host, dir, file):
if user == 'None':
user = 'anonymous'
if passwd == 'None':
passwd = program_name
- command = '''
-open -u%s,%s -p21 %s
-set passive-mode off
-cd "%s"
-ls -1 "%s"
-''' % (user, passwd, host, dir, file)
- temp = tempfile.mktemp (program_name)
- f = open (temp, 'w')
- f.write (command)
- f.close ()
- p = os.popen ('lftp -f %s' % temp, 'r')
- s = p.read ()
- status = p.close ()
- return string.split (s[:-1], '\n')
+ ftp = ftplib.FTP (host)
+ ftp.login (user, passwd)
+ ftp.set_pasv (1)
+ ftp.cwd (dir)
+ list = ftp.nlst (file)
+ try:
+ ftp.quit ()
+ except:
+ ftp.close ()
+ return list
def split_url (url):
m = re.match ('([^:/]*)(:)?(/*([^:]*):)?(/*([^@]*)@)?(//([^/]*))?(.*)/(.*)',
if passwd == 'None':
passwd = program_name
- command = '''
-open -u%s,%s -p21 %s
-set passive-mode off
-cd "%s"
-get "%s"
-''' % (user, passwd, host, dir, file)
- temp = tempfile.mktemp (program_name)
- f = open (temp, 'w')
- f.write (command)
- f.close ()
- p = os.popen ('lftp -f %s' % temp, 'r')
- s = p.read ()
- status = p.close ()
+ ftp = ftplib.FTP (host)
+ ftp.login (user, passwd)
+ ftp.set_pasv (1)
+ t = tempfile.mktemp (program_name)
+ try:
+ f = open (t, 'w')
+ ftp.retrbinary ('RETR %s/%s' % (dir, file),
+ lambda x, f=f: f.write (x))
+ f.close ()
+ # huh? Invalid cross-device link
+ # os.rename (t, file)
+ system ('mv %s %s' % (t, file))
+ except:
+ os.remove (t)
+ raise 'Foo'
+ try:
+ ftp.quit ()
+ except:
+ ftp.close ()
+ return list
+
+
def copy_url (url, dir):
os.chdir (dir)
s = "copy_%s ('%s', '%s', '%s', '%s', '%s')" % split_url (url)
def find_latest (url):
- progress (_ ("listing %s...") % url)
+ progress (_ ("Listing `%s'...") % url)
list = map (split_package, list_url (url))
list.sort ()
return join_package (list[-1])
c = re.sub (i, expand[i], c)
return system (c, 1)
+
+
(sh, long) = getopt_args (__main__.option_definitions)
try:
- (options, files) = getopt.getopt (sys.argv[1:], sh, long)
-except:
+ (options, files) = getopt.getopt(sys.argv[1:], sh, long)
+except getopt.error, s:
+ errorport.write ('\n')
+ errorport.write (_ ("error: ") + _ ("getopt says: `%s\'" % s))
+ errorport.write ('\n')
+ errorport.write ('\n')
help ()
sys.exit (2)
-
+
for opt in options:
o = opt[0]
a = opt[1]
if 1:
latest = find_latest (url)
- if os.path.isdir ('%s/%s' % (build_root, latest)):
- progress (_ ("latest is %s") % latest)
+ # if os.path.isdir ('%s/%s' % (build_root, latest)):
+ if os.path.exists ('%s/%s/index.html' % (build_root, latest)):
+ progress (_ ("latest is: %s") % latest)
progress (_ ("relax, %s is up to date" % package_name))
sys.exit (0)
os.chdir (patch_dir)
if not os.path.isfile (latest + '.diff.gz'):
get = get_base + latest + '.diff.gz'
- progress (_ ("fetching %s...") % get)
+ progress (_ ("Fetching `%s'...") % get)
copy_url (get, '.')
if not os.path.isdir (build_root):
build_root = temp_dir
+
if not os.path.isdir (release_dir):
release_dir = temp_dir
setup_temp ()
os.chdir (release_dir)
if not os.path.isfile (latest + '.tar.gz'):
get = get_base + latest + '.tar.gz'
- progress (_ ("fetching %s...") % get)
+ progress (_ ("Fetching `%s'...") % get)
copy_url (get, '.')
if os.path.isdir (os.path.join (build_root, package_name)):
else:
previous = 0
- progress (_ ("building %s...") % latest)
+ progress (_ ("Building `%s'...") % latest)
os.chdir (build_root)
- if build (latest) and previous and remove_previous_p:
- system ('rm -rf %s' % os.path.join (build_root, previous))
+ if not build (latest):
+ if previous and remove_previous_p:
+ system ('rm -rf %s' % os.path.join (build_root, previous))
else:
if notify:
system ('(date; uname -a) | mail -s "%s failed" %s' % (program_name, notify))