1 import gtk
, os
, gobject
3 from policy
import Policy
6 from reader
import InvalidInterface
7 from model
import SafeException
12 class GUIPolicy(Policy
):
17 def __init__(self
, interface
, prog_args
):
18 Policy
.__init
__(self
, interface
)
24 self
.window
= mainwindow
.MainWindow(prog_args
)
25 self
.window
.browser
.set_root(policy
.get_interface(policy
.root
))
27 def monitor_download(self
, dl
):
28 error_stream
= dl
.start()
29 def error_ready(src
, cond
):
30 got
= os
.read(src
.fileno(), 100)
34 if self
.n_downloads
== 0:
35 self
.window
.progress
.hide()
36 gobject
.source_remove(self
.pulse
)
39 data
= dl
.error_stream_closed()
40 self
.check_signed_data(dl
, data
)
41 except download
.DownloadError
, ex
:
42 dialog
.alert(self
.window
,
43 "Error downloading interface '%s':\n\n%s" %
44 (dl
.interface
.uri
, ex
))
45 except InvalidInterface
, ex
:
46 dialog
.alert(self
.window
,
47 "Syntax error in downloaded interface '%s':\n\n%s" %
48 (dl
.interface
.uri
, ex
))
49 except SafeException
, ex
:
50 dialog
.alert(self
.window
,
51 "Error updating interface '%s':\n\n%s" %
52 (dl
.interface
.uri
, ex
))
54 dl
.error_stream_data(got
)
57 gobject
.io_add_watch(error_stream
,
58 gobject
.IO_IN | gobject
.IO_HUP
,
62 if self
.pulse
is None:
63 progress
= self
.window
.progress
64 self
.pulse
= gobject
.timeout_add(50, lambda: progress
.pulse() or True)
67 def confirm_trust_keys(self
, interface
, sigs
, iface_xml
):
69 trust_box
.trust_box
.confirm_trust(interface
, sigs
, iface_xml
)
75 def pretty_size(size
):
79 return '%d bytes' % size
81 for unit
in ('Kb', 'Mb', 'Gb', 'Tb'):
85 return '%.1f %s' % (size
, unit
)