Start development series 0.19-post
[0compile.git] / publish.py
blobeee852b069566e06355c759cd03a43dc2f0d1763
1 # Copyright (C) 2006, Thomas Leonard
2 # See http://0install.net/0compile.html
4 import sys, os, __main__
5 from logging import info
6 from xml.dom import minidom
7 from optparse import OptionParser
9 from support import *
11 pubish_command = os.environ["0COMPILE_0PUBLISH"]
13 def do_publish(args):
14 """publish [ DOWNLOAD-BASE-URL ]"""
16 parser = OptionParser(usage="usage: %prog publish [options] [ DOWNLOAD-BASE-URL ]")
18 parser.add_option('', "--target-feed", help="name of output feed file to create", metavar='FILE')
19 (options, args2) = parser.parse_args(args)
21 buildenv = BuildEnv()
22 if len(args2) == 0:
23 if not buildenv.download_base_url:
24 raise SafeException("No download base set. Give the URL for a remote directory.")
25 elif len(args2) == 1:
26 buildenv.config.set('compile', 'download-base-url', args2[0])
27 buildenv.save()
29 info("Using download base URL: %s", buildenv.download_base_url)
31 if not os.path.isdir(buildenv.distdir):
32 raise SafeException("Directory '%s' does not exist. Try 'compile build'." % buildenv.distdir)
34 distdir = os.path.basename(buildenv.distdir)
35 archive_name = buildenv.archive_stem + '.tar.bz2'
37 # Make all directories in the archive user writable
38 for main, dirs, files in os.walk(distdir):
39 os.chmod(main, os.stat(main).st_mode | 0200)
41 import tarfile
42 archive = tarfile.open(archive_name, mode = 'w:bz2')
43 archive.add(distdir, buildenv.archive_stem)
44 archive.close()
46 target_feed = options.target_feed or buildenv.local_download_iface
48 download_url = os.path.join(buildenv.download_base_url, archive_name)
49 shutil.copyfile(buildenv.local_iface_file, target_feed)
51 spawn_and_check(pubish_command,
52 [target_feed,
53 '--archive-url', download_url,
54 '--archive-extract', buildenv.archive_stem])
56 if options.target_feed is None:
57 # If --target-feed is used this is probably a script, so don't print
58 # out hints.
59 print "Now upload '%s' as:\n%s\n" % (archive_name, download_url)
61 print "Once uploaded, you can download and run with:"
62 print "$ 0launch %s" % target_feed
64 __main__.commands.append(do_publish)