-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpublish.py
80 lines (61 loc) · 2.48 KB
/
publish.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Copyright (C) 2006, Thomas Leonard
# See http://0install.net/0compile.html
import os, sys, __main__
from logging import info
from optparse import OptionParser
import shutil
from zeroinstall import SafeException
from support import BuildEnv, spawn_and_check
pubish_command = os.environ["ZI_COMPILE_0PUBLISH"]
def do_publish(args):
"""publish [ DOWNLOAD-BASE-URL ]"""
parser = OptionParser(usage="usage: %prog publish [options] [ DOWNLOAD-BASE-URL ]")
parser.add_option('', "--target-feed", help="name of output feed file to create", metavar='FILE')
(options, args2) = parser.parse_args(args)
buildenv = BuildEnv()
if len(args2) == 1:
buildenv.config.set('compile', 'download-base-url', args2[0])
buildenv.save()
elif len(args2) > 1:
parser.print_help()
sys.exit(1)
download_base_url = buildenv.download_base_url or None
if download_base_url:
info("Using download base URL: %s", download_base_url)
if not os.path.isdir(buildenv.distdir):
raise SafeException("Directory '%s' does not exist. Try 'compile build'." % buildenv.distdir)
distdir = os.path.basename(buildenv.distdir)
archive_name = buildenv.archive_stem + '.tar.bz2'
# Make all directories in the archive user writable
for main, dirs, files in os.walk(distdir):
os.chmod(main, os.stat(main).st_mode | 0o200)
import tarfile
archive = tarfile.open(archive_name, mode = 'w:bz2')
archive.add(distdir, buildenv.archive_stem)
archive.close()
target_feed = options.target_feed or buildenv.local_download_iface
if download_base_url:
download_url = os.path.join(download_base_url, archive_name)
else:
download_url = archive_name
shutil.copyfile(buildenv.local_iface_file, target_feed)
# XXX: we're assuming that 0publish requires the same version of Python as
# 0compile. This is currently needed for Arch Linux, but long-term we need to
# use the <runner>.
spawn_and_check(sys.executable, [
pubish_command,
target_feed,
'--archive-url', download_url,
'--archive-extract', buildenv.archive_stem])
if options.target_feed is None:
# If --target-feed is used this is probably a script, so don't print
# out hints.
if download_base_url:
print("Now upload '%s' as:\n%s\n" % (archive_name, download_url))
print("Once uploaded, you can download and run with:")
print("0launch %s" % target_feed)
else:
print("Generated archive '%s' and feed '%s'." % (archive_name, target_feed))
print("Upload it to a repository with:")
print("0repo add %s" % target_feed)
__main__.commands.append(do_publish)