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
10 def ensure_download_base(buildenv
, args
):
12 if not buildenv
.download_base_url
:
13 raise SafeException("No download base set. Give the URL for a remote directory.")
15 buildenv
.config
.set('compile', 'download-base-url', args
[0])
18 raise __main__
.UsageError()
20 def do_autopublish(args
):
21 """autopublish [ DOWNLOAD-BASE-URL ]"""
26 ensure_download_base(buildenv
, args
)
34 """publish [ DOWNLOAD-BASE-URL ]"""
36 ensure_download_base(buildenv
, args
)
38 info("Using download base URL: %s", buildenv
.download_base_url
)
40 if not os
.path
.isdir(buildenv
.distdir
):
41 raise SafeException("Directory '%s' does not exist. Try 'compile build'." % buildenv
.distdir
)
43 distdir
= os
.path
.basename(buildenv
.distdir
)
44 archive_name
= buildenv
.archive_stem
+ '.tar.bz2'
46 # Make all directories in the archive user writable
47 for main
, dirs
, files
in os
.walk(distdir
):
48 os
.chmod(main
, os
.stat(main
).st_mode |
0200)
51 archive
= tarfile
.open(archive_name
, mode
= 'w:bz2')
52 archive
.add(distdir
, buildenv
.archive_stem
)
55 download_url
= os
.path
.join(buildenv
.download_base_url
, archive_name
)
56 shutil
.copyfile(buildenv
.local_iface_file
, buildenv
.local_download_iface
)
58 spawn_and_check(find_in_path('0launch'),
59 ['http://0install.net/2006/interfaces/0publish', buildenv
.local_download_iface
,
60 '--archive-url', download_url
,
61 '--archive-extract', buildenv
.archive_stem
])
63 print "Now upload '%s' as:\n%s\n" % (archive_name
, download_url
)
65 print "Once uploaded, you can download and run with:"
66 print "$ 0launch %s" % buildenv
.local_download_iface
68 __main__
.commands
+= [do_autopublish
, do_publish
]