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
12 """publish [ DOWNLOAD-BASE-URL ]"""
14 parser
= OptionParser(usage
="usage: %prog publish [options] [ DOWNLOAD-BASE-URL ]")
16 parser
.add_option('', "--target-feed", help="name of output feed file to create", metavar
='FILE')
17 (options
, args2
) = parser
.parse_args(args
)
21 if not buildenv
.download_base_url
:
22 raise SafeException("No download base set. Give the URL for a remote directory.")
24 buildenv
.config
.set('compile', 'download-base-url', args2
[0])
27 info("Using download base URL: %s", buildenv
.download_base_url
)
29 if not os
.path
.isdir(buildenv
.distdir
):
30 raise SafeException("Directory '%s' does not exist. Try 'compile build'." % buildenv
.distdir
)
32 distdir
= os
.path
.basename(buildenv
.distdir
)
33 archive_name
= buildenv
.archive_stem
+ '.tar.bz2'
35 # Make all directories in the archive user writable
36 for main
, dirs
, files
in os
.walk(distdir
):
37 os
.chmod(main
, os
.stat(main
).st_mode |
0200)
40 archive
= tarfile
.open(archive_name
, mode
= 'w:bz2')
41 archive
.add(distdir
, buildenv
.archive_stem
)
44 target_feed
= options
.target_feed
or buildenv
.local_download_iface
46 download_url
= os
.path
.join(buildenv
.download_base_url
, archive_name
)
47 shutil
.copyfile(buildenv
.local_iface_file
, target_feed
)
49 spawn_and_check(find_in_path('0launch'),
50 ['http://0install.net/2006/interfaces/0publish', target_feed
,
51 '--archive-url', download_url
,
52 '--archive-extract', buildenv
.archive_stem
])
54 if options
.target_feed
is None:
55 # If --target-feed is used this is probably a script, so don't print
57 print "Now upload '%s' as:\n%s\n" % (archive_name
, download_url
)
59 print "Once uploaded, you can download and run with:"
60 print "$ 0launch %s" % target_feed
62 __main__
.commands
.append(do_publish
)