reduce the dbus signal calls and correctly handle password timeout

This commit is contained in:
guinux 2013-03-29 15:49:47 +01:00
parent 831af0a5ca
commit ee592092ad
2 changed files with 49 additions and 20 deletions

View File

@ -20,9 +20,13 @@ class PamacDBusService(dbus.service.Object):
self.task = None self.task = None
self.error = '' self.error = ''
self.warning = '' self.warning = ''
self.previous_action = ''
self.action = 'Preparing...' self.action = 'Preparing...'
self.previous_icon = ''
self.icon = '/usr/share/pamac/icons/24x24/status/setup.png' self.icon = '/usr/share/pamac/icons/24x24/status/setup.png'
self.previous_target = ''
self.target = '' self.target = ''
self.previous_percent = 0
self.percent = 0 self.percent = 0
self.total_size = 0 self.total_size = 0
self.already_transferred = 0 self.already_transferred = 0
@ -107,8 +111,12 @@ class PamacDBusService(dbus.service.Object):
self.action = '' self.action = ''
#self.EmitTarget('') #self.EmitTarget('')
#self.EmitPercent(str(0)) #self.EmitPercent(str(0))
self.EmitAction(self.action) if self.action != self.previous_action:
self.EmitIcon(self.icon) self.previous_action = self.action
self.EmitAction(self.action)
if self.icon != self.previous_icon:
self.previous_icon = self.icon
self.EmitIcon(self.icon)
print(ID,event) print(ID,event)
def cb_conv(self, *args): def cb_conv(self, *args):
@ -141,31 +149,43 @@ class PamacDBusService(dbus.service.Object):
try: try:
if (self.t.to_remove or self.t.to_add): if (self.t.to_remove or self.t.to_add):
for pkg in self.t.to_remove+self.t.to_add: for pkg in self.t.to_remove+self.t.to_add:
if pkg.name+'-'+pkg.version in _target: if pkg.filename == _target:
size = pkg.size size = pkg.size
if _transferred == size: if _transferred == size:
self.already_transferred += size self.already_transferred += size
self.action = 'Downloading '+common.format_size(self.total_size) self.action = 'Downloading '+common.format_size(self.total_size)
self.target = _target self.target = _target
self.percent = fraction self.percent = round(fraction, 2)
self.icon = '/usr/share/pamac/icons/24x24/status/package-download.png' self.icon = '/usr/share/pamac/icons/24x24/status/package-download.png'
else: else:
self.action = 'Refreshing...' self.action = 'Refreshing...'
self.target = _target self.target = _target
self.percent = 2 self.percent = 2
self.icon = '/usr/share/pamac/icons/24x24/status/refresh-cache.png' self.icon = '/usr/share/pamac/icons/24x24/status/refresh-cache.png'
self.EmitAction(self.action) if self.action != self.previous_action:
self.EmitIcon(self.icon) self.previous_action = self.action
self.EmitTarget(self.target) self.EmitAction(self.action)
self.EmitPercent(str(self.percent)) if self.icon != self.previous_icon:
self.previous_icon = self.icon
self.EmitIcon(self.icon)
if self.target != self.previous_target:
self.previous_target = self.target
self.EmitTarget(self.target)
if self.percent != self.previous_percent:
self.previous_percent = self.percent
self.EmitPercent(self.percent)
except pyalpm.error: except pyalpm.error:
pass pass
def cb_progress(self, _target, _percent, n, i): def cb_progress(self, _target, _percent, n, i):
self.target = _target+' ('+str(i)+'/'+str(n)+')' self.target = _target+' ('+str(i)+'/'+str(n)+')'
self.percent = _percent/100 self.percent = round(_percent/100, 2)
self.EmitTarget(self.target) if self.target != self.previous_target:
self.EmitPercent(str(self.percent)) self.previous_target = self.target
self.EmitTarget(self.target)
if self.percent != self.previous_percent:
self.previous_percent = self.percent
self.EmitPercent(self.percent)
def policykit_test(self, sender, connexion, action): def policykit_test(self, sender, connexion, action):
bus = dbus.SystemBus() bus = dbus.SystemBus()
@ -345,13 +365,19 @@ class PamacDBusService(dbus.service.Object):
self.EmitTransactionError(self.error) self.EmitTransactionError(self.error)
else: else:
self.EmitTransactionDone('Transaction successfully finished') self.EmitTransactionDone('Transaction successfully finished')
if self.policykit_test(sender,connexion,'org.manjaro.pamac.commit'): try:
self.task = Process(target=commit) authorized = self.policykit_test(sender,connexion,'org.manjaro.pamac.commit')
self.task.start() except dbus.exceptions.DBusException as e:
else :
self.t.release()
self.EmitTransactionError('You are not authorized') self.EmitTransactionError('You are not authorized')
success('') success('')
else:
if authorized:
self.task = Process(target=commit)
self.task.start()
else :
self.t.release()
self.EmitTransactionError('You are not authorized')
success('')
@dbus.service.signal('org.manjaro.pamac') @dbus.service.signal('org.manjaro.pamac')
def EmitTransactionDone(self, message): def EmitTransactionDone(self, message):

View File

@ -75,10 +75,10 @@ def target_signal_handler(target):
progress_bar.set_text(target) progress_bar.set_text(target)
def percent_signal_handler(percent): def percent_signal_handler(percent):
if float(percent) > 1: if percent > 1:
progress_bar.pulse() progress_bar.pulse()
else: else:
progress_bar.set_fraction(float(percent)) progress_bar.set_fraction(percent)
bus = dbus.SystemBus() bus = dbus.SystemBus()
bus.add_signal_receiver(action_signal_handler, dbus_interface = "org.manjaro.pamac", signal_name = "EmitAction") bus.add_signal_receiver(action_signal_handler, dbus_interface = "org.manjaro.pamac", signal_name = "EmitAction")
@ -583,7 +583,10 @@ def finalize():
ProgressWindow.show_all() ProgressWindow.show_all()
while Gtk.events_pending(): while Gtk.events_pending():
Gtk.main_iteration() Gtk.main_iteration()
transaction.Commit()#reply_handler = handle_reply, error_handler = handle_error, timeout = 2000*1000) try:
transaction.Commit()#reply_handler = handle_reply, error_handler = handle_error, timeout = 2000*1000)
except dbus.exceptions.DBusException as e:
handle_error(str(e))
def check_conflicts(mode, pkg_list): def check_conflicts(mode, pkg_list):
depends = [pkg_list] depends = [pkg_list]