2 from zeroinstall
.support
import tasks
3 from zeroinstall
.injector
.model
import *
4 from zeroinstall
.injector
.iface_cache
import iface_cache
5 from zeroinstall
.injector
import writer
, namespaces
, gpg
8 from logging
import warn
11 from dialog
import DialogResponse
, Template
12 from impl_list
import ImplementationList
17 _dialogs
= {} # Interface -> Properties
30 def format_para(para
):
31 lines
= [l
.strip() for l
in para
.split('\n')]
32 return ' '.join(lines
)
34 def have_source_for(policy
, interface
):
35 # Note: we don't want to actually fetch the source interfaces at
36 # this point, so we check whether:
37 # - We have a feed of type 'src' (not fetched), or
38 # - We have a source implementation in a regular feed
40 for f
in interface
.feeds
:
41 if f
.machine
== 'src':
43 # Don't have any src feeds. Do we have a source implementation
44 # as part of a regular feed?
45 impls
= interface
.implementations
.values()
46 for f
in policy
.usable_feeds(interface
):
48 feed_iface
= iface_cache
.get_interface(f
.uri
)
49 if feed_iface
.implementations
:
50 impls
.extend(feed_iface
.implementations
.values())
51 except zeroinstall
.NeedDownload
:
52 pass # OK, will get called again later
54 warn("Failed to load feed '%s': %s", f
.uri
, str(ex
))
56 if x
.machine
== 'src':
61 def __init__(self
, widgets
):
62 description
= widgets
.get_widget('description')
63 description
.connect('button-press-event', self
.button_press
)
65 self
.buffer = description
.get_buffer()
66 self
.heading_style
= self
.buffer.create_tag(underline
= True, scale
= 1.2)
67 self
.link_style
= self
.buffer.create_tag(underline
= True, foreground
= 'blue')
68 description
.set_size_request(-1, 100)
70 def button_press(self
, tv
, bev
):
71 if bev
.type == gtk
.gdk
.BUTTON_PRESS
and bev
.button
== 1:
72 x
, y
= tv
.window_to_buffer_coords(tv
.get_window_type(bev
.window
),
73 int(bev
.x
), int(bev
.y
))
74 itr
= tv
.get_iter_at_location(x
, y
)
75 if itr
and self
.link_style
in itr
.get_tags():
76 if not itr
.begins_tag(self
.link_style
):
77 itr
.backward_to_tag_toggle(self
.link_style
)
79 end
.forward_to_tag_toggle(self
.link_style
)
80 target
= itr
.get_text(end
).strip()
82 browser
.open_in_browser(target
)
84 def set_details(self
, interface
):
86 heading_style
= self
.heading_style
88 buffer.delete(buffer.get_start_iter(), buffer.get_end_iter())
90 iter = buffer.get_start_iter()
92 buffer.insert_with_tags(iter,
93 '%s ' % interface
.get_name(), heading_style
)
94 buffer.insert(iter, '(%s)' % interface
.summary
)
96 buffer.insert(iter, '\n%s\n' % interface
.uri
)
98 # (converts to local time)
99 if interface
.last_modified
:
100 buffer.insert(iter, '\nLast upstream change: %s' % time
.ctime(interface
.last_modified
))
102 if interface
.last_checked
:
103 buffer.insert(iter, '\nLast checked: %s' % time
.ctime(interface
.last_checked
))
105 last_check_attempt
= iface_cache
.get_last_check_attempt(interface
.uri
)
106 if last_check_attempt
:
107 if interface
.last_checked
and interface
.last_checked
>= last_check_attempt
:
108 pass # Don't bother reporting successful attempts
110 buffer.insert(iter, '\nLast check attempt: %s (failed or in progress)' %
111 time
.ctime(last_check_attempt
))
113 buffer.insert_with_tags(iter, '\n\nDescription\n', heading_style
)
115 paragraphs
= [format_para(p
) for p
in (interface
.description
or "-").split('\n\n')]
117 buffer.insert(iter, '\n\n'.join(paragraphs
))
118 buffer.insert(iter, '\n')
121 for x
in interface
.get_metadata(namespaces
.XMLNS_IFACE
, 'homepage'):
123 buffer.insert(iter, '\n')
125 buffer.insert(iter, 'Homepage: ')
126 buffer.insert_with_tags(iter, '%s\n' % x
.content
, self
.link_style
)
128 buffer.insert_with_tags(iter, '\nSignatures\n', heading_style
)
129 sigs
= iface_cache
.get_cached_signatures(interface
.uri
)
132 if isinstance(sig
, gpg
.ValidSig
):
134 details
= sig
.get_details()
136 if item
[0] in ('pub', 'uid') and len(item
) > 9:
139 buffer.insert_with_tags(iter, 'Valid signature by "%s"\n- Dated: %s\n- Fingerprint: %s\n' %
140 (name
, time
.ctime(sig
.get_timestamp()), sig
.fingerprint
))
141 if not sig
.is_trusted():
142 if interface
.uri
.startswith('/'):
143 buffer.insert_with_tags(iter, 'WARNING: This key is not in the trusted list\n')
145 buffer.insert_with_tags(iter, 'WARNING: This key is not in the trusted list (either you removed it, or '
146 'you trust one of the other signatures)\n')
148 buffer.insert_with_tags(iter, '%s\n' % sig
)
150 buffer.insert_with_tags(iter, 'No signature information (old style interface or out-of-date cache)\n')
157 def __init__(self
, policy
, interface
, widgets
):
159 self
.interface
= interface
161 self
.model
= gtk
.ListStore(str, str, bool)
163 self
.description
= Description(widgets
)
165 self
.lines
= self
.build_model()
166 for line
in self
.lines
:
167 self
.model
.append(line
)
169 add_remote_feed_button
= widgets
.get_widget('add_remote_feed')
170 add_remote_feed_button
.connect('clicked', lambda b
: add_remote_feed(policy
, widgets
.get_widget(), interface
))
172 add_local_feed_button
= widgets
.get_widget('add_local_feed')
173 add_local_feed_button
.connect('clicked', lambda b
: add_local_feed(policy
, interface
))
175 self
.remove_feed_button
= widgets
.get_widget('remove_feed')
176 def remove_feed(button
):
177 model
, iter = self
.tv
.get_selection().get_selected()
178 feed_uri
= model
[iter][Feeds
.URI
]
179 for x
in interface
.feeds
:
180 if x
.uri
== feed_uri
:
182 interface
.extra_feeds
.remove(x
)
183 writer
.save_interface(interface
)
187 dialog
.alert(self
.get_toplevel(),
188 _("Can't remove '%s' as you didn't add it.") % feed_uri
)
190 raise Exception("Missing feed '%s'!" % feed_uri
)
191 self
.remove_feed_button
.connect('clicked', remove_feed
)
193 self
.tv
= widgets
.get_widget('feeds_list')
194 self
.tv
.set_model(self
.model
)
195 text
= gtk
.CellRendererText()
196 self
.tv
.append_column(gtk
.TreeViewColumn('Source', text
, text
= Feeds
.URI
, sensitive
= Feeds
.USED
))
197 self
.tv
.append_column(gtk
.TreeViewColumn('Arch', text
, text
= Feeds
.ARCH
, sensitive
= Feeds
.USED
))
199 sel
= self
.tv
.get_selection()
200 sel
.set_mode(gtk
.SELECTION_BROWSE
)
201 sel
.connect('changed', self
.sel_changed
)
202 sel
.select_path((0,))
204 def build_model(self
):
205 usable_feeds
= frozenset(self
.policy
.usable_feeds(self
.interface
))
206 unusable_feeds
= frozenset(self
.interface
.feeds
) - usable_feeds
208 out
= [[self
.interface
.uri
, None, True]]
210 if self
.interface
.feeds
:
211 for feed
in usable_feeds
:
212 out
.append([feed
.uri
, feed
.arch
, True])
213 for feed
in unusable_feeds
:
214 out
.append([feed
.uri
, feed
.arch
, False])
217 def sel_changed(self
, sel
):
218 model
, miter
= sel
.get_selected()
219 if not miter
: return # build in progress
220 iface
= model
[miter
][Feeds
.URI
]
221 # Only enable removing user_override feeds
222 enable_remove
= False
223 for x
in self
.interface
.feeds
:
227 self
.remove_feed_button
.set_sensitive( enable_remove
)
228 self
.description
.set_details(iface_cache
.get_interface(iface
))
231 new_lines
= self
.build_model()
232 if new_lines
!= self
.lines
:
233 self
.lines
= new_lines
235 for line
in self
.lines
:
236 self
.model
.append(line
)
237 self
.tv
.get_selection().select_path((0,))
239 self
.sel_changed(self
.tv
.get_selection())
247 def __init__(self
, policy
, interface
, show_versions
= False):
250 widgets
= Template('interface_properties')
252 self
.interface
= interface
254 window
= widgets
.get_widget('interface_properties')
256 window
.set_title('Properties for ' + interface
.get_name())
257 window
.set_default_size(-1, gtk
.gdk
.screen_height() / 3)
259 self
.compile_button
= widgets
.get_widget('compile')
260 self
.compile_button
.connect('clicked', lambda b
: compile.compile(policy
, interface
))
261 window
.set_default_response(gtk
.RESPONSE_CANCEL
)
263 def response(dialog
, resp
):
264 if resp
== gtk
.RESPONSE_CANCEL
:
266 elif resp
== gtk
.RESPONSE_HELP
:
267 properties_help
.display()
268 window
.connect('response', response
)
270 notebook
= widgets
.get_widget('interface_notebook')
273 feeds
= Feeds(policy
, interface
, widgets
)
275 stability
= widgets
.get_widget('preferred_stability')
276 stability
.set_active(0)
277 if interface
.stability_policy
:
278 i
= [stable
, testing
, developer
].index(interface
.stability_policy
)
280 warn("Unknown stability policy %s", interface
.stability_policy
)
284 stability
.set_active(i
)
286 def set_stability_policy(combo
):
287 i
= stability
.get_active()
291 name
= stability
.get_model()[i
][0].lower()
292 new_stability
= stability_levels
[name
]
293 interface
.set_stability_policy(new_stability
)
294 writer
.save_interface(interface
)
296 stability
.connect('changed', set_stability_policy
)
298 self
.use_list
= ImplementationList(policy
, interface
, widgets
)
302 feeds
.tv
.grab_focus()
308 window
.connect('destroy', lambda s
: policy
.watchers
.remove(updated
))
309 policy
.watchers
.append(updated
)
316 self
.window
.destroy()
318 def shade_compile(self
):
319 self
.compile_button
.set_sensitive(have_source_for(self
.policy
, self
.interface
))
321 def update_list(self
):
322 ranked_items
= self
.policy
.solver
.details
.get(self
.interface
, None)
323 if ranked_items
is None:
324 # The Solver didn't get this far, but we should still display them!
325 ranked_items
= self
.interface
.implementations
.values()
327 self
.use_list
.set_items(ranked_items
)
330 def add_remote_feed(policy
, parent
, interface
):
332 d
= gtk
.MessageDialog(parent
, 0, gtk
.MESSAGE_QUESTION
, gtk
.BUTTONS_CANCEL
,
333 _('Enter the URL of the new source of implementations of this interface:'))
334 d
.add_button(gtk
.STOCK_ADD
, gtk
.RESPONSE_OK
)
335 d
.set_default_response(gtk
.RESPONSE_OK
)
338 align
= gtk
.VBox(False, 0)
339 align
.set_border_width(4)
341 d
.vbox
.pack_start(align
)
342 entry
.set_activates_default(True)
348 error_label
= gtk
.Label('')
349 error_label
.set_padding(4, 4)
350 align
.pack_start(error_label
)
356 error_label
.set_text(message
)
362 got_response
= DialogResponse(d
)
364 tasks
.check(got_response
)
365 resp
= got_response
.response
368 if resp
== gtk
.RESPONSE_OK
:
370 url
= entry
.get_text()
372 raise SafeException(_('Enter a URL'))
373 fetch
= policy
.fetcher
.download_and_import_feed(url
, iface_cache
)
375 d
.set_sensitive(False)
377 d
.set_sensitive(True)
380 iface
= iface_cache
.get_interface(url
)
382 d
.set_sensitive(True)
384 error('Failed to read interface')
386 if not iface
.feed_for
:
387 error("Feed '%s' is not a feed for '%s'." % (iface
.get_name(), interface
.get_name()))
388 elif interface
.uri
not in iface
.feed_for
:
389 error("This is not a feed for '%s'.\nOnly for:\n%s" %
390 (interface
.uri
, '\n'.join(iface
.feed_for
)))
391 elif iface
.uri
in [f
.uri
for f
in interface
.feeds
]:
392 error("Feed from '%s' has already been added!" % iface
.uri
)
394 interface
.extra_feeds
.append(Feed(iface
.uri
, arch
= None, user_override
= True))
395 writer
.save_interface(interface
)
398 except SafeException
, ex
:
403 except Exception, ex
:
405 traceback
.print_exc()
406 policy
.handler
.report_error(ex
)
408 def add_local_feed(policy
, interface
):
409 sel
= gtk
.FileSelection(_('Select XML feed file'))
410 sel
.set_has_separator(False)
412 from xml
.dom
import minidom
413 from zeroinstall
.injector
import reader
414 feed
= sel
.get_filename()
416 feed_targets
= policy
.get_feed_targets(feed
)
417 if interface
not in feed_targets
:
418 raise Exception("Not a valid feed for '%s'; this is a feed for:\n%s" %
420 '\n'.join([f
.uri
for f
in feed_targets
])))
421 if interface
.get_feed(feed
):
422 dialog
.alert(None, 'This feed is already registered.')
424 interface
.extra_feeds
.append(Feed(feed
, user_override
= True, arch
= None))
426 writer
.save_interface(interface
)
428 reader
.update_from_cache(interface
)
430 except Exception, ex
:
431 dialog
.alert(None, "Error in feed file '%s':\n\n%s" % (feed
, str(ex
)))
433 sel
.ok_button
.connect('clicked', ok
)
434 sel
.cancel_button
.connect('clicked', lambda b
: sel
.destroy())
437 def edit(policy
, interface
, show_versions
= False):
438 assert isinstance(interface
, Interface
)
439 if interface
in _dialogs
:
440 _dialogs
[interface
].destroy()
441 _dialogs
[interface
] = Properties(policy
, interface
, show_versions
)
443 properties_help
= help_box
.HelpBox("Injector Properties Help",
444 ('Interface properties', """
445 This window displays information about an interface. There are two tabs at the top: \
446 Feeds shows the places where the injector looks for implementations of the interface, while \
447 Versions shows the list of implementations found (from all feeds) in order of preference."""),
449 ('The Feeds tab', """
450 At the top is a list of feeds. By default, the injector uses the full name of the interface \
451 as the default feed location (so if you ask it to run the program "http://foo/bar.xml" then it will \
452 by default get the list of versions by downloading "http://foo/bar.xml".
454 You can add and remove feeds using the buttons on the right. The main feed may also add \
455 some extra feeds itself. If you've checked out a developer version of a program, you can use \
456 the 'Add Local Feed...' button to let the injector know about it, for example.
458 Below the list of feeds is a box describing the selected one:
460 - At the top is its short name.
461 - Below that is the address (a URL or filename).
462 - 'Last upstream change' shows the version of the cached copy of the interface file.
463 - 'Last checked' is the last time a fresh copy of the upstream interface file was \
465 - Then there is a longer description of the interface."""),
467 ('The Versions tab', """
468 This tab shows a list of all known implementations of the interface, from all the feeds. \
469 The columns have the following meanings:
471 Version gives the version number. High-numbered versions are considered to be \
472 better than low-numbered ones.
474 Released gives the date this entry was added to the feed.
476 Stability is 'stable' if the implementation is believed to be stable, 'buggy' if \
477 it is known to contain serious bugs, and 'testing' if its stability is not yet \
478 known. This information is normally supplied and updated by the author of the \
479 software, but you can override their rating (overridden values are shown in upper-case). \
480 You can also use the special level 'preferred'.
482 C(ached) indicates whether the implementation is already stored on your computer. \
483 In off-line mode, only cached implementations are considered for use.
485 Arch indicates what kind of computer system the implementation is for, or 'any' \
486 if it works with all types of system.
489 The implementations are listed in the injector's currently preferred order (the one \
490 at the top will actually be used). Usable implementations all come before unusable \
493 Unusable ones are those for incompatible \
494 architectures, those marked as 'buggy', versions explicitly marked as incompatible with \
495 another interface you are using and, in off-line mode, uncached implementations. Unusable \
496 implementations are shown crossed out.
498 For the usable implementations, the order is as follows:
500 - Preferred implementations come first.
502 - Then, if network use is set to 'Minimal', cached implementations come before \
505 - Then, implementations at or above the selected stability level come before all others.
507 - Then, higher-numbered versions come before low-numbered ones.
509 - Then cached come before non-cached (for 'Full' network use mode).
513 If there is no binary available for your system then you may be able to compile one from \
514 source by clicking on the Compile button. If no source is available, the Compile button will \