Mercurial > gub
view bin/gupdate @ 6512:ccc20ae889ca default tip guix
mingw::guile-2.0.7 builds.
author | Jan Nieuwenhuizen <janneke@gnu.org> |
---|---|
date | Thu, 24 Mar 2016 08:03:39 +0100 |
parents | e537c5665092 |
children |
line wrap: on
line source
#! /usr/bin/env python """ Copyright (c) 2005--2009 Jan Nieuwenhuizen <janneke@gnu.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. """ def argv0_relocation (): import os, sys bindir = os.path.dirname (sys.argv[0]) prefix = os.path.dirname (bindir) if not prefix: prefix = bindir + '/..' sys.path.insert (0, prefix) argv0_relocation () import optparse import os import re import sys # from gub import misc from gub.syntax import printf def parse_command_line (): p = optparse.OptionParser () p.description = 'GUB updater - check for and show or update new upstream releases.' p.usage = 'gupdate [OPTION]... SPEC...' p.add_option ('--replace', action='store_true', help='replace old urls.') examples = ''' Examples: gupdate gub/specs/git.py gupdate $(gub --show-dependencies lilypond 2>/dev/null | sed -e 's/(gcc|glibc)//g') ''' misc.optparse_epilog (p, examples) (options, files) = p.parse_args () if not files: p.print_help () return (options, files) def string_get_url (string): m = re.search ('''source = ['"](http://[^'"]+[.]tar.(?:gz|bz2))([?&][^'"]+)?['"]''', string) if m: return m.group (1) return '' def url_get_latest (url): name, version_tuple, format = misc.split_ball (url) url_dir = url[:url.rfind ('/')+1] if 'lilypond-' in url: #sys.stderr.write ('lilypond-url: %(url)s\n' % locals ()) from gub.specs import lilypond return lilypond.url () elif '/GNOME/platform/' in url: #sys.stderr.write ('gnome-platform-url: %(url)s\n' % locals ()) from gub import gnome latest = gnome.platform_url (name) if latest: return latest return misc.latest_url (url_dir, name) def do_spec (file_name, options): s = open (file_name).read () url = string_get_url (s) if not url: printf ('%(file_name)s: cannot find ball' % locals ()) return latest = url_get_latest (url) if not latest: sys.stderr.write ('cannot find upstream for: %(url)s\n' % locals ()) elif latest != url: if options.replace: printf ('%(file_name)s: updating to: %(latest)s' % locals ()) inert_url = url.replace ('+', '[+]') misc.file_sub ([(inert_url, latest)], file_name, must_succeed=True) else: printf ('%(file_name)s: new ball: %(latest)s' % locals ()) def arg_to_file (arg): if os.path.isfile (arg): return arg name = arg if '::' in arg: name = misc.strip_platform (arg) if os.path.isfile (name): return name file_name = os.path.join ('gub/specs', name) if not file_name.endswith ('.py'): file_name += '.py' if os.path.isfile (file_name): return file_name sys.stderr.write ('cannot find file for: %(arg)s: skipping\n' % locals ()) return None def main (): (options, args) = parse_command_line () files = [x for x in map (arg_to_file, args) if x] for f in files: do_spec (f, options) if __name__ == '__main__': main ()