1 # Copyright (C) 2006, Thomas Leonard
2 # See http://0install.net/0compile.html
4 import os
, sys
, __main__
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 buildenv
.config
.set('compile', 'download-base-url', args2
[0])
31 download_base_url
= buildenv
.download_base_url
or None
34 info("Using download base URL: %s", download_base_url
)
36 if not os
.path
.isdir(buildenv
.distdir
):
37 raise SafeException("Directory '%s' does not exist. Try 'compile build'." % buildenv
.distdir
)
39 distdir
= os
.path
.basename(buildenv
.distdir
)
40 archive_name
= buildenv
.archive_stem
+ '.tar.bz2'
42 # Make all directories in the archive user writable
43 for main
, dirs
, files
in os
.walk(distdir
):
44 os
.chmod(main
, os
.stat(main
).st_mode |
0200)
47 archive
= tarfile
.open(archive_name
, mode
= 'w:bz2')
48 archive
.add(distdir
, buildenv
.archive_stem
)
51 target_feed
= options
.target_feed
or buildenv
.local_download_iface
54 download_url
= os
.path
.join(download_base_url
, archive_name
)
56 download_url
= archive_name
57 shutil
.copyfile(buildenv
.local_iface_file
, target_feed
)
59 # XXX: we're assuming that 0publish requires the same version of Python as
60 # 0compile. This is currently needed for Arch Linux, but long-term we need to
62 spawn_and_check(sys
.executable
, [
65 '--archive-url', download_url
,
66 '--archive-extract', buildenv
.archive_stem
])
68 if options
.target_feed
is None:
69 # If --target-feed is used this is probably a script, so don't print
71 print "Now upload '%s' as:\n%s\n" % (archive_name
, download_url
)
73 print "Once uploaded, you can download and run with:"
74 print "$ 0launch %s" % target_feed
76 __main__
.commands
.append(do_publish
)