diff --git a/gui/dialogs.glade b/gui/dialogs.glade
index 8a6d966..afda014 100644
--- a/gui/dialogs.glade
+++ b/gui/dialogs.glade
@@ -10,7 +10,6 @@
center-on-parent
dialog
True
- True
False
error
ok
@@ -36,6 +35,41 @@
+
False
5
diff --git a/gui/manager.glade b/gui/manager.glade
index 0b6dcf5..e93f92a 100644
--- a/gui/manager.glade
+++ b/gui/manager.glade
@@ -9,7 +9,6 @@
center-on-parent
dialog
True
- True
False
ManagerWindow
@@ -121,7 +120,6 @@
/usr/share/pamac/icons/22x22/status/package-info.png
dialog
True
- True
False
ManagerWindow
@@ -265,6 +263,7 @@
500
False
Pamac
+ center
800
500
/usr/share/pamac/icons/22x22/status/package-sources.png
diff --git a/pamac-daemon b/pamac-daemon
index da19cbe..ce0d298 100755
--- a/pamac-daemon
+++ b/pamac-daemon
@@ -8,7 +8,7 @@ from gi.repository import GObject
import pyalpm
#import traceback
-#import threading
+from multiprocessing import Process
from pamac import config, common
class PamacDBusService(dbus.service.Object):
@@ -17,6 +17,7 @@ class PamacDBusService(dbus.service.Object):
bus_name = dbus.service.BusName('org.manjaro.pamac', bus)
dbus.service.Object.__init__(self, bus_name, '/org/manjaro/pamac')
self.t = None
+ self.task = None
self.error = ''
self.warning = ''
self.action = 'Preparing...'
@@ -109,14 +110,13 @@ class PamacDBusService(dbus.service.Object):
print("conversation", args)
def cb_log(self, level, line):
- #global t
_logmask = pyalpm.LOG_ERROR | pyalpm.LOG_WARNING
if not (level & _logmask):
return
if level & pyalpm.LOG_ERROR:
self.error += "ERROR: "+line
print(self.error)
- #t.release()
+ #self.t.release()
elif level & pyalpm.LOG_WARNING:
self.warning += "WARNING: "+line
elif level & pyalpm.LOG_DEBUG:
@@ -133,25 +133,28 @@ class PamacDBusService(dbus.service.Object):
if self.total_size > 0:
fraction = (_transferred+self.already_transferred)/self.total_size
size = 0
- if (t.to_remove or t.to_add):
- for pkg in t.to_remove+t.to_add:
- if pkg.name+'-'+pkg.version in _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.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))
+ 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:
+ 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.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))
+ except pyalpm.error:
+ pass
def cb_progress(self, _target, _percent, n, i):
self.target = _target+' ('+str(i)+'/'+str(n)+')'
@@ -159,7 +162,7 @@ class PamacDBusService(dbus.service.Object):
self.EmitTarget(self.target)
self.EmitPercent(str(self.percent))
- def policykit_test(self, sender,connexion, action):
+ def policykit_test(self, sender, connexion, action):
bus = dbus.SystemBus()
proxy_dbus = connexion.get_object('org.freedesktop.DBus','/org/freedesktop/DBus/Bus', False)
dbus_info = dbus.Interface(proxy_dbus,'org.freedesktop.DBus')
@@ -184,30 +187,35 @@ class PamacDBusService(dbus.service.Object):
updates = True
self.EmitAvailableUpdates(updates)
- @dbus.service.method('org.manjaro.pamac', '', 's')
- def Refresh(self):
- global t
- self.error = ''
- for db in config.handle.get_syncdbs():
- try:
- t = config.handle.init_transaction()
- db.update(force=False)
- t.release()
- except pyalpm.error as e:
- self.error += ' --> '+str(e)+'\n'
- t.release()
- #break
- self.CheckUpdates()
- return self.error
+ @dbus.service.method('org.manjaro.pamac', '', 's', async_callbacks=('success', 'nosuccess'))
+ def Refresh(self, success, nosuccess):
+ def refresh():
+ self.target = ''
+ self.percent = 0
+ self.error = ''
+ for db in config.handle.get_syncdbs():
+ try:
+ self.t = config.handle.init_transaction()
+ db.update(force=False)
+ except pyalpm.error as e:
+ self.error += ' --> '+str(e)+'\n'
+ #break
+ finally:
+ self.t.release()
+ self.CheckUpdates()
+ if self.error:
+ self.EmitTransactionError(self.error)
+ self.task = Process(target=refresh)
+ self.task.start()
+ success('')
@dbus.service.method('org.manjaro.pamac', 'a{sb}', 's', sender_keyword='sender', connection_keyword='connexion')
def Init(self, options, sender=None, connexion=None):
- global t
self.error = ''
if self.policykit_test(sender,connexion,'org.manjaro.pamac.init_release'):
try:
- t = config.handle.init_transaction(**options)
- print('Init:',t.flags)
+ self.t = config.handle.init_transaction(**options)
+ print('Init:',self.t.flags)
except pyalpm.error as e:
self.error += ' --> '+str(e)+'\n'
finally:
@@ -217,11 +225,10 @@ class PamacDBusService(dbus.service.Object):
@dbus.service.method('org.manjaro.pamac', '', 's')
def Sysupgrade(self):
- global t
self.error = ''
try:
- t.sysupgrade(downgrade=False)
- print('to_upgrade:',t.to_add)
+ self.t.sysupgrade(downgrade=False)
+ print('to_upgrade:',self.t.to_add)
except pyalpm.error as e:
self.error += ' --> '+str(e)+'\n'
finally:
@@ -229,12 +236,11 @@ class PamacDBusService(dbus.service.Object):
@dbus.service.method('org.manjaro.pamac', 's', 's')
def Remove(self, pkgname):
- global t
self.error = ''
try:
pkg = config.handle.get_localdb().get_pkg(pkgname)
if pkg is not None:
- t.remove_pkg(pkg)
+ self.t.remove_pkg(pkg)
except pyalpm.error as e:
self.error += ' --> '+str(e)+'\n'
finally:
@@ -242,13 +248,12 @@ class PamacDBusService(dbus.service.Object):
@dbus.service.method('org.manjaro.pamac', 's', 's')
def Add(self, pkgname):
- global t
self.error = ''
try:
for repo in config.handle.get_syncdbs():
pkg = repo.get_pkg(pkgname)
if pkg:
- t.add_pkg(pkg)
+ self.t.add_pkg(pkg)
break
except pyalpm.error as e:
self.error += ' --> '+str(e)+'\n'
@@ -257,12 +262,11 @@ class PamacDBusService(dbus.service.Object):
@dbus.service.method('org.manjaro.pamac', '', 's')
def Prepare(self):
- global t
self.error = ''
try:
- t.prepare()
- print('to_add:',t.to_add)
- print('to_remove:',t.to_remove)
+ self.t.prepare()
+ print('to_add:',self.t.to_add)
+ print('to_remove:',self.t.to_remove)
except pyalpm.error as e:
print(e)
self.error += ' --> '+str(e)+'\n'
@@ -271,48 +275,79 @@ class PamacDBusService(dbus.service.Object):
@dbus.service.method('org.manjaro.pamac', '', 'as')
def To_Remove(self):
- global t
liste = []
- for pkg in t.to_remove:
+ for pkg in self.t.to_remove:
liste.append(pkg.name)
- return liste
+ return liste
@dbus.service.method('org.manjaro.pamac', '', 'as')
def To_Add(self):
- global t
liste = []
- for pkg in t.to_add:
+ for pkg in self.t.to_add:
liste.append(pkg.name)
- return liste
+ return liste
- @dbus.service.method('org.manjaro.pamac', '', 's', sender_keyword='sender', connection_keyword='connexion')#, async_callbacks=('success', 'nosuccess'))
- def Commit(self, sender=None, connexion=None):#success, nosuccess, sender=None, connexion=None):
- global t
- self.error = ''
- if self.policykit_test(sender,connexion,'org.manjaro.pamac.commit'):
+ @dbus.service.method('org.manjaro.pamac', '', 's', async_callbacks=('success', 'nosuccess'))
+ def Interrupt(self, success, nosuccess):
+ def interrupt():
+ self.error = ''
+ #try:
+ # self.t.interrupt()
+ #except pyalpm.error as e:
+ # self.error += ' --> '+str(e)+'\n'
try:
- t.commit()
- #success('')
+ self.t.release()
+ #except pyalpm.error as e:
+ #self.error += ' --> '+str(e)+'\n'
+ except:
+ pass
+ finally:
+ self.CheckUpdates()
+ #if self.error:
+ #self.EmitTransactionError(self.error)
+ self.task.terminate()
+ interrupt()
+ success('')
+
+ @dbus.service.method('org.manjaro.pamac', '', 's', sender_keyword='sender', connection_keyword='connexion', async_callbacks=('success', 'nosuccess'))
+ def Commit(self, success, nosuccess, sender=None, connexion=None):
+ def commit():
+ self.error = ''
+ try:
+ self.t.commit()
except pyalpm.error as e:
#error = traceback.format_exc()
self.error += ' --> '+str(e)+'\n'
- #nosuccess(self.error)
#except dbus.exceptions.DBusException:
#pass
finally:
self.CheckUpdates()
- return self.error
+ if self.error:
+ 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 :
- return 'You are not authorized'
- #nosuccess('You are not authorized')
+ self.t.release()
+ self.EmitTransactionError('You are not authorized')
+ success('')
+
+ @dbus.service.signal('org.manjaro.pamac')
+ def EmitTransactionDone(self, message):
+ pass
+
+ @dbus.service.signal('org.manjaro.pamac')
+ def EmitTransactionError(self, message):
+ pass
@dbus.service.method('org.manjaro.pamac', '', 's', sender_keyword='sender', connection_keyword='connexion')
def Release(self, sender=None, connexion=None):
- global t
self.error = ''
if self.policykit_test(sender,connexion,'org.manjaro.pamac.init_release'):
try:
- t.release()
+ self.t.release()
except pyalpm.error as e:
self.error += ' --> '+str(e)+'\n'
finally:
@@ -322,13 +357,13 @@ class PamacDBusService(dbus.service.Object):
@dbus.service.method('org.manjaro.pamac')
def StopDaemon(self):
- global t
try:
- t.release()
+ self.t.release()
except:
pass
mainloop.quit()
+GObject.threads_init()
DBusGMainLoop(set_as_default=True)
myservice = PamacDBusService()
mainloop = GObject.MainLoop()
diff --git a/pamac/main.py b/pamac/main.py
index 91aa579..4702698 100644
--- a/pamac/main.py
+++ b/pamac/main.py
@@ -12,10 +12,11 @@ from pamac import config, common, transaction
interface = Gtk.Builder()
-interface.add_from_file('/usr/share/pamac/gui/dialogs.glade')
-ErrorDialog = interface.get_object('ErrorDialog')
-WarningDialog = interface.get_object('WarningDialog')
-QuestionDialog = interface.get_object('QuestionDialog')
+#interface.add_from_file('/usr/share/pamac/gui/dialogs.glade')
+#ErrorDialog = interface.get_object('ErrorDialog')
+#WarningDialog = interface.get_object('WarningDialog')
+#InfoDialog = interface.get_object('InfoDialog')
+#QuestionDialog = interface.get_object('QuestionDialog')
interface.add_from_file('/usr/share/pamac/gui/manager.glade')
ManagerWindow = interface.get_object("ManagerWindow")
@@ -49,12 +50,10 @@ update_label = interface.get_object('update_label')
def action_signal_handler(action):
if action:
progress_label.set_text(action)
- #if 'Downloading' in action:
- # print('cancel enabled')
- # ProgressCancelButton.set_visible(True)
- #else:
- ProgressCancelButton.set_visible(False)
- #print('cancel disabled')
+ if ('Refreshing' in action) or ('Preparing' in action) or ('Downloading' in action) or ('Checking' in action) or ('Resolving' in action) or ('Loading' in action):
+ ProgressCancelButton.set_visible(True)
+ else:
+ ProgressCancelButton.set_visible(False)
def icon_signal_handler(icon):
action_icon.set_from_file(icon)
@@ -275,6 +274,7 @@ def set_transaction_sum():
def handle_error(error):
global transaction_type
global transaction_dict
+ ProgressWindow.hide()
if error:
if not 'DBus.Error.NoReply' in str(error):
print('error:', error)
@@ -283,11 +283,7 @@ def handle_error(error):
if response:
transaction.ErrorDialog.hide()
transaction.t_lock = False
- try:
- transaction.Release()
- except:
- pass
- ProgressWindow.hide()
+ transaction.Release()
if mode == 'manager':
transaction.to_add = []
transaction.to_remove = []
@@ -302,17 +298,17 @@ def handle_error(error):
def handle_reply(reply):
global transaction_type
global transaction_dict
+ ProgressWindow.hide()
if reply:
- transaction.ErrorDialog.format_secondary_text(reply)
- response = transaction.ErrorDialog.run()
+ transaction.InfoDialog.format_secondary_text(reply)
+ response = transaction.InfoDialog.run()
if response:
- transaction.ErrorDialog.hide()
+ transaction.InfoDialog.hide()
transaction.t_lock = False
try:
transaction.Release()
except:
pass
- ProgressWindow.hide()
transaction.to_add = []
transaction.to_remove = []
transaction_dict.clear()
@@ -327,6 +323,9 @@ def handle_reply(reply):
if mode == 'manager':
do_sysupgrade()
+bus.add_signal_receiver(handle_reply, dbus_interface = "org.manjaro.pamac", signal_name = "EmitTransactionDone")
+bus.add_signal_receiver(handle_error, dbus_interface = "org.manjaro.pamac", signal_name = "EmitTransactionError")
+
def do_refresh():
"""Sync databases like pacman -Sy"""
if transaction.t_lock is False:
@@ -336,7 +335,7 @@ def do_refresh():
ProgressWindow.show_all()
while Gtk.events_pending():
Gtk.main_iteration()
- transaction.Refresh(reply_handler = handle_reply, error_handler = handle_error, timeout = 2000*1000)
+ transaction.Refresh(reply_handler = handle_reply, error_handler = handle_error)#, timeout = 2000*1000)
def have_updates():
do_syncfirst, updates = transaction.get_updates()
@@ -417,7 +416,7 @@ 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)
+ transaction.Commit()#reply_handler = handle_reply, error_handler = handle_error, timeout = 2000*1000)
def check_conflicts(pkg_list):
depends = [pkg_list]
@@ -801,7 +800,11 @@ class Handler:
def on_ProgressCancelButton_clicked(self, *arg):
print('cancelled')
- handle_reply('')
+ error = transaction.Interrupt()
+ if error:
+ handle_error(error)
+ else:
+ handle_reply('')
def main(_mode):
if common.pid_file_exists():
diff --git a/pamac/transaction.py b/pamac/transaction.py
index e597c1f..641d8d4 100644
--- a/pamac/transaction.py
+++ b/pamac/transaction.py
@@ -24,7 +24,8 @@ interface = Gtk.Builder()
interface.add_from_file('/usr/share/pamac/gui/dialogs.glade')
ErrorDialog = interface.get_object('ErrorDialog')
WarningDialog = interface.get_object('WarningDialog')
-QuestionDialog = interface.get_object('QuestionDialog')
+#QuestionDialog = interface.get_object('QuestionDialog')
+InfoDialog = interface.get_object('InfoDialog')
def get_handle():
global handle
@@ -57,6 +58,7 @@ Prepare = proxy.get_dbus_method('Prepare','org.manjaro.pamac')
To_Remove = proxy.get_dbus_method('To_Remove','org.manjaro.pamac')
To_Add = proxy.get_dbus_method('To_Add','org.manjaro.pamac')
Commit = proxy.get_dbus_method('Commit','org.manjaro.pamac')
+Interrupt = proxy.get_dbus_method('Interrupt','org.manjaro.pamac')
Release = proxy.get_dbus_method('Release','org.manjaro.pamac')
StopDaemon = proxy.get_dbus_method('StopDaemon','org.manjaro.pamac')