1 # Copyright (C) 2009, Thomas Leonard
2 # See the README file for details, or visit http://0install.net.
7 from logging
import info
9 from zeroinstall
.injector
import reader
, iface_cache
, model
10 from zeroinstall
.injector
.policy
import Policy
12 XMLNS_0COMPILE
= 'http://zero-install.sourceforge.net/2006/namespaces/0compile'
19 def run(self
, command
, success
):
20 assert self
.child
is None
21 self
.success
= success
22 self
.child
= subprocess
.Popen(command
,
23 stdout
= subprocess
.PIPE
,
24 stderr
= subprocess
.STDOUT
)
25 gobject
.io_add_watch(self
.child
.stdout
, gobject
.IO_IN | gobject
.IO_HUP
, self
.got_data
)
27 def got_data(self
, src
, cond
):
28 data
= os
.read(src
.fileno(), 100)
33 status
= self
.child
.wait()
36 if os
.WIFEXITED(status
) and os
.WEXITSTATUS(status
) == 0:
39 if os
.WIFEXITED(status
):
40 status
= os
.WEXITSTATUS(status
)
41 if status
== 1 and not self
.error
:
42 return False # Cancelled
43 dialog
.alert(None, _("Command failed with exit code %(status)d:\n%(error)s\n") %
44 {'status': status
, 'error': self
.error
})
46 dialog
.alert(None, _("Command failed:\n%s\n") % self
.error
)
49 def compile(policy
, interface
, autocompile
= False):
50 our_min_version
= '0.18' # The oldest version of 0compile we support
53 # A new local feed may have been registered, so update the interface from the cache
54 info(_("0compile command completed successfully. Reloading interface details."))
55 reader
.update_from_cache(interface
)
59 # Get the chosen versions
60 src_policy
= Policy(interface
.uri
, src
= True)
61 src_policy
.freshness
= 0
63 src_policy
.recalculate()
64 if not src_policy
.ready
:
65 raise Exception(_('Internal error: required source components not found!'))
67 root_iface
= iface_cache
.iface_cache
.get_interface(src_policy
.root
)
68 impl
= src_policy
.implementation
[root_iface
]
70 min_version
= impl
.metadata
.get(XMLNS_0COMPILE
+ ' min-version', our_min_version
)
71 # Check the syntax is valid and the version is high enough
72 if model
.parse_version(min_version
) < model
.parse_version(our_min_version
):
73 min_version
= our_min_version
75 # Do the whole build-and-register-feed
78 '--message', _('Download the 0compile tool, to compile the source code'),
79 '--not-before=' + min_version
,
80 "http://0install.net/2006/interfaces/0compile.xml",
83 interface
.uri
), add_feed
)
88 '--message', 'Download the 0compile tool, to compile the source code',
89 '--not-before=' + our_min_version
,
90 "http://0install.net/2006/interfaces/0compile.xml",
93 interface
.uri
), add_feed
)
95 # Prompt user to choose source version
98 '--message', _('Download the source code to be compiled'),
99 '--gui', '--source', '--download-only', interface
.uri
], build
)