1 # Copyright (C) 2006, Thomas Leonard
2 # See http://0install.net/0compile.html
5 from logging
import info
6 from optparse
import OptionParser
9 from zeroinstall
import SafeException
11 from support
import BuildEnv
, spawn_and_check
13 pubish_command
= os
.environ
["0COMPILE_0PUBLISH"]
16 """publish [ DOWNLOAD-BASE-URL ]"""
18 parser
= OptionParser(usage
="usage: %prog publish [options] [ DOWNLOAD-BASE-URL ]")
20 parser
.add_option('', "--target-feed", help="name of output feed file to create", metavar
='FILE')
21 (options
, args2
) = parser
.parse_args(args
)
25 if not buildenv
.download_base_url
:
26 raise SafeException("No download base set. Give the URL for a remote directory.")
28 buildenv
.config
.set('compile', 'download-base-url', args2
[0])
31 info("Using download base URL: %s", buildenv
.download_base_url
)
33 if not os
.path
.isdir(buildenv
.distdir
):
34 raise SafeException("Directory '%s' does not exist. Try 'compile build'." % buildenv
.distdir
)
36 distdir
= os
.path
.basename(buildenv
.distdir
)
37 archive_name
= buildenv
.archive_stem
+ '.tar.bz2'
39 # Make all directories in the archive user writable
40 for main
, dirs
, files
in os
.walk(distdir
):
41 os
.chmod(main
, os
.stat(main
).st_mode |
0200)
44 archive
= tarfile
.open(archive_name
, mode
= 'w:bz2')
45 archive
.add(distdir
, buildenv
.archive_stem
)
48 target_feed
= options
.target_feed
or buildenv
.local_download_iface
50 download_url
= os
.path
.join(buildenv
.download_base_url
, archive_name
)
51 shutil
.copyfile(buildenv
.local_iface_file
, target_feed
)
53 spawn_and_check(pubish_command
,
55 '--archive-url', download_url
,
56 '--archive-extract', buildenv
.archive_stem
])
58 if options
.target_feed
is None:
59 # If --target-feed is used this is probably a script, so don't print
61 print "Now upload '%s' as:\n%s\n" % (archive_name
, download_url
)
63 print "Once uploaded, you can download and run with:"
64 print "$ 0launch %s" % target_feed
66 __main__
.commands
.append(do_publish
)