1 # Copyright (C) 2008, 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
= popen2
.Popen4(command
)
23 self
.child
.tochild
.close()
24 gobject
.io_add_watch(self
.child
.fromchild
, gobject
.IO_IN | gobject
.IO_HUP
, self
.got_data
)
26 def got_data(self
, src
, cond
):
27 data
= os
.read(src
.fileno(), 100)
32 status
= self
.child
.wait()
35 if os
.WIFEXITED(status
) and os
.WEXITSTATUS(status
) == 0:
38 if os
.WIFEXITED(status
):
39 status
= os
.WEXITSTATUS(status
)
40 if status
== 1 and not self
.error
:
41 return False # Cancelled
42 dialog
.alert(None, "Command failed with exit code %d:\n%s\n" %
45 dialog
.alert(None, "Command failed:\n%s\n" % self
.error
)
48 def compile(policy
, interface
):
50 # A new local feed may have been registered, so update the interface from the cache
51 info("0compile command completed successfully. Reloading interface details.")
52 reader
.update_from_cache(interface
)
56 # Get the chosen versions
57 src_policy
= Policy(interface
.uri
, src
= True)
58 src_policy
.freshness
= 0
60 src_policy
.recalculate()
61 if not src_policy
.ready
:
62 raise Exception('Internal error: required source components not found!')
64 root_iface
= iface_cache
.iface_cache
.get_interface(src_policy
.root
)
65 impl
= src_policy
.implementation
[root_iface
]
66 min_version
= impl
.metadata
.get(XMLNS_0COMPILE
+ ' min-version', None)
67 if not min_version
: min_version
= '0.4'
68 # Check the syntax is valid and the version is high enough
69 if model
.parse_version(min_version
) < model
.parse_version('0.4'):
72 # Do the whole build-and-register-feed
75 '--not-before=' + min_version
,
76 "http://0install.net/2006/interfaces/0compile.xml",
79 interface
.uri
), add_feed
)
81 # Prompt user to choose source version
83 c
.run(['0launch', '--gui', '--source', '--download-only', interface
.uri
], build
)