1 # Copyright (C) 2009, Thomas Leonard
2 # See the README file for details, or visit http://0install.net.
7 from StringIO
import StringIO
9 from zeroinstall
.injector
import model
, selections
, qdom
11 XMLNS_0COMPILE
= 'http://zero-install.sourceforge.net/2006/namespaces/0compile'
18 self
.watched_streams
= 0
20 def run(self
, command
, success
, get_stdout
= False):
21 assert self
.child
is None
22 self
.success
= success
24 self
.child
= subprocess
.Popen(command
,
25 stdout
= subprocess
.PIPE
,
26 stderr
= subprocess
.PIPE
)
27 gobject
.io_add_watch(self
.child
.stdout
, gobject
.IO_IN | gobject
.IO_HUP
, self
.got_stdout
)
28 gobject
.io_add_watch(self
.child
.stderr
, gobject
.IO_IN | gobject
.IO_HUP
, self
.got_errors
)
29 self
.watched_streams
= 2
31 self
.child
= subprocess
.Popen(command
,
32 stdout
= subprocess
.PIPE
,
33 stderr
= subprocess
.STDOUT
)
34 gobject
.io_add_watch(self
.child
.stdout
, gobject
.IO_IN | gobject
.IO_HUP
, self
.got_errors
)
35 self
.watched_streams
= 1
37 def got_stdout(self
, src
, cond
):
38 data
= os
.read(src
.fileno(), 100)
47 self
.watched_streams
-= 1
48 if self
.watched_streams
== 0:
49 status
= self
.child
.wait()
53 self
.success(self
.stdout
)
55 if status
== 1 and not self
.error
:
56 return False # Cancelled
57 dialog
.alert(None, _("Command failed with exit code %(status)d:\n%(error)s\n") %
58 {'status': status
, 'error': self
.error
})
60 def got_errors(self
, src
, cond
):
61 data
= os
.read(src
.fileno(), 100)
69 def compile(on_success
, interface_uri
, autocompile
= False):
70 our_min_version
= '0.18' # The oldest version of 0compile we support
72 def build(selections_xml
):
73 # Get the chosen versions
74 sels
= selections
.Selections(qdom
.parse(StringIO(selections_xml
)))
76 impl
= sels
.selections
[interface_uri
]
78 min_version
= impl
.attrs
.get(XMLNS_0COMPILE
+ ' min-version', our_min_version
)
79 # Check the syntax is valid and the version is high enough
80 if model
.parse_version(min_version
) < model
.parse_version(our_min_version
):
81 min_version
= our_min_version
83 # Do the whole build-and-register-feed
86 '--message', _('Download the 0compile tool, to compile the source code'),
87 '--not-before=' + min_version
,
88 "http://0install.net/2006/interfaces/0compile.xml",
90 interface_uri
), lambda unused
: on_success())
95 '--message', 'Download the 0compile tool, to compile the source code',
96 '--not-before=' + our_min_version
,
97 "http://0install.net/2006/interfaces/0compile.xml",
100 interface_uri
), lambda unused
: on_success())
102 # Prompt user to choose source version
104 c
.run(['0install', 'download', '--xml',
105 '--message', _('Download the source code to be compiled'),
106 '--gui', '--source', '--', interface_uri
], build
, get_stdout
= True)