4 from logging
import info
6 from zeroinstall
.injector
import reader
, iface_cache
, model
7 from zeroinstall
.injector
.policy
import Policy
9 XMLNS_0COMPILE
= 'http://zero-install.sourceforge.net/2006/namespaces/0compile'
16 def run(self
, command
, success
):
17 assert self
.child
is None
18 self
.success
= success
19 self
.child
= popen2
.Popen4(command
)
20 self
.child
.tochild
.close()
21 gobject
.io_add_watch(self
.child
.fromchild
, gobject
.IO_IN | gobject
.IO_HUP
, self
.got_data
)
23 def got_data(self
, src
, cond
):
24 data
= os
.read(src
.fileno(), 100)
29 status
= self
.child
.wait()
32 if os
.WIFEXITED(status
) and os
.WEXITSTATUS(status
) == 0:
35 if os
.WIFEXITED(status
):
36 status
= os
.WEXITSTATUS(status
)
37 if status
== 1 and not self
.error
:
38 return False # Cancelled
39 dialog
.alert(None, "Command failed with exit code %d:\n%s\n" %
42 dialog
.alert(None, "Command failed:\n%s\n" % self
.error
)
45 def compile(policy
, interface
):
47 # A new local feed may have been registered, so update the interface from the cache
48 info("0compile command completed successfully. Reloading interface details.")
49 reader
.update_from_cache(interface
)
53 # Get the chosen versions
54 src_policy
= Policy(interface
.uri
, src
= True)
55 src_policy
.freshness
= 0
57 src_policy
.recalculate()
58 if not src_policy
.ready
:
59 raise Exception('Internal error: required source components not found!')
61 root_iface
= iface_cache
.iface_cache
.get_interface(src_policy
.root
)
62 impl
= src_policy
.implementation
[root_iface
]
63 min_version
= impl
.metadata
.get(XMLNS_0COMPILE
+ ' min-version', None)
64 if not min_version
: min_version
= '0.4'
65 # Check the syntax is valid and the version is high enough
66 if model
.parse_version(min_version
) < model
.parse_version('0.4'):
69 # Do the whole build-and-register-feed
72 '--not-before=' + min_version
,
73 "http://0install.net/2006/interfaces/0compile.xml",
76 interface
.uri
), add_feed
)
78 # Prompt user to choose source version
80 c
.run(['0launch', '--gui', '--source', '--download-only', interface
.uri
], build
)