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
.download_base_url
= args
[0]
18 doc
= minidom
.parse(file(ENV_FILE
))
19 doc
.documentElement
.setAttributeNS(XMLNS_0COMPILE
, 'compile:download-base-url', args
[0])
20 doc
.writexml(file(ENV_FILE
, 'w'))
22 info("Using download base URL: %s", buildenv
.download_base_url
)
24 if not os
.path
.isdir(buildenv
.distdir
):
25 raise SafeException("Directory '%s' does not exist. Try 'compile build'." % buildenv
.distdir
)
27 distdir
= os
.path
.basename(buildenv
.distdir
)
28 archive_name
= distdir
+ '.tar.bz2'
31 for command
in ['gtar', 'tar', 'gnutar', 'star']:
32 if find_in_path(command
):
33 stream
= os
.popen("'%s' --version 2>&1" % command
)
35 version
= stream
.read()
36 if 'GNU tar' in version
or \
43 raise SafeException("GNU tar not found in $PATH")
45 # Make all directories in the archive user writable
46 for main
, dirs
, files
in os
.walk(distdir
):
47 os
.chmod(main
, os
.stat(main
).st_mode |
0200)
49 spawn_and_check(find_in_path(gnutar
), ['cjf', archive_name
, distdir
])
51 download_url
= os
.path
.join(buildenv
.download_base_url
, archive_name
)
52 shutil
.copyfile(buildenv
.local_iface_file
, buildenv
.local_download_iface
)
54 spawn_and_check(find_in_path('0launch'),
55 ['http://0install.net/2006/interfaces/0publish', buildenv
.local_download_iface
,
56 '--archive-url', download_url
,
57 '--archive-extract', distdir
])
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" % buildenv
.local_download_iface
64 __main__
.commands
.append(do_publish
)