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

View File

@ -75,10 +75,10 @@ def target_signal_handler(target):
progress_bar.set_text(target)
def percent_signal_handler(percent):
if float(percent) > 1:
if percent > 1:
progress_bar.pulse()
else:
progress_bar.set_fraction(float(percent))
progress_bar.set_fraction(percent)
bus = dbus.SystemBus()
bus.add_signal_receiver(action_signal_handler, dbus_interface = "org.manjaro.pamac", signal_name = "EmitAction")
@ -583,7 +583,10 @@ def finalize():
ProgressWindow.show_all()
while Gtk.events_pending():
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):
depends = [pkg_list]