Updated unit-tests for latest 0repo
[0release.git] / 0release
blob91d5af964d10bbf13c9602e20459294335c5bab5
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 # NOT the first element... that's us!
11 # (and we want our setup.py, not 0install's)
12 sys.path.insert(1, zi)
13 from zeroinstall import SafeException
14 from zeroinstall.injector import qdom
16 version = '0.15'
18 parser = OptionParser(usage = """usage: %prog [options] LOCAL-FEED
20 Run this command from a new empty directory to set things up.""")
22 parser.add_option("", "--builders", help="comma-separated list of builders for binaries", metavar='LIST')
23 parser.add_option("", "--build-slave", help="compile a binary a source release candidate", action='store_true')
24 parser.add_option("-k", "--key", help="GPG key to use for signing", action='store', metavar='KEYID')
25 parser.add_option("-v", "--verbose", help="more verbose output", action='count')
26 parser.add_option("-r", "--release", help="make a new release", action='store_true')
27 parser.add_option("", "--archive-dir-public-url", help="remote directory for releases", metavar='URL')
28 parser.add_option("", "--master-feed-file", help="local file to extend with new releases", metavar='PATH')
29 parser.add_option("", "--archive-upload-command", help="shell command to upload releases", metavar='COMMAND')
30 parser.add_option("", "--master-feed-upload-command", help="shell command to upload feed", metavar='COMMAND')
31 parser.add_option("", "--public-scm-repository", help="the name of the repository to push to", metavar='REPOS')
32 parser.add_option("", "--release-version", help="explicitly set the version of this release", metavar='VERSION')
33 parser.add_option("-V", "--version", help="display version information", action='store_true')
35 (options, args) = parser.parse_args()
37 if options.version:
38 print "0release (zero-install) " + version
39 print "Copyright (C) 2009 Thomas Leonard"
40 print "This program comes with ABSOLUTELY NO WARRANTY,"
41 print "to the extent permitted by law."
42 print "You may redistribute copies of this program"
43 print "under the terms of the GNU General Public License."
44 print "For more information about these matters, see the file named COPYING."
45 sys.exit(0)
47 if options.verbose:
48 import logging
49 logger = logging.getLogger()
50 if options.verbose == 1:
51 logger.setLevel(logging.INFO)
52 else:
53 logger.setLevel(logging.DEBUG)
55 if options.build_slave:
56 if len(args) != 4:
57 parser.print_help()
58 sys.exit(1)
59 src_feed, archive_file, archive_dir_public_url, target_feed = args
60 import compile
61 compile.build_slave(src_feed, archive_file, archive_dir_public_url, target_feed)
62 sys.exit(0)
64 if len(args) != 1:
65 parser.print_help()
66 sys.exit(1)
68 local_feed_path = os.path.abspath(args[0])
70 try:
71 if not os.path.exists(local_feed_path):
72 raise SafeException("Local feed file '%s' does not exist" % local_feed_path)
74 with open(local_feed_path, 'rb') as stream:
75 root = qdom.parse(stream)
77 import support
78 feed = support.load_feed(local_feed_path)
80 if options.release:
81 import release
82 release.do_release(feed, options)
83 else:
84 import setup
85 setup.init_releases_directory(feed)
86 except KeyboardInterrupt, ex:
87 print >>sys.stderr, "Interrupted"
88 sys.exit(1)
89 except OSError, ex:
90 if options.verbose: raise
91 print >>sys.stderr, str(ex)
92 sys.exit(1)
93 except IOError, ex:
94 if options.verbose: raise
95 print >>sys.stderr, str(ex)
96 sys.exit(1)
97 except SafeException, ex:
98 if options.verbose: raise
99 print >>sys.stderr, str(ex)
100 sys.exit(1)