Cope with using a distribution version of 0install
[0release.git] / 0release
blob5ada74a602c72163f3a62dee907aa245181deb93
1 #!/usr/bin/env python
2 # Copyright (C) 2009, Thomas Leonard
3 # See the README file for details, or visit http://0install.net.
5 from optparse import OptionParser
6 import os, sys
8 zi = os.environ.get("0RELEASE_ZEROINSTALL", None)
9 if zi is not None:
10 sys.path.insert(0, zi)
11 from zeroinstall import SafeException
12 from zeroinstall.injector import reader, model
14 version = '0.12'
16 parser = OptionParser(usage = """usage: %prog [options] LOCAL-FEED
18 Run this command from a new empty directory to set things up.""")
20 parser.add_option("", "--builders", help="comma-separated list of builders for binaries", metavar='LIST')
21 parser.add_option("", "--build-slave", help="compile a binary a source release candidate", action='store_true')
22 parser.add_option("-k", "--key", help="GPG key to use for signing", action='store', metavar='KEYID')
23 parser.add_option("-v", "--verbose", help="more verbose output", action='count')
24 parser.add_option("-r", "--release", help="make a new release", action='store_true')
25 parser.add_option("", "--archive-dir-public-url", help="remote directory for releases", metavar='URL')
26 parser.add_option("", "--master-feed-file", help="local file to extend with new releases", metavar='PATH')
27 parser.add_option("", "--archive-upload-command", help="shell command to upload releases", metavar='COMMAND')
28 parser.add_option("", "--master-feed-upload-command", help="shell command to upload feed", metavar='COMMAND')
29 parser.add_option("", "--public-scm-repository", help="the name of the repository to push to", metavar='REPOS')
30 parser.add_option("-V", "--version", help="display version information", action='store_true')
32 (options, args) = parser.parse_args()
34 if options.version:
35 print "0release (zero-install) " + version
36 print "Copyright (C) 2009 Thomas Leonard"
37 print "This program comes with ABSOLUTELY NO WARRANTY,"
38 print "to the extent permitted by law."
39 print "You may redistribute copies of this program"
40 print "under the terms of the GNU General Public License."
41 print "For more information about these matters, see the file named COPYING."
42 sys.exit(0)
44 if options.verbose:
45 import logging
46 logger = logging.getLogger()
47 if options.verbose == 1:
48 logger.setLevel(logging.INFO)
49 else:
50 logger.setLevel(logging.DEBUG)
52 if options.build_slave:
53 if len(args) != 4:
54 parser.print_help()
55 sys.exit(1)
56 src_feed, archive_file, archive_dir_public_url, target_feed = args
57 import compile
58 compile.build_slave(src_feed, archive_file, archive_dir_public_url, target_feed)
59 sys.exit(0)
61 if len(args) != 1:
62 parser.print_help()
63 sys.exit(1)
65 local_feed_path = args[0]
67 try:
68 if not os.path.exists(local_feed_path):
69 raise SafeException("Local feed file '%s' does not exist" % local_feed_path)
71 iface = model.Interface(model.canonical_iface_uri(local_feed_path))
72 reader.update(iface, local_feed_path, local = True)
74 if options.release:
75 import release
76 release.do_release(iface, options)
77 else:
78 import setup
79 setup.init_releases_directory(iface)
80 except KeyboardInterrupt, ex:
81 print >>sys.stderr, "Interrupted"
82 sys.exit(1)
83 except OSError, ex:
84 if options.verbose: raise
85 print >>sys.stderr, str(ex)
86 sys.exit(1)
87 except IOError, ex:
88 if options.verbose: raise
89 print >>sys.stderr, str(ex)
90 sys.exit(1)
91 except SafeException, ex:
92 if options.verbose: raise
93 print >>sys.stderr, str(ex)
94 sys.exit(1)