Force unit-tests to test with the same version of 0release
[0release.git] / 0release
blobe45e079b42e4cbe41bf6985589cf5db9c7a8ea8d
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 reader, model, qdom
16 version = '0.13'
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("-V", "--version", help="display version information", action='store_true')
34 (options, args) = parser.parse_args()
36 if options.version:
37 print "0release (zero-install) " + version
38 print "Copyright (C) 2009 Thomas Leonard"
39 print "This program comes with ABSOLUTELY NO WARRANTY,"
40 print "to the extent permitted by law."
41 print "You may redistribute copies of this program"
42 print "under the terms of the GNU General Public License."
43 print "For more information about these matters, see the file named COPYING."
44 sys.exit(0)
46 if options.verbose:
47 import logging
48 logger = logging.getLogger()
49 if options.verbose == 1:
50 logger.setLevel(logging.INFO)
51 else:
52 logger.setLevel(logging.DEBUG)
54 if options.build_slave:
55 if len(args) != 4:
56 parser.print_help()
57 sys.exit(1)
58 src_feed, archive_file, archive_dir_public_url, target_feed = args
59 import compile
60 compile.build_slave(src_feed, archive_file, archive_dir_public_url, target_feed)
61 sys.exit(0)
63 if len(args) != 1:
64 parser.print_help()
65 sys.exit(1)
67 local_feed_path = os.path.abspath(args[0])
69 try:
70 if not os.path.exists(local_feed_path):
71 raise SafeException("Local feed file '%s' does not exist" % local_feed_path)
73 with open(local_feed_path, 'rb') as stream:
74 root = qdom.parse(stream)
76 feed = model.ZeroInstallFeed(root, local_path = local_feed_path)
78 if options.release:
79 import release
80 release.do_release(feed, options)
81 else:
82 import setup
83 setup.init_releases_directory(feed)
84 except KeyboardInterrupt, ex:
85 print >>sys.stderr, "Interrupted"
86 sys.exit(1)
87 except OSError, ex:
88 if options.verbose: raise
89 print >>sys.stderr, str(ex)
90 sys.exit(1)
91 except IOError, ex:
92 if options.verbose: raise
93 print >>sys.stderr, str(ex)
94 sys.exit(1)
95 except SafeException, ex:
96 if options.verbose: raise
97 print >>sys.stderr, str(ex)
98 sys.exit(1)