From d08e0aac2f76bb6056be4e45c1cadd32320e8c00 Mon Sep 17 00:00:00 2001 From: guinux Date: Wed, 30 Jan 2013 18:37:41 +0100 Subject: [PATCH] improved conflicts and provides handling --- gui/manager.glade | 80 +++++++------- pamac/common.py | 8 ++ pamac/manager.py | 247 +++++++++++++++++++++++++------------------ pamac/transaction.py | 30 +++--- test.py | 1 + 5 files changed, 211 insertions(+), 155 deletions(-) diff --git a/gui/manager.glade b/gui/manager.glade index 8f71edc..6ce630c 100644 --- a/gui/manager.glade +++ b/gui/manager.glade @@ -1,19 +1,46 @@ - + False + 5 True center-on-parent dialog True True - - - True + + False vertical - 5 + 2 + + + False + end + + + gtk-ok + True + True + True + True + + + + False + True + 0 + + + + + False + True + end + 0 + + True @@ -23,7 +50,7 @@ False True - 0 + 1 @@ -31,6 +58,8 @@ True True in + 300 + 250 True @@ -39,10 +68,9 @@ False False False + 0 - - multiple - + @@ -69,38 +97,14 @@ True True - 1 - - - - - True - False - end - - - gtk-ok - True - True - True - True - - - - False - True - 0 - - - - - False - True 2 + + ChooseButton + False @@ -133,13 +137,13 @@ - 200 - 120 True True True True in + 300 + 250 True diff --git a/pamac/common.py b/pamac/common.py index 1e2d1df..55b271d 100755 --- a/pamac/common.py +++ b/pamac/common.py @@ -9,3 +9,11 @@ def format_size(size): else: size_string = '%.2f MiB' % (KiB_size / 1024) return size_string + +def format_pkg_name(name): + unwanted = ['>','<','='] + for i in unwanted: + index = name.find(i) + if index != -1: + name = name[0:index] + return name diff --git a/pamac/manager.py b/pamac/manager.py index 1f803b2..b4bf1ec 100755 --- a/pamac/manager.py +++ b/pamac/manager.py @@ -226,6 +226,61 @@ def set_transaction_sum(): #bottom_label.set_markup('Total Download size: '+common.format_size(totaldlcb)) top_label.set_markup('Transaction Summary') +def handle_error(error): + global transaction_type + global transaction_dict + if not 'DBus.Error.NoReply' in str(error): + transaction.ErrorDialog.format_secondary_text('Error:\n'+str(error)) + response = transaction.ErrorDialog.run() + if response: + transaction.ErrorDialog.hide() + transaction.t_lock = False + transaction.Release() + transaction.ProgressWindow.hide() + transaction.to_add = [] + transaction.to_remove = [] + transaction_dict.clear() + transaction_type = None + set_packages_list() + print('error',error) + +def handle_reply(reply): + global transaction_type + global transaction_dict + if str(reply): + transaction.ErrorDialog.format_secondary_text('Error:\n'+str(reply)) + response = transaction.ErrorDialog.run() + if response: + transaction.ErrorDialog.hide() + if transaction.do_syncfirst is True: + transaction.do_syncfirst = False + transaction.list_first = [] + transaction.t_lock = False + transaction.Release() + transaction.ProgressWindow.hide() + transaction.to_add = [] + transaction.to_remove = [] + transaction_dict.clear() + if (transaction_type == "install") or (transaction_type == "remove"): + transaction_type = None + set_packages_list() + else: + transaction_type = None + if transaction.get_updates(): + do_sysupgrade() + +def do_refresh(): + """Sync databases like pacman -Sy""" + transaction.get_handle() + if transaction.t_lock is False: + transaction.t_lock = True + transaction.progress_label.set_text('Refreshing...') + transaction.action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/refresh-cache.png') + transaction.ProgressWindow.show_all() + while Gtk.events_pending(): + Gtk.main_iteration() + transaction.Refresh(reply_handler = handle_reply, error_handler = handle_error, timeout = 2000*1000) + def do_sysupgrade(): global transaction_type """Upgrade a system like pacman -Su""" @@ -245,59 +300,18 @@ def do_sysupgrade(): 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() + handle_error(error) else: + transaction.get_to_remove() + transaction.get_to_add() + transaction.check_conflicts() transaction.Release() - transaction.t_lock = False - -def handle_error(error): - global transaction_type - global transaction_dict - if not 'DBus.Error.NoReply' in str(error): - transaction.ErrorDialog.format_secondary_text('Commit Error:\n'+str(error)) - response = transaction.ErrorDialog.run() - if response: - transaction.ErrorDialog.hide() - transaction.t_lock = False - transaction.Release() - transaction.ProgressWindow.hide() - transaction.to_add = [] - transaction.to_remove = [] - transaction_dict.clear() - transaction_type = None - set_packages_list() - -def handle_reply(reply): - global transaction_type - global transaction_dict - if str(reply): - transaction.ErrorDialog.format_secondary_text('Commit Error:\n'+str(reply)) - response = transaction.ErrorDialog.run() - if response: - transaction.ErrorDialog.hide() - if transaction.do_syncfirst is True: - transaction.do_syncfirst = False - transaction.list_first = [] - transaction.t_lock = False - transaction.Release() - transaction.ProgressWindow.hide() - transaction.to_add = [] - transaction.to_remove = [] - transaction_dict.clear() - transaction_type = None - set_packages_list() + 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 choose_provides(): to_check = [] @@ -311,7 +325,7 @@ def choose_provides(): break for target in to_check: for name in target.depends: - depends.append(name) + depends.append(common.format_pkg_name(name)) for installed_pkg in transaction.handle.get_localdb().pkgcache: if installed_pkg.name in depends: depends.remove(installed_pkg.name) @@ -320,20 +334,55 @@ def choose_provides(): if pkg.name in depends: depends.remove(pkg.name) if depends: + for installed_pkg in transaction.handle.get_localdb().pkgcache: + for name in pkg.provides: + if common.format_pkg_name(name) in depends: + depends.remove(common.format_pkg_name(name)) for repo in transaction.handle.get_syncdbs(): for pkg in repo.pkgcache: for depend in depends: for name in pkg.provides: - if name == depend: + if common.format_pkg_name(name) == depend: if not provides.__contains__(depend): provides[depend] = [] - provides.get(depend).append(pkg.name) - if provides: + if not pkg.name in provides.get(depend): + provides.get(depend).append(pkg.name) + if provides: for virtualdep, liste in provides.items(): - choose_list.clear() - for name in liste: - choose_list.append([False, name]) - ChooseDialog.show_all() + if ('-module' in virtualdep) or ('linux' in virtualdep): + print('choose module') + pkgs = transaction.handle.get_localdb().search('linux3') + installed_linux = [] + to_remove_from_add = [] + for i in pkgs: + if len(i.name) == 7: + installed_linux.append(i.name) + for to_install in transaction.to_add: + if 'linux3' in to_install: + if len(to_install) == 7: + if to_install in transaction_dict.keys(): + installed_linux.append(to_install) + else: + to_remove_from_add.append(to_install) + for name in liste: + if name == to_install: + if not to_install in transaction_dict.keys(): + to_remove_from_add.append(to_install) + for to_remove in to_remove_from_add: + transaction.to_add.remove(to_remove) + for name in liste: + for linux in installed_linux: + if not transaction.handle.get_localdb().get_pkg(name): + if linux in name: + transaction.to_add.append(name) + else: + choose_list.clear() + for name in liste: + if transaction.handle.get_localdb().get_pkg(name): + choose_list.append([True, name]) + else: + choose_list.append([False, name]) + ChooseDialog.run() class Handler: def on_MainWindow_delete_event(self, *arg): @@ -366,34 +415,38 @@ class Handler: transaction.Remove(pkgname) error = transaction.Prepare() 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() - set_transaction_sum() - ConfDialog.show_all() + handle_error(error) + else: + transaction.get_to_remove() + transaction.get_to_add() + set_transaction_sum() + ConfDialog.show_all() if transaction_type is "install": if transaction.init_transaction(noconflicts = True): for pkgname in transaction_dict.keys(): transaction.Add(pkgname) error = transaction.Prepare() if error: - transaction.ErrorDialog.format_secondary_text(error) - response = transaction.ErrorDialog.run() - if response: - transaction.ErrorDialog.hide() + handle_error(error) + else: + transaction.get_to_remove() + transaction.get_to_add() transaction.Release() - transaction.t_lock = False - transaction.get_to_remove() - transaction.get_to_add() - #choose_provides() - transaction.check_conflicts() - transaction.Release() - if len(transaction.to_add) + len(transaction.to_update) + len(transaction.to_remove) != 0: + choose_provides() + transaction.check_conflicts() + if transaction.init_transaction(noconflicts = True): + for pkgname in transaction.to_add: + transaction.Add(pkgname) + for pkgname in transaction.to_remove: + transaction.Remove(pkgname) + error = transaction.Prepare() + if error: + handle_error(error) + else: + transaction.get_to_remove() + transaction.get_to_add() + transaction.Release() + if len(transaction.to_add) + len(transaction.to_remove) != 0: set_transaction_sum() ConfDialog.show_all() else: @@ -412,7 +465,7 @@ class Handler: def on_RefreshButton_clicked(self, *arg): transaction.do_refresh() - refresh_packages_list() + set_packages_list() def on_TransCancelButton_clicked(self, *arg): global transaction_type @@ -427,6 +480,7 @@ class Handler: ConfDialog.hide() transaction.progress_label.set_text('Preparing...') transaction.action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/setup.png') + transaction.progress_bar.set_text('') while Gtk.events_pending(): Gtk.main_iteration() if transaction_type == "remove": @@ -434,7 +488,7 @@ class Handler: while Gtk.events_pending(): Gtk.main_iteration() transaction.Commit(reply_handler = handle_reply, error_handler = handle_error, timeout = 2000*1000) - if transaction_type == ("install" or "update"): + if (transaction_type == "install") or (transaction_type == "update"): if transaction.init_transaction(noconflicts = True, nodeps = True): for pkgname in transaction.to_update: transaction.Add(pkgname) @@ -444,12 +498,7 @@ class Handler: transaction.Remove(pkgname) error = transaction.Prepare() if error: - transaction.ErrorDialog.format_secondary_text(error) - response = transaction.ErrorDialog.run() - if response: - transaction.ErrorDialog.hide() - transaction.Release() - transaction.t_lock = False + handle_error(error) else: transaction.ProgressWindow.show_all() while Gtk.events_pending(): @@ -543,23 +592,18 @@ class Handler: line = 0 while line < len(choose_list): if choose_list[line][0] is True: - transaction.to_add.append(snap_list[line][1]) - elif choose_list[line][0] in transaction.to_add: - transaction.to_add.remove(snap_list[line][1]) + if not choose_list[line][1] in transaction.to_add: + if not transaction.handle.get_localdb().get_pkg(choose_list[line][1]): + transaction.to_add.append(choose_list[line][1]) + if choose_list[line][0] is False: + if choose_list[line][1] in transaction.to_add: + transaction.to_add.remove(choose_list[line][1]) line += 1 + print(transaction.to_add) def main(): 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() + do_refresh() MainWindow.show_all() while Gtk.events_pending(): Gtk.main_iteration() @@ -567,4 +611,3 @@ def main(): if __name__ == "__main__": main() Gtk.main() - diff --git a/pamac/transaction.py b/pamac/transaction.py index cea9ce9..be1b43f 100755 --- a/pamac/transaction.py +++ b/pamac/transaction.py @@ -7,7 +7,7 @@ import pyalpm import dbus from dbus.mainloop.glib import DBusGMainLoop -from pamac import config +from pamac import config, common interface = Gtk.Builder() interface.add_from_file('/usr/share/pamac/gui/dialogs.glade') @@ -105,29 +105,29 @@ def check_conflicts(): installed_pkg_name.append(installed_pkg.name) for target in to_check: for name in target.replaces: - if name in installed_pkg_name: - if not name in to_remove: - to_remove.append(name) + if common.format_pkg_name(name) in installed_pkg_name: + if not common.format_pkg_name(name) in to_remove: + to_remove.append(common.format_pkg_name(name)) if warning: warning = warning+'\n' warning = warning+name+' will be replaced by '+target.name for name in target.conflicts: - if name in to_add: - to_add.remove(name) + if common.format_pkg_name(name) in to_add: + to_add.remove(common.format_pkg_name(name)) to_add.remove(target.name) if warning: warning = warning+'\n' warning = warning+name+' conflicts with '+target.name+'\nNone of them will be installed' - if name in installed_pkg_name: - if not name in to_remove: - to_remove.append(name) + if common.format_pkg_name(name) in installed_pkg_name: + if not common.format_pkg_name(name) in to_remove: + to_remove.append(common.format_pkg_name(name)) if warning: warning = warning+'\n' warning = warning+name+' conflicts with '+target.name for installed_pkg in handle.get_localdb().pkgcache: for name in installed_pkg.conflicts: - if name == target.name: - if not name in to_remove: + if common.format_pkg_name(name) == target.name: + if not common.format_pkg_name(name) in to_remove: to_remove.append(installed_pkg.name) if warning: warning = warning+'\n' @@ -135,12 +135,12 @@ def check_conflicts(): for repo in handle.get_syncdbs(): for pkg in repo.pkgcache: for name in pkg.replaces: - if name in installed_pkg_name: - if not name in to_remove: - to_remove.append(name) + if common.format_pkg_name(name) in installed_pkg_name: + if not common.format_pkg_name(name) in to_remove: + to_remove.append(common.format_pkg_name(name)) if warning: warning = warning+'\n' - warning = warning+name+' will be replaced by '+pkg.name + warning = warning+common.format_pkg_name(name)+' will be replaced by '+pkg.name if not pkg.name in to_add: to_add.append(pkg.name) if warning: diff --git a/test.py b/test.py index fbad541..77a4082 100755 --- a/test.py +++ b/test.py @@ -13,6 +13,7 @@ for repo in config.handle.get_syncdbs(): for pkg in syncpkgs.values(): for name in pkg.depends: if (not name in syncpkgs.keys()) and (not '>' in name) and (not '<' in name) and (not '=' in name): + if 'module' in name: if not virtualdeps.__contains__(name): virtualdeps[name] = [] virtualdeps.get(name).append(pkg.name)