improved conflicts and provides handling

This commit is contained in:
guinux 2013-01-30 18:37:41 +01:00
parent 90b04d0319
commit d08e0aac2f
5 changed files with 211 additions and 155 deletions

View File

@ -1,19 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<interface> <interface>
<!-- interface-requires gtk+ 3.0 --> <!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="ChooseDialog"> <object class="GtkDialog" id="ChooseDialog">
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="modal">True</property> <property name="modal">True</property>
<property name="window_position">center-on-parent</property> <property name="window_position">center-on-parent</property>
<property name="type_hint">dialog</property> <property name="type_hint">dialog</property>
<property name="skip_taskbar_hint">True</property> <property name="skip_taskbar_hint">True</property>
<property name="urgency_hint">True</property> <property name="urgency_hint">True</property>
<child> <child internal-child="vbox">
<object class="GtkBox" id="box8"> <object class="GtkBox" id="dialog-vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="spacing">5</property> <property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area1">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="ChooseButton">
<property name="label">gtk-ok</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="on_ChooseButton_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</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>
<child> <child>
<object class="GtkLabel" id="chooselabel"> <object class="GtkLabel" id="chooselabel">
<property name="visible">True</property> <property name="visible">True</property>
@ -23,7 +50,7 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">0</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
<child> <child>
@ -31,6 +58,8 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="shadow_type">in</property> <property name="shadow_type">in</property>
<property name="min_content_width">300</property>
<property name="min_content_height">250</property>
<child> <child>
<object class="GtkTreeView" id="treeview5"> <object class="GtkTreeView" id="treeview5">
<property name="visible">True</property> <property name="visible">True</property>
@ -39,10 +68,9 @@
<property name="headers_visible">False</property> <property name="headers_visible">False</property>
<property name="headers_clickable">False</property> <property name="headers_clickable">False</property>
<property name="enable_search">False</property> <property name="enable_search">False</property>
<property name="search_column">0</property>
<child internal-child="selection"> <child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection5"> <object class="GtkTreeSelection" id="treeview-selection5"/>
<property name="mode">multiple</property>
</object>
</child> </child>
<child> <child>
<object class="GtkTreeViewColumn" id="treeviewcolumn1"> <object class="GtkTreeViewColumn" id="treeviewcolumn1">
@ -69,38 +97,14 @@
<packing> <packing>
<property name="expand">True</property> <property name="expand">True</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButtonBox" id="buttonbox3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="ChooseButton">
<property name="label">gtk-ok</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="on_ChooseButton_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
</object> </object>
</child> </child>
<action-widgets>
<action-widget response="0">ChooseButton</action-widget>
</action-widgets>
</object> </object>
<object class="GtkWindow" id="ConfDialog"> <object class="GtkWindow" id="ConfDialog">
<property name="can_focus">False</property> <property name="can_focus">False</property>
@ -133,13 +137,13 @@
</child> </child>
<child> <child>
<object class="GtkScrolledWindow" id="scrolledwindow4"> <object class="GtkScrolledWindow" id="scrolledwindow4">
<property name="width_request">200</property>
<property name="height_request">120</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="vexpand">True</property> <property name="vexpand">True</property>
<property name="shadow_type">in</property> <property name="shadow_type">in</property>
<property name="min_content_width">300</property>
<property name="min_content_height">250</property>
<child> <child>
<object class="GtkTreeView" id="treeview4"> <object class="GtkTreeView" id="treeview4">
<property name="visible">True</property> <property name="visible">True</property>

View File

@ -9,3 +9,11 @@ def format_size(size):
else: else:
size_string = '%.2f MiB' % (KiB_size / 1024) size_string = '%.2f MiB' % (KiB_size / 1024)
return size_string 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

View File

@ -226,6 +226,61 @@ 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 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(): def do_sysupgrade():
global transaction_type global transaction_type
"""Upgrade a system like pacman -Su""" """Upgrade a system like pacman -Su"""
@ -245,12 +300,8 @@ def do_sysupgrade():
if transaction.init_transaction(): if transaction.init_transaction():
error = transaction.Sysupgrade() error = transaction.Sysupgrade()
if error: if error:
transaction.ErrorDialog.format_secondary_text(error) handle_error(error)
response = transaction.ErrorDialog.run() else:
if response:
transaction.ErrorDialog.hide()
transaction.Release()
transaction.t_lock = False
transaction.get_to_remove() transaction.get_to_remove()
transaction.get_to_add() transaction.get_to_add()
transaction.check_conflicts() transaction.check_conflicts()
@ -262,43 +313,6 @@ def do_sysupgrade():
transaction.Release() transaction.Release()
transaction.t_lock = False 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()
def choose_provides(): def choose_provides():
to_check = [] to_check = []
depends = [] depends = []
@ -311,7 +325,7 @@ def choose_provides():
break break
for target in to_check: for target in to_check:
for name in target.depends: for name in target.depends:
depends.append(name) depends.append(common.format_pkg_name(name))
for installed_pkg in transaction.handle.get_localdb().pkgcache: for installed_pkg in transaction.handle.get_localdb().pkgcache:
if installed_pkg.name in depends: if installed_pkg.name in depends:
depends.remove(installed_pkg.name) depends.remove(installed_pkg.name)
@ -320,20 +334,55 @@ def choose_provides():
if pkg.name in depends: if pkg.name in depends:
depends.remove(pkg.name) depends.remove(pkg.name)
if depends: 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 repo in transaction.handle.get_syncdbs():
for pkg in repo.pkgcache: for pkg in repo.pkgcache:
for depend in depends: for depend in depends:
for name in pkg.provides: for name in pkg.provides:
if name == depend: if common.format_pkg_name(name) == depend:
if not provides.__contains__(depend): if not provides.__contains__(depend):
provides[depend] = [] provides[depend] = []
if not pkg.name in provides.get(depend):
provides.get(depend).append(pkg.name) provides.get(depend).append(pkg.name)
if provides: if provides:
for virtualdep, liste in provides.items(): for virtualdep, liste in provides.items():
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() choose_list.clear()
for name in liste: for name in liste:
if transaction.handle.get_localdb().get_pkg(name):
choose_list.append([True, name])
else:
choose_list.append([False, name]) choose_list.append([False, name])
ChooseDialog.show_all() ChooseDialog.run()
class Handler: class Handler:
def on_MainWindow_delete_event(self, *arg): def on_MainWindow_delete_event(self, *arg):
@ -366,12 +415,8 @@ class Handler:
transaction.Remove(pkgname) transaction.Remove(pkgname)
error = transaction.Prepare() error = transaction.Prepare()
if error: if error:
transaction.ErrorDialog.format_secondary_text(error) handle_error(error)
response = transaction.ErrorDialog.run() else:
if response:
transaction.ErrorDialog.hide()
transaction.Release()
transaction.t_lock = False
transaction.get_to_remove() transaction.get_to_remove()
transaction.get_to_add() transaction.get_to_add()
set_transaction_sum() set_transaction_sum()
@ -382,18 +427,26 @@ class Handler:
transaction.Add(pkgname) transaction.Add(pkgname)
error = transaction.Prepare() error = transaction.Prepare()
if error: if error:
transaction.ErrorDialog.format_secondary_text(error) handle_error(error)
response = transaction.ErrorDialog.run() else:
if response:
transaction.ErrorDialog.hide()
transaction.Release()
transaction.t_lock = False
transaction.get_to_remove() transaction.get_to_remove()
transaction.get_to_add() transaction.get_to_add()
#choose_provides()
transaction.check_conflicts()
transaction.Release() 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() set_transaction_sum()
ConfDialog.show_all() ConfDialog.show_all()
else: else:
@ -412,7 +465,7 @@ class Handler:
def on_RefreshButton_clicked(self, *arg): def on_RefreshButton_clicked(self, *arg):
transaction.do_refresh() transaction.do_refresh()
refresh_packages_list() set_packages_list()
def on_TransCancelButton_clicked(self, *arg): def on_TransCancelButton_clicked(self, *arg):
global transaction_type global transaction_type
@ -427,6 +480,7 @@ class Handler:
ConfDialog.hide() ConfDialog.hide()
transaction.progress_label.set_text('Preparing...') transaction.progress_label.set_text('Preparing...')
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')
transaction.progress_bar.set_text('')
while Gtk.events_pending(): while Gtk.events_pending():
Gtk.main_iteration() Gtk.main_iteration()
if transaction_type == "remove": if transaction_type == "remove":
@ -434,7 +488,7 @@ class Handler:
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 == ("install" or "update"): if (transaction_type == "install") or (transaction_type == "update"):
if transaction.init_transaction(noconflicts = True, nodeps = True): if transaction.init_transaction(noconflicts = True, nodeps = True):
for pkgname in transaction.to_update: for pkgname in transaction.to_update:
transaction.Add(pkgname) transaction.Add(pkgname)
@ -444,12 +498,7 @@ class Handler:
transaction.Remove(pkgname) transaction.Remove(pkgname)
error = transaction.Prepare() error = transaction.Prepare()
if error: if error:
transaction.ErrorDialog.format_secondary_text(error) handle_error(error)
response = transaction.ErrorDialog.run()
if response:
transaction.ErrorDialog.hide()
transaction.Release()
transaction.t_lock = False
else: else:
transaction.ProgressWindow.show_all() transaction.ProgressWindow.show_all()
while Gtk.events_pending(): while Gtk.events_pending():
@ -543,23 +592,18 @@ class Handler:
line = 0 line = 0
while line < len(choose_list): while line < len(choose_list):
if choose_list[line][0] is True: if choose_list[line][0] is True:
transaction.to_add.append(snap_list[line][1]) if not choose_list[line][1] in transaction.to_add:
elif choose_list[line][0] in transaction.to_add: if not transaction.handle.get_localdb().get_pkg(choose_list[line][1]):
transaction.to_add.remove(snap_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 line += 1
print(transaction.to_add)
def main(): def main():
interface.connect_signals(Handler()) interface.connect_signals(Handler())
transaction.do_refresh() 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(): while Gtk.events_pending():
Gtk.main_iteration() Gtk.main_iteration()
@ -567,4 +611,3 @@ def main():
if __name__ == "__main__": if __name__ == "__main__":
main() main()
Gtk.main() Gtk.main()

View File

@ -7,7 +7,7 @@ import pyalpm
import dbus import dbus
from dbus.mainloop.glib import DBusGMainLoop from dbus.mainloop.glib import DBusGMainLoop
from pamac import config from pamac import config, common
interface = Gtk.Builder() interface = Gtk.Builder()
interface.add_from_file('/usr/share/pamac/gui/dialogs.glade') interface.add_from_file('/usr/share/pamac/gui/dialogs.glade')
@ -105,29 +105,29 @@ def check_conflicts():
installed_pkg_name.append(installed_pkg.name) installed_pkg_name.append(installed_pkg.name)
for target in to_check: for target in to_check:
for name in target.replaces: for name in target.replaces:
if name in installed_pkg_name: if common.format_pkg_name(name) in installed_pkg_name:
if not name in to_remove: if not common.format_pkg_name(name) in to_remove:
to_remove.append(name) to_remove.append(common.format_pkg_name(name))
if warning: if warning:
warning = warning+'\n' warning = warning+'\n'
warning = warning+name+' will be replaced by '+target.name warning = warning+name+' will be replaced by '+target.name
for name in target.conflicts: for name in target.conflicts:
if name in to_add: if common.format_pkg_name(name) in to_add:
to_add.remove(name) to_add.remove(common.format_pkg_name(name))
to_add.remove(target.name) to_add.remove(target.name)
if warning: if warning:
warning = warning+'\n' warning = warning+'\n'
warning = warning+name+' conflicts with '+target.name+'\nNone of them will be installed' warning = warning+name+' conflicts with '+target.name+'\nNone of them will be installed'
if name in installed_pkg_name: if common.format_pkg_name(name) in installed_pkg_name:
if not name in to_remove: if not common.format_pkg_name(name) in to_remove:
to_remove.append(name) to_remove.append(common.format_pkg_name(name))
if warning: if warning:
warning = warning+'\n' warning = warning+'\n'
warning = warning+name+' conflicts with '+target.name warning = warning+name+' conflicts with '+target.name
for installed_pkg in handle.get_localdb().pkgcache: for installed_pkg in handle.get_localdb().pkgcache:
for name in installed_pkg.conflicts: for name in installed_pkg.conflicts:
if name == target.name: if common.format_pkg_name(name) == target.name:
if not name in to_remove: if not common.format_pkg_name(name) in to_remove:
to_remove.append(installed_pkg.name) to_remove.append(installed_pkg.name)
if warning: if warning:
warning = warning+'\n' warning = warning+'\n'
@ -135,12 +135,12 @@ def check_conflicts():
for repo in handle.get_syncdbs(): for repo in handle.get_syncdbs():
for pkg in repo.pkgcache: for pkg in repo.pkgcache:
for name in pkg.replaces: for name in pkg.replaces:
if name in installed_pkg_name: if common.format_pkg_name(name) in installed_pkg_name:
if not name in to_remove: if not common.format_pkg_name(name) in to_remove:
to_remove.append(name) to_remove.append(common.format_pkg_name(name))
if warning: if warning:
warning = warning+'\n' 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: if not pkg.name in to_add:
to_add.append(pkg.name) to_add.append(pkg.name)
if warning: if warning:

View File

@ -13,6 +13,7 @@ for repo in config.handle.get_syncdbs():
for pkg in syncpkgs.values(): for pkg in syncpkgs.values():
for name in pkg.depends: for name in pkg.depends:
if (not name in syncpkgs.keys()) and (not '>' in name) and (not '<' in name) and (not '=' in name): 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): if not virtualdeps.__contains__(name):
virtualdeps[name] = [] virtualdeps[name] = []
virtualdeps.get(name).append(pkg.name) virtualdeps.get(name).append(pkg.name)