Fixed usage message for --shell.
[0compile.git] / publish.py
blob5a446dcf1e5f3d023c5a63528d2b8f6662755956
1 # Copyright (C) 2006, Thomas Leonard
2 # See http://0install.net/0compile.html
4 import sys, os, __main__
5 from logging import info
7 from support import *
9 def do_publish(args):
10 """publish [ DOWNLOAD-BASE-URL ]"""
11 buildenv = BuildEnv()
12 if len(args) == 0:
13 if not buildenv.download_base_url:
14 raise SafeException("No download base set. Give the URL for a remote directory.")
15 elif len(args) == 1:
16 buildenv.download_base_url = args[0]
17 buildenv.doc.documentElement.setAttributeNS(None, 'download-base-url', args[0])
18 buildenv.doc.writexml(file(ENV_FILE, 'w'))
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 = distdir + '.tar.bz2'
28 gnutar = None
29 for command in ['gtar', 'tar', 'gnutar', 'star']:
30 if find_in_path(command):
31 stream = os.popen("'%s' --version 2>&1" % command)
32 try:
33 version = stream.read()
34 if 'GNU tar' in version or \
35 'star' in version:
36 gnutar = command
37 break
38 finally:
39 stream.close()
40 if not gnutar:
41 raise SafeException("GNU tar not found in $PATH")
43 # Make all directories in the archive user writable
44 for main, dirs, files in os.walk(distdir):
45 os.chmod(main, os.stat(main).st_mode | 0200)
47 spawn_and_check(find_in_path(gnutar), ['cjf', archive_name, distdir])
49 download_url = os.path.join(buildenv.download_base_url, archive_name)
50 shutil.copyfile(buildenv.local_iface_file, buildenv.local_download_iface)
52 spawn_and_check(find_in_path('0launch'),
53 ['http://0install.net/2006/interfaces/0publish', buildenv.local_download_iface,
54 '--archive-url', download_url,
55 '--archive-extract', distdir])
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" % buildenv.local_download_iface
62 __main__.commands.append(do_publish)