improve updates and conflicts handling

This commit is contained in:
guinux 2013-01-26 14:42:01 +01:00
parent acf5f9f66c
commit a769f4e397
4 changed files with 162 additions and 81 deletions

View File

@ -4,11 +4,7 @@
from gi.repository import Gtk from gi.repository import Gtk
import pyalpm import pyalpm
import math
import sys
from time import strftime, localtime from time import strftime, localtime
from os import geteuid
import traceback
from pamac import config, common, transaction from pamac import config, common, transaction
@ -227,6 +223,42 @@ def set_transaction_sum():
#bottom_label.set_markup('<b>Total Download size: </b>'+common.format_size(totaldlcb)) #bottom_label.set_markup('<b>Total Download size: </b>'+common.format_size(totaldlcb))
top_label.set_markup('<big><b>Transaction Summary</b></big>') top_label.set_markup('<big><b>Transaction Summary</b></big>')
def do_sysupgrade():
global transaction_type
"""Upgrade a system like pacman -Su"""
if transaction.t_lock is False:
transaction_type = "update"
if transaction.do_syncfirst is True:
if transaction.init_transaction(recurse = True):
for pkg in transaction.list_first:
transaction.Add(pkg.name)
transaction.get_to_remove()
transaction.get_to_add()
transaction.check_conflicts()
transaction.Release()
set_transaction_sum()
ConfDialog.show_all()
else:
if transaction.init_transaction():
error = transaction.Sysupgrade()
if error:
transaction.ErrorDialog.format_secondary_text(error)
response = transaction.ErrorDialog.run()
if response:
transaction.ErrorDialog.hide()
transaction.Release()
transaction.t_lock = False
transaction.get_to_remove()
transaction.get_to_add()
transaction.check_conflicts()
transaction.Release()
if len(transaction.to_add) + len(transaction.to_update) + len(transaction.to_remove) != 0:
set_transaction_sum()
ConfDialog.show_all()
else:
transaction.Release()
transaction.t_lock = False
def handle_error(error): def handle_error(error):
global transaction_type global transaction_type
global transaction_dict global transaction_dict
@ -252,6 +284,9 @@ def handle_reply(reply):
response = transaction.ErrorDialog.run() response = transaction.ErrorDialog.run()
if response: if response:
transaction.ErrorDialog.hide() transaction.ErrorDialog.hide()
if transaction.do_syncfirst is True:
transaction.do_syncfirst = False
transaction.list_first = []
transaction.t_lock = False transaction.t_lock = False
transaction.Release() transaction.Release()
transaction.ProgressWindow.hide() transaction.ProgressWindow.hide()
@ -318,8 +353,15 @@ class Handler:
transaction.get_to_add() transaction.get_to_add()
transaction.check_conflicts() transaction.check_conflicts()
transaction.Release() transaction.Release()
set_transaction_sum() if len(transaction.to_add) + len(transaction.to_update) + len(transaction.to_remove) != 0:
ConfDialog.show_all() set_transaction_sum()
ConfDialog.show_all()
else:
transaction.WarningDialog.format_secondary_text('Nothing to do due to packages conflicts')
response = transaction.WarningDialog.run()
if response:
transaction.WarningDialog.hide()
transaction.t_lock = False
def on_EraseButton_clicked(self, *arg): def on_EraseButton_clicked(self, *arg):
global transaction_type global transaction_type
@ -333,9 +375,13 @@ class Handler:
refresh_packages_list() refresh_packages_list()
def on_TransCancelButton_clicked(self, *arg): def on_TransCancelButton_clicked(self, *arg):
global transaction_type
transaction.ProgressWindow.hide()
ConfDialog.hide() ConfDialog.hide()
transaction.t_lock = False transaction.t_lock = False
transaction.Release() transaction.Release()
if transaction_type == "update":
transaction_type = None
def on_TransValidButton_clicked(self, *arg): def on_TransValidButton_clicked(self, *arg):
ConfDialog.hide() ConfDialog.hide()
@ -343,13 +389,15 @@ class Handler:
transaction.action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/setup.png') transaction.action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/setup.png')
while Gtk.events_pending(): while Gtk.events_pending():
Gtk.main_iteration() Gtk.main_iteration()
if transaction_type is "remove": if transaction_type == "remove":
transaction.ProgressWindow.show_all() transaction.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) transaction.Commit(reply_handler = handle_reply, error_handler = handle_error, timeout = 2000*1000)
if transaction_type is "install": if transaction_type == ("install" or "update"):
if transaction.init_transaction(noconflicts = True, nodeps = True): if transaction.init_transaction(noconflicts = True, nodeps = True):
for pkgname in transaction.to_update:
transaction.Add(pkgname)
for pkgname in transaction.to_add: for pkgname in transaction.to_add:
transaction.Add(pkgname) transaction.Add(pkgname)
for pkgname in transaction.to_remove: for pkgname in transaction.to_remove:
@ -449,7 +497,19 @@ class Handler:
def main(): def main():
interface.connect_signals(Handler()) interface.connect_signals(Handler())
transaction.do_refresh()
do_sysupgrade()
#~ if transaction.get_updates():
#~ transaction.QuestionDialog.format_secondary_text("Some updates are available.\nIt is higly recommended to update your system before installing/removing software.\nDo you want to update your system now ?")
#~ response = transaction.QuestionDialog.run()
#~ if response == Gtk.ResponseType.YES:
#~ transaction.QuestionDialog.hide()
#~ do_sysupgrade()
#~ else:
#~ transaction.QuestionDialog.hide()
MainWindow.show_all() MainWindow.show_all()
while Gtk.events_pending():
Gtk.main_iteration()
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@ -165,7 +165,6 @@ class PamacDBusService(dbus.service.Object):
try: try:
t = config.handle.init_transaction() t = config.handle.init_transaction()
db.update(force=False) db.update(force=False)
print('refresh')
t.release() t.release()
except pyalpm.error: except pyalpm.error:
error = traceback.format_exc() error = traceback.format_exc()

View File

@ -1,10 +1,9 @@
#! /usr/bin/python #! /usr/bin/python
# -*-coding:utf-8-*- # -*-coding:utf-8-*-
from gi.repository import Gtk, GObject from gi.repository import Gtk
import pyalpm import pyalpm
import traceback
import dbus import dbus
from dbus.mainloop.glib import DBusGMainLoop from dbus.mainloop.glib import DBusGMainLoop
@ -15,6 +14,7 @@ interface.add_from_file('/usr/share/pamac/gui/dialogs.glade')
ErrorDialog = interface.get_object('ErrorDialog') ErrorDialog = interface.get_object('ErrorDialog')
WarningDialog = interface.get_object('WarningDialog') WarningDialog = interface.get_object('WarningDialog')
QuestionDialog = interface.get_object('QuestionDialog')
ProgressWindow = interface.get_object('ProgressWindow') ProgressWindow = interface.get_object('ProgressWindow')
progress_bar = interface.get_object('progressbar2') progress_bar = interface.get_object('progressbar2')
progress_label = interface.get_object('progresslabel2') progress_label = interface.get_object('progresslabel2')
@ -64,10 +64,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 percent == '0': #~ if percent == '0':
progress_bar.pulse() #~ progress_bar.pulse()
else: #~ else:
progress_bar.set_fraction(float(percent)) progress_bar.set_fraction(float(percent))
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")
bus.add_signal_receiver(icon_signal_handler, dbus_interface = "org.manjaro.pamac", signal_name = "EmitIcon") bus.add_signal_receiver(icon_signal_handler, dbus_interface = "org.manjaro.pamac", signal_name = "EmitIcon")
@ -82,7 +82,7 @@ def init_transaction(**options):
t_lock = True t_lock = True
return True return True
else: else:
ErrorDialog.format_secondary_text(error) ErrorDialog.format_secondary_text('Init Error:\n'+str(error))
response = ErrorDialog.run() response = ErrorDialog.run()
if response: if response:
ErrorDialog.hide() ErrorDialog.hide()
@ -111,16 +111,28 @@ def check_conflicts():
warning = warning+pkg.name+' will be replaced by '+target.name warning = warning+pkg.name+' will be replaced by '+target.name
if target.conflicts: if target.conflicts:
for name in target.conflicts: for name in target.conflicts:
if name in to_add:
to_add.remove(name)
to_add.remove(target.name)
if warning:
warning = warning+'\n'
warning = warning+name+' conflicts with '+target.name+'\nNone of them will be installed'
pkg = handle.get_localdb().get_pkg(name) pkg = handle.get_localdb().get_pkg(name)
if pkg: if pkg:
if not pkg.name in to_remove: if not pkg.name in to_remove:
to_remove.append(pkg.name) to_remove.append(pkg.name)
if warning:
warning = warning+'\n'
warning = warning+pkg.name+' conflicts with '+target.name
for installed_pkg in handle.get_localdb().pkgcache: for installed_pkg in handle.get_localdb().pkgcache:
if installed_pkg.conflicts: if installed_pkg.conflicts:
for name in installed_pkg.conflicts: for name in installed_pkg.conflicts:
if name == target.name: if name == target.name:
if not name in to_remove: if not name in to_remove:
to_remove.append(installed_pkg.name) to_remove.append(installed_pkg.name)
if warning:
warning = warning+'\n'
warning = warning+installed_pkg.name+' conflicts with '+target.name
for repo in handle.get_syncdbs(): for repo in handle.get_syncdbs():
for pkg in repo.pkgcache: for pkg in repo.pkgcache:
if pkg.replaces: if pkg.replaces:
@ -141,8 +153,6 @@ def check_conflicts():
if response: if response:
WarningDialog.hide() WarningDialog.hide()
def get_to_remove(): def get_to_remove():
global to_remove global to_remove
to_remove = To_Remove() to_remove = To_Remove()
@ -154,21 +164,31 @@ def get_to_add():
def do_refresh(): def do_refresh():
"""Sync databases like pacman -Sy""" """Sync databases like pacman -Sy"""
global t_lock global t_lock
ProgressWindow.show_all() get_handle()
print('show')
if t_lock is False: if t_lock is False:
t_lock = True t_lock = True
progress_label.set_text('Refreshing...')
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/refresh-cache.png')
ProgressWindow.show_all() ProgressWindow.show_all()
error = Refresh(timeout = 2000*1000) while Gtk.events_pending():
if error: Gtk.main_iteration()
ErrorDialog.format_secondary_text(error) Refresh(reply_handler = handle_reply, error_handler = handle_error, timeout = 2000*1000)
response = ErrorDialog.run()
if response: def handle_error(error):
ErrorDialog.hide() global t_lock
Release() if not 'DBus.Error.NoReply' in str(error):
ProgressWindow.hide() transaction.ErrorDialog.format_secondary_text('Refresh Error:\n'+str(error))
print('hide') response = transaction.ErrorDialog.run()
t_lock = False if response:
transaction.ErrorDialog.hide()
t_lock = False
Release()
ProgressWindow.hide()
def handle_reply(reply):
global t_lock
t_lock = False
ProgressWindow.hide()
def get_updates(): def get_updates():
"""Return a list of package objects in local db which can be updated""" """Return a list of package objects in local db which can be updated"""

View File

@ -3,9 +3,6 @@
from gi.repository import Gtk from gi.repository import Gtk
import pyalpm
from os import geteuid
from pamac import config, common, transaction from pamac import config, common, transaction
interface = Gtk.Builder() interface = Gtk.Builder()
@ -65,13 +62,58 @@ def set_transaction_add():
#bottom_label.set_markup('<b>Total Download size: </b>'+format_size(totaldlcb)) #bottom_label.set_markup('<b>Total Download size: </b>'+format_size(totaldlcb))
top_label.set_markup('<big><b>Additionnal Transaction(s)</b></big>') top_label.set_markup('<big><b>Additionnal Transaction(s)</b></big>')
def do_sysupgrade():
"""Upgrade a system like pacman -Su"""
if transaction.t_lock is False:
if transaction.do_syncfirst is True:
if transaction.init_transaction(recurse = True):
for pkg in transaction.list_first:
transaction.Add(pkg.name)
transaction.get_to_remove()
transaction.get_to_add()
set_transaction_add()
if len(transaction.to_add) + len(transaction.to_remove) != 0:
ConfDialog.show_all()
else:
finalize()
else:
if transaction.init_transaction():
error = transaction.Sysupgrade()
if error:
transaction.ErrorDialog.format_secondary_text(error)
response = transaction.ErrorDialog.run()
if response:
transaction.ErrorDialog.hide()
transaction.Release()
transaction.t_lock = False
transaction.get_to_remove()
transaction.get_to_add()
transaction.check_conflicts()
transaction.Release()
if len(transaction.to_update) == 0:
transaction.t_lock = False
print("Nothing to update")
else:
if transaction.init_transaction(noconflicts = True, nodeps = True):
for pkgname in transaction.to_update:
transaction.Add(pkgname)
for pkgname in transaction.to_add:
transaction.Add(pkgname)
for pkgname in transaction.to_remove:
transaction.Remove(pkgname)
set_transaction_add()
if len(transaction.to_add) + len(transaction.to_remove) != 0:
ConfDialog.show_all()
else:
finalize()
def finalize(): def finalize():
error = transaction.Prepare() error = transaction.Prepare()
if error: if error:
ErrorDialog.format_secondary_text(error) transaction.ErrorDialog.format_secondary_text(error)
response = ErrorDialog.run() response = transaction.ErrorDialog.run()
if response: if response:
ErrorDialog.hide() transaction.ErrorDialog.hide()
transaction.Release() transaction.Release()
transaction.t_lock = False transaction.t_lock = False
else: else:
@ -99,56 +141,14 @@ def handle_reply(reply):
response = transaction.ErrorDialog.run() response = transaction.ErrorDialog.run()
if response: if response:
transaction.ErrorDialog.hide() transaction.ErrorDialog.hide()
if transaction.do_syncfirst is True:
transaction.do_syncfirst = False
transaction.list_first = []
transaction.t_lock = False transaction.t_lock = False
transaction.Release() transaction.Release()
transaction.ProgressWindow.hide() transaction.ProgressWindow.hide()
have_updates() have_updates()
def do_sysupgrade():
"""Upgrade a system like pacman -Su"""
if transaction.t_lock is False:
if transaction.do_syncfirst is True:
if transaction.init_transaction(recurse = True):
for pkg in transaction.list_first:
transaction.Add(pkg.name)
transaction.get_to_remove()
transaction.get_to_add()
set_transaction_add()
if len(transaction.to_add) != 0:
ConfDialog.show_all()
else:
finalize()
transaction.do_syncfirst = False
transaction.list_first = []
else:
if transaction.init_transaction():
error = transaction.Sysupgrade()
if error:
transaction.ErrorDialog.format_secondary_text(error)
response = transaction.ErrorDialog.run()
if response:
transaction.ErrorDialog.hide()
transaction.Release()
transaction.t_lock = False
transaction.get_to_remove()
transaction.get_to_add()
transaction.check_conflicts()
transaction.Release()
if len(transaction.to_add) + len(transaction.to_remove) == 0:
transaction.t_lock = False
print("Nothing to update")
else:
if transaction.init_transaction(noconflicts = True, nodeps = True):
for pkgname in transaction.to_add:
transaction.Add(pkgname)
for pkgname in transaction.to_remove:
transaction.Remove(pkgname)
set_transaction_add()
if len(transaction_add) != 0:
ConfDialog.show_all()
else:
finalize()
class Handler: class Handler:
def on_UpdateWindow_delete_event(self, *arg): def on_UpdateWindow_delete_event(self, *arg):
transaction.StopDaemon() transaction.StopDaemon()
@ -191,6 +191,8 @@ def main():
have_updates() have_updates()
interface.connect_signals(Handler()) interface.connect_signals(Handler())
UpdateWindow.show_all() UpdateWindow.show_all()
while Gtk.events_pending():
Gtk.main_iteration()
if __name__ == "__main__": if __name__ == "__main__":
main() main()