Fixed support for bundled dependenecies
[0compile.git] / publish.py
bloba1c2ecd47cb9b4ca7dc866a886bcc42723da2ae5
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
8 from support import *
10 def ensure_download_base(buildenv, args):
11 if len(args) == 0:
12 if not buildenv.download_base_url:
13 raise SafeException("No download base set. Give the URL for a remote directory.")
14 elif len(args) == 1:
15 buildenv.config.set('compile', 'download-base-url', args[0])
16 buildenv.save()
17 else:
18 raise __main__.UsageError()
20 def do_autopublish(args):
21 """autopublish [ DOWNLOAD-BASE-URL ]"""
22 import clean
23 import build
25 buildenv = BuildEnv()
26 ensure_download_base(buildenv, args)
28 clean.do_clean([])
29 build.do_build([])
30 do_publish([])
31 clean.do_clean([])
33 def do_publish(args):
34 """publish [ DOWNLOAD-BASE-URL ]"""
35 buildenv = BuildEnv()
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)
50 import tarfile
51 archive = tarfile.open(archive_name, mode = 'w:bz2')
52 archive.add(distdir, buildenv.archive_stem)
53 archive.close()
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]