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
11 """publish [ DOWNLOAD-BASE-URL ]"""
14 if not buildenv
.download_base_url
:
15 raise SafeException("No download base set. Give the URL for a remote directory.")
17 buildenv
.config
.set('compile', 'download-base-url', args
[0])
20 info("Using download base URL: %s", buildenv
.download_base_url
)
22 if not os
.path
.isdir(buildenv
.distdir
):
23 raise SafeException("Directory '%s' does not exist. Try 'compile build'." % buildenv
.distdir
)
25 distdir
= os
.path
.basename(buildenv
.distdir
)
26 archive_name
= buildenv
.archive_stem
+ '.tar.bz2'
28 # Make all directories in the archive user writable
29 for main
, dirs
, files
in os
.walk(distdir
):
30 os
.chmod(main
, os
.stat(main
).st_mode |
0200)
33 archive
= tarfile
.open(archive_name
, mode
= 'w:bz2')
34 archive
.add(distdir
, buildenv
.archive_stem
)
37 download_url
= os
.path
.join(buildenv
.download_base_url
, archive_name
)
38 shutil
.copyfile(buildenv
.local_iface_file
, buildenv
.local_download_iface
)
40 spawn_and_check(find_in_path('0launch'),
41 ['http://0install.net/2006/interfaces/0publish', buildenv
.local_download_iface
,
42 '--archive-url', download_url
,
43 '--archive-extract', buildenv
.archive_stem
])
45 print "Now upload '%s' as:\n%s\n" % (archive_name
, download_url
)
47 print "Once uploaded, you can download and run with:"
48 print "$ 0launch %s" % buildenv
.local_download_iface
50 __main__
.commands
.append(do_publish
)