finnally got it ;)

This commit is contained in:
guinux 2013-03-15 17:15:34 +01:00
parent 76714eedb8
commit 73e1e8d6c0
5 changed files with 172 additions and 99 deletions

View File

@ -10,7 +10,6 @@
<property name="window_position">center-on-parent</property>
<property name="type_hint">dialog</property>
<property name="skip_taskbar_hint">True</property>
<property name="urgency_hint">True</property>
<property name="has_resize_grip">False</property>
<property name="message_type">error</property>
<property name="buttons">ok</property>
@ -36,6 +35,41 @@
</object>
</child>
</object>
<object class="GtkMessageDialog" id="InfoDialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="window_position">center-on-parent</property>
<property name="type_hint">dialog</property>
<property name="skip_taskbar_hint">True</property>
<property name="buttons">ok</property>
<child internal-child="vbox">
<object class="GtkBox" id="messagedialog-vbox9">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="messagedialog-action_area9">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
</object>
<object class="GtkMessageDialog" id="QuestionDialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>

View File

@ -9,7 +9,6 @@
<property name="window_position">center-on-parent</property>
<property name="type_hint">dialog</property>
<property name="skip_taskbar_hint">True</property>
<property name="urgency_hint">True</property>
<property name="deletable">False</property>
<property name="transient_for">ManagerWindow</property>
<child internal-child="vbox">
@ -121,7 +120,6 @@
<property name="icon">/usr/share/pamac/icons/22x22/status/package-info.png</property>
<property name="type_hint">dialog</property>
<property name="skip_taskbar_hint">True</property>
<property name="urgency_hint">True</property>
<property name="deletable">False</property>
<property name="transient_for">ManagerWindow</property>
<child>
@ -265,6 +263,7 @@
<property name="height_request">500</property>
<property name="can_focus">False</property>
<property name="title" translatable="yes">Pamac</property>
<property name="window_position">center</property>
<property name="default_width">800</property>
<property name="default_height">500</property>
<property name="icon">/usr/share/pamac/icons/22x22/status/package-sources.png</property>

View File

@ -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,8 +133,9 @@ 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:
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:
@ -152,6 +153,8 @@ class PamacDBusService(dbus.service.Object):
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)+')'
@ -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
@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:
t = config.handle.init_transaction()
self.t = config.handle.init_transaction()
db.update(force=False)
t.release()
except pyalpm.error as e:
self.error += ' --> '+str(e)+'\n'
t.release()
#break
finally:
self.t.release()
self.CheckUpdates()
return self.error
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
@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
@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
@dbus.service.method('org.manjaro.pamac', '', 's', async_callbacks=('success', 'nosuccess'))
def Interrupt(self, success, nosuccess):
def interrupt():
self.error = ''
if self.policykit_test(sender,connexion,'org.manjaro.pamac.commit'):
#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:
return 'You are not authorized'
#nosuccess('You are not authorized')
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()
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()

View File

@ -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:
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)
#print('cancel disabled')
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()
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,6 +800,10 @@ class Handler:
def on_ProgressCancelButton_clicked(self, *arg):
print('cancelled')
error = transaction.Interrupt()
if error:
handle_error(error)
else:
handle_reply('')
def main(_mode):

View File

@ -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')