incredibily improve check conflicts

This commit is contained in:
guinux 2013-02-06 16:09:43 +01:00
parent ed8deca51a
commit 5741cf9f5e
5 changed files with 306 additions and 301 deletions

View File

@ -17,3 +17,4 @@ def format_pkg_name(name):
if index != -1: if index != -1:
name = name[0:index] name = name[0:index]
return name return name

View File

@ -4,6 +4,7 @@
from gi.repository import Gtk from gi.repository import Gtk
import pyalpm import pyalpm
from collections import OrderedDict
from time import strftime, localtime from time import strftime, localtime
from pamac import config, common, transaction from pamac import config, common, transaction
@ -35,7 +36,6 @@ installed_column.set_sort_column_id(1)
name_column.set_sort_column_id(0) name_column.set_sort_column_id(0)
transaction.get_handle() transaction.get_handle()
tmp_list = [] tmp_list = []
for repo in transaction.handle.get_syncdbs(): for repo in transaction.handle.get_syncdbs():
for name, pkgs in repo.grpcache: for name, pkgs in repo.grpcache:
@ -128,7 +128,6 @@ def refresh_packages_list():
def set_packages_list(): def set_packages_list():
global list_dict global list_dict
transaction.get_handle()
if list_dict == "search": if list_dict == "search":
search_strings_list = search_entry.get_text().split() search_strings_list = search_entry.get_text().split()
set_list_dict_search(*search_strings_list) set_list_dict_search(*search_strings_list)
@ -242,6 +241,7 @@ def handle_error(error):
transaction.to_remove = [] transaction.to_remove = []
transaction_dict.clear() transaction_dict.clear()
transaction_type = None transaction_type = None
transaction.get_handle()
set_packages_list() set_packages_list()
print('error',error) print('error',error)
@ -253,26 +253,24 @@ 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()
transaction.to_add = [] transaction.to_add = []
transaction.to_remove = [] transaction.to_remove = []
transaction_dict.clear() transaction_dict.clear()
transaction.get_handle()
if (transaction_type == "install") or (transaction_type == "remove"): if (transaction_type == "install") or (transaction_type == "remove"):
transaction_type = None transaction_type = None
set_packages_list() set_packages_list()
else: else:
transaction_type = None transaction_type = None
if transaction.get_updates(): do_syncfirst, updates = transaction.get_updates()
do_sysupgrade() if updates:
do_sysupgrade(do_syncfirst, updates)
def do_refresh(): def do_refresh():
"""Sync databases like pacman -Sy""" """Sync databases like pacman -Sy"""
transaction.get_handle()
if transaction.t_lock is False: if transaction.t_lock is False:
transaction.t_lock = True transaction.t_lock = True
transaction.progress_label.set_text('Refreshing...') transaction.progress_label.set_text('Refreshing...')
@ -282,112 +280,183 @@ def do_refresh():
Gtk.main_iteration() 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 do_sysupgrade(): def do_sysupgrade(do_syncfirst, updates_list):
global transaction_type global transaction_type
"""Upgrade a system like pacman -Su""" """Upgrade a system like pacman -Su"""
if transaction.t_lock is False: if transaction.t_lock is False:
transaction_type = "update" transaction_type = "update"
if transaction.do_syncfirst is True: do_syncfirst, updates = transaction.get_updates()
if updates:
transaction.to_add = []
transaction.to_remove = []
check_conflicts(updates)
if do_syncfirst is True:
for pkg in updates:
transaction.to_add.append(pkg.name)
if transaction.init_transaction(recurse = True): if transaction.init_transaction(recurse = True):
for pkg in transaction.list_first: for pkgname in transaction.to_add:
transaction.Add(pkg.name) transaction.Add(pkgname)
transaction.get_to_remove() for pkgname in transaction.to_remove:
transaction.get_to_add() transaction.Remove(pkgname)
transaction.check_conflicts() error = transaction.Prepare()
transaction.Release()
set_transaction_sum()
ConfDialog.show_all()
else:
if transaction.init_transaction():
error = transaction.Sysupgrade()
if error: if error:
handle_error(error) handle_error(error)
else: else:
transaction.get_to_remove() transaction.get_to_remove()
transaction.get_to_add() transaction.get_to_add()
transaction.check_conflicts() set_transaction_sum()
transaction.Release() ConfDialog.show_all()
if len(transaction.to_add) + len(transaction.to_update) + len(transaction.to_remove) != 0: else:
if transaction.init_transaction(noconflicts = True):
error = transaction.Sysupgrade()
if error:
handle_error(error)
else:
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()
set_transaction_sum() set_transaction_sum()
ConfDialog.show_all() ConfDialog.show_all()
else:
transaction.Release()
transaction.t_lock = False
def choose_provides(): def check_conflicts(pkg_list):
to_check = [] #~ global to_add
depends = [] #~ global to_remove
provides = {} #~ global to_provide
already_provided = False depends = [pkg_list]
for pkgname in transaction.to_add: warning = ''
for repo in transaction.handle.get_syncdbs(): #transaction.get_handle()
pkg = repo.get_pkg(pkgname) pkgs = transaction.handle.get_localdb().search('linux3')
if pkg: installed_linux = []
to_check.append(pkg) for i in pkgs:
break if len(i.name) == 7:
for target in to_check: installed_linux.append(i.name)
for name in target.depends: for to_install in transaction.to_add:
depends.append(name) if 'linux3' in to_install:
for installed_pkg in transaction.handle.get_localdb().pkgcache: if len(to_install) == 7:
if installed_pkg.name in depends: installed_linux.append(to_install)
depends.remove(installed_pkg.name) i = 0
for repo in transaction.handle.get_syncdbs(): while depends[i]:
for pkg in repo.pkgcache: depends.append([])
if pkg.name in depends: for pkg in depends[i]:
depends.remove(pkg.name) for depend in pkg.depends:
if depends: provide = pyalpm.find_satisfier(transaction.localpkgs.values(), depend)
for repo in transaction.handle.get_syncdbs(): if provide:
for pkg in repo.pkgcache: print(i,'local',provide)
for depend in depends: if provide.name != common.format_pkg_name(depend):
for name in pkg.provides: if ('linux' in depend) or ('-module' in depend):
if name == depend: for pkg in transaction.syncpkgs.values():
if not provides.__contains__(depend): if not pkg.name in transaction.localpkgs.keys():
provides[depend] = [] for name in pkg.provides:
if not pkg.name in provides.get(depend): for linux in installed_linux:
provides.get(depend).append(pkg.name) if linux in pkg.name:
if provides: if common.format_pkg_name(depend) == common.format_pkg_name(name):
for virtualdep, liste in provides.items(): depends[i+1].append(pkg)
if ('-module' in virtualdep) or ('linux' in virtualdep): transaction.to_add.append(pkg.name)
pkgs = transaction.handle.get_localdb().search('linux3') else:
installed_linux = [] provide = pyalpm.find_satisfier(transaction.syncpkgs.values(), depend)
to_remove_from_add = [] if provide:
for i in pkgs: print(i,'sync',provide)
if len(i.name) == 7: if provide.name != common.format_pkg_name(depend):
installed_linux.append(i.name) if ('linux' in depend) or ('-module' in depend):
for to_install in transaction.to_add: for pkg in transaction.syncpkgs.values():
if 'linux3' in to_install: if not pkg.name in transaction.localpkgs.keys():
if len(to_install) == 7: for name in pkg.provides:
if to_install in transaction_dict.keys(): for linux in installed_linux:
installed_linux.append(to_install) if linux in pkg.name:
if common.format_pkg_name(depend) == common.format_pkg_name(name):
depends[i+1].append(pkg)
transaction.to_add.append(pkg.name)
else: else:
to_remove_from_add.append(to_install) to_add_to_depends = choose_provides(depend)
for name in liste: print(to_add_to_depends)
if name == to_install: for pkg in to_add_to_depends:
if not to_install in transaction_dict.keys(): depends[i+1].append(pkg)
to_remove_from_add.append(to_install) transaction.to_add.append(pkg.name)
for to_remove in to_remove_from_add: else:
transaction.to_add.remove(to_remove) depends[i+1].append(provide)
for name in liste: for replace in pkg.replaces:
for linux in installed_linux: provide = pyalpm.find_satisfier(transaction.localpkgs.values(), replace)
if not transaction.handle.get_localdb().get_pkg(name): if provide:
if linux in name: if provide.name != pkg.name:
transaction.to_add.append(name) if not provide.name in transaction.to_remove:
already_provided = True transaction.to_remove.append(provide.name)
for installed_pkg in transaction.handle.get_localdb().pkgcache: if warning:
for name in installed_pkg.provides: warning = warning+'\n'
if name == virtualdep: warning = warning+provide.name+' will be replaced by '+pkg.name
already_provided = True for conflict in pkg.conflicts:
if already_provided: provide = pyalpm.find_satisfier(transaction.localpkgs.values(), conflict)
pass if provide:
if provide.name != pkg.name:
if not provide.name in transaction.to_remove:
transaction.to_remove.append(provide.name)
if warning:
warning = warning+'\n'
warning = warning+pkg.name+' conflicts with '+provide.name
provide = pyalpm.find_satisfier(depends[0], conflict)
if provide:
if not common.format_pkg_name(conflict) in transaction.to_remove:
if pkg.name in transaction.to_add and common.format_pkg_name(conflict) in transaction.to_add:
transaction.to_add.remove(common.format_pkg_name(conflict))
transaction.to_add.remove(pkg.name)
if warning:
warning = warning+'\n'
warning = warning+pkg.name+' conflicts with '+common.format_pkg_name(conflict)+'\nNone of them will be installed'
i += 1
for pkg in transaction.localpkgs.values():
for conflict in pkg.conflicts:
provide = pyalpm.find_satisfier(depends[0], conflict)
if provide:
if provide.name != pkg.name:
if not provide.name in transaction.to_remove:
transaction.to_remove.append(pkg.name)
if warning:
warning = warning+'\n'
warning = warning+provide.name+' conflicts with '+pkg.name
for pkg in transaction.syncpkgs.values():
for replace in pkg.replaces:
provide = pyalpm.find_satisfier(transaction.localpkgs.values(), replace)
if provide:
if provide.name != pkg.name:
if not provide.name in transaction.localpkgs.keys():
if not provide.name in transaction.to_remove:
transaction.to_remove.append(provide.name)
if warning:
warning = warning+'\n'
warning = warning+provide.name+' will be replaced by '+pkg.name
if not pkg.name in transaction.to_add:
transaction.to_add.append(pkg.name)
print(transaction.to_add,transaction.to_remove)
if warning:
transaction.WarningDialog.format_secondary_text(warning)
response = transaction.WarningDialog.run()
if response:
transaction.WarningDialog.hide()
def choose_provides(name):
provides = OrderedDict()
already_add = []
for pkg in transaction.syncpkgs.values():
for provide in pkg.provides:
if common.format_pkg_name(name) == common.format_pkg_name(provide):
if not pkg.name in provides.keys():
provides[pkg.name] = pkg
if provides:
choose_label.set_markup('<b>{} is provided by {} packages.\nPlease choose the one(s) you want to install:</b>'.format(name,str(len(provides.keys()))))
choose_list.clear()
for name in provides.keys():
if transaction.handle.get_localdb().get_pkg(name):
choose_list.append([True, name])
else: else:
choose_label.set_markup('<b>{} is provided by {} packages.\nPlease choose the one(s) you want to install:</b>'.format(virtualdep,str(len(liste)))) choose_list.append([False, name])
choose_list.clear() ChooseDialog.run()
for name in liste: return [provides[pkgname] for pkgname in transaction.to_provide]
if transaction.handle.get_localdb().get_pkg(name):
choose_list.append([True, name])
else:
choose_list.append([False, name])
ChooseDialog.run()
class Handler: class Handler:
def on_MainWindow_delete_event(self, *arg): def on_MainWindow_delete_event(self, *arg):
@ -427,19 +496,12 @@ class Handler:
set_transaction_sum() set_transaction_sum()
ConfDialog.show_all() ConfDialog.show_all()
if transaction_type is "install": if transaction_type is "install":
if transaction.init_transaction(noconflicts = True): transaction.to_add = []
for pkgname in transaction_dict.keys(): for pkgname in transaction_dict.keys():
transaction.Add(pkgname) transaction.to_add.append(pkgname)
error = transaction.Prepare() transaction.to_remove = []
if error: check_conflicts(transaction_dict.values())
handle_error(error) if transaction.to_add:
else:
transaction.get_to_remove()
transaction.get_to_add()
transaction.Release()
choose_provides()
transaction.check_conflicts()
if set(transaction_dict.keys()).intersection(transaction.to_add):
if transaction.init_transaction(noconflicts = True): if transaction.init_transaction(noconflicts = True):
for pkgname in transaction.to_add: for pkgname in transaction.to_add:
transaction.Add(pkgname) transaction.Add(pkgname)
@ -451,17 +513,13 @@ class Handler:
else: else:
transaction.get_to_remove() transaction.get_to_remove()
transaction.get_to_add() 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:
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
else: else:
transaction.WarningDialog.format_secondary_text('Nothing to do')
response = transaction.WarningDialog.run()
if response:
transaction.WarningDialog.hide()
transaction.t_lock = False transaction.t_lock = False
def on_EraseButton_clicked(self, *arg): def on_EraseButton_clicked(self, *arg):
@ -473,7 +531,7 @@ class Handler:
refresh_packages_list() refresh_packages_list()
def on_RefreshButton_clicked(self, *arg): def on_RefreshButton_clicked(self, *arg):
transaction.do_refresh() do_refresh()
set_packages_list() set_packages_list()
def on_TransCancelButton_clicked(self, *arg): def on_TransCancelButton_clicked(self, *arg):
@ -490,29 +548,10 @@ class Handler:
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('') transaction.progress_bar.set_text('')
transaction.ProgressWindow.show_all()
while Gtk.events_pending(): while Gtk.events_pending():
Gtk.main_iteration() Gtk.main_iteration()
if transaction_type == "remove": transaction.Commit(reply_handler = handle_reply, error_handler = handle_error, timeout = 2000*1000)
transaction.ProgressWindow.show_all()
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 (transaction_type == "update"):
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)
error = transaction.Prepare()
if error:
handle_error(error)
else:
transaction.ProgressWindow.show_all()
while Gtk.events_pending():
Gtk.main_iteration()
transaction.Commit(reply_handler = handle_reply, error_handler = handle_error, timeout = 2000*1000)
def on_search_button_clicked(self, widget): def on_search_button_clicked(self, widget):
global list_dict global list_dict
@ -599,14 +638,15 @@ class Handler:
def on_ChooseButton_clicked(self, *arg): def on_ChooseButton_clicked(self, *arg):
ChooseDialog.hide() ChooseDialog.hide()
line = 0 line = 0
transaction.to_provide = []
while line < len(choose_list): while line < len(choose_list):
if choose_list[line][0] is True: if choose_list[line][0] is True:
if not choose_list[line][1] in transaction.to_add: if not choose_list[line][1] in transaction.to_provide:
if not transaction.handle.get_localdb().get_pkg(choose_list[line][1]): if not choose_list[line][1] in transaction.localpkgs.keys():
transaction.to_add.append(choose_list[line][1]) transaction.to_provide.append(choose_list[line][1])
if choose_list[line][0] is False: if choose_list[line][0] is False:
if choose_list[line][1] in transaction.to_add: if choose_list[line][1] in transaction.to_provide:
transaction.to_add.remove(choose_list[line][1]) transaction.to_provide.remove(choose_list[line][1])
line += 1 line += 1
def main(): def main():

View File

@ -198,6 +198,7 @@ class PamacDBusService(dbus.service.Object):
error = '' error = ''
try: try:
t.sysupgrade(downgrade=False) t.sysupgrade(downgrade=False)
print('to_upgrade:',t.to_add)
except pyalpm.error: except pyalpm.error:
error = traceback.format_exc() error = traceback.format_exc()
finally: finally:

View File

@ -4,6 +4,7 @@
from gi.repository import Gtk from gi.repository import Gtk
import pyalpm import pyalpm
from collections import OrderedDict
import dbus import dbus
from dbus.mainloop.glib import DBusGMainLoop from dbus.mainloop.glib import DBusGMainLoop
@ -22,16 +23,29 @@ action_icon = interface.get_object('action_icon')
ProgressCancelButton = interface.get_object('ProgressCancelButton') ProgressCancelButton = interface.get_object('ProgressCancelButton')
t_lock = False t_lock = False
do_syncfirst = False
list_first = []
to_remove = [] to_remove = []
to_add = [] to_add = []
to_provide = []
to_update = [] to_update = []
handle = None handle = None
syncpkgs = OrderedDict()
localpkgs = OrderedDict()
def get_handle(): def get_handle():
global handle global handle
global syncpkgs
global localpkgs
syncpkgs = OrderedDict()
localpkgs = OrderedDict()
handle = config.pacman_conf.initialize_alpm() handle = config.pacman_conf.initialize_alpm()
for repo in handle.get_syncdbs():
for pkg in repo.pkgcache:
if not pkg.name in syncpkgs.keys():
syncpkgs[pkg.name] = pkg
for pkg in handle.get_localdb().pkgcache:
if not pkg.name in localpkgs.keys():
localpkgs[pkg.name] = pkg
print('get handle')
DBusGMainLoop(set_as_default=True) DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus() bus = dbus.SystemBus()
@ -88,69 +102,6 @@ def init_transaction(**options):
ErrorDialog.hide() ErrorDialog.hide()
return False return False
def check_conflicts():
global to_add
global to_remove
to_check = []
installed_pkg_name = []
syncdbs_pkg_name = []
warning = ''
for pkgname in to_add:
for repo in handle.get_syncdbs():
pkg = repo.get_pkg(pkgname)
if pkg:
to_check.append(pkg)
break
for installed_pkg in handle.get_localdb().pkgcache:
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 warning:
warning = warning+'\n'
warning = warning+name+' will be replaced by '+target.name
for name in target.conflicts:
#if common.format_pkg_name(name) in to_add:
if name in to_add:
#to_add.remove(common.format_pkg_name(name))
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'
if name in installed_pkg_name:
if not name in to_remove:
to_remove.append(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:
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 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 warning:
warning = warning+'\n'
warning = warning+name+' will be replaced by '+pkg.name
if not pkg.name in to_add:
to_add.append(pkg.name)
if warning:
WarningDialog.format_secondary_text(warning)
response = WarningDialog.run()
if response:
WarningDialog.hide()
def get_to_remove(): def get_to_remove():
global to_remove global to_remove
to_remove = To_Remove() to_remove = To_Remove()
@ -161,30 +112,31 @@ def get_to_add():
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"""
global do_syncfirst do_syncfirst = False
global list_first list_first = []
get_handle() #get_handle()
if config.syncfirst: if config.syncfirst:
for name in config.syncfirst: for name in config.syncfirst:
pkg = handle.get_localdb().get_pkg(name) pkg = handle.get_localdb().get_pkg(name)
if pkg: if pkg:
candidate = pyalpm.sync_newversion(pkg, handle.get_syncdbs()) candidate = pyalpm.sync_newversion(pkg, handle.get_syncdbs())
if candidate: if candidate:
list_first.append(candidate) for repo in handle.get_syncdbs():
pkg = repo.get_pkg(candidate.name)
if pkg:
list_first.append(pkg)
break
if list_first: if list_first:
do_syncfirst = True do_syncfirst = True
return list_first return do_syncfirst, list_first
result = [] result = []
installed_pkglist = handle.get_localdb().pkgcache installed_pkglist = handle.get_localdb().pkgcache
for pkg in installed_pkglist: for pkg in installed_pkglist:
candidate = pyalpm.sync_newversion(pkg, handle.get_syncdbs()) candidate = pyalpm.sync_newversion(pkg, handle.get_syncdbs())
if candidate: if candidate:
result.append(candidate) for repo in handle.get_syncdbs():
return result pkg = repo.get_pkg(candidate.name)
if pkg:
def get_new_version_available(pkgname): result.append(pkg)
for repo in handle.get_syncdbs(): break
pkg = repo.get_pkg(pkgname) return do_syncfirst, result
if pkg is not None:
return pkg.version
break

161
test.py
View File

@ -4,17 +4,28 @@
import pyalpm import pyalpm
from pamac import config, common from pamac import config, common
from collections import OrderedDict from collections import OrderedDict
syncpkgs = OrderedDict() #~ syncpkgs = OrderedDict()
localpkgs = OrderedDict() #~ localpkgs = OrderedDict()
virtualdeps = {} #~ virtualdeps = {}
for repo in config.handle.get_syncdbs(): class MyOrderedDict(OrderedDict):
for pkg in repo.pkgcache: def keys(self):
if not pkg.name in syncpkgs.keys(): return [i for i in self]
syncpkgs[pkg.name] = pkg def values(self):
for pkg in config.handle.get_localdb().pkgcache: return [self[i] for i in self]
if not pkg.name in localpkgs.keys():
localpkgs[pkg.name] = pkg d=MyOrderedDict()
d['pear']=3
d['apple']=2
print(d.items())
#~ for repo in config.handle.get_syncdbs():
#~ for pkg in repo.pkgcache:
#~ if not pkg.name in syncpkgs.keys():
#~ syncpkgs[pkg.name] = pkg
#~ for pkg in config.handle.get_localdb().pkgcache:
#~ if not pkg.name in localpkgs.keys():
#~ localpkgs[pkg.name] = pkg
#~ 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):
@ -23,68 +34,68 @@ for pkg in config.handle.get_localdb().pkgcache:
#~ virtualdeps[name] = [] #~ virtualdeps[name] = []
#~ virtualdeps.get(name).append(pkg.name) #~ virtualdeps.get(name).append(pkg.name)
to_add = ['libreoffice-writer', 'anjuta'] #~ to_add = ['libreoffice-writer', 'anjuta']
depends = [[syncpkgs['libreoffice-writer'],syncpkgs['anjuta']]] #~ depends = [[syncpkgs['libreoffice-writer'],syncpkgs['anjuta']]]
to_provide = [] #~ to_provide = []
to_remove = [] #~ to_remove = []
warning = '' #~ warning = ''
i = 0 #~ i = 0
while depends[i]: #~ while depends[i]:
depends.append([]) #~ depends.append([])
for pkg in depends[i]: #~ for pkg in depends[i]:
for depend in pkg.depends: #~ for depend in pkg.depends:
provide = pyalpm.find_satisfier(localpkgs.values(), depend) #~ provide = pyalpm.find_satisfier(localpkgs.values(), depend)
if provide: #~ if provide:
print(i,'local',provide) #~ print(i,'local',provide)
if provide.name != common.format_pkg_name(depend): #~ if provide.name != common.format_pkg_name(depend):
if ('-module' in depend) or ('linux' in depend): #~ if ('-module' in depend) or ('linux' in depend):
to_provide.append(depend) #~ to_provide.append(depend)
else: #~ else:
provide = pyalpm.find_satisfier(syncpkgs.values(), depend) #~ provide = pyalpm.find_satisfier(syncpkgs.values(), depend)
if provide: #~ if provide:
print(i,'sync',provide) #~ print(i,'sync',provide)
if provide.name != common.format_pkg_name(depend): #~ if provide.name != common.format_pkg_name(depend):
print(provide.name,common.format_pkg_name(depend)) #~ print(provide.name,common.format_pkg_name(depend))
to_provide.append(depend) #~ to_provide.append(depend)
else: #~ else:
depends[i+1].append(provide) #~ depends[i+1].append(provide)
for replace in pkg.replaces: #~ for replace in pkg.replaces:
provide = pyalpm.find_satisfier(localpkgs.values(), replace) #~ provide = pyalpm.find_satisfier(localpkgs.values(), replace)
if provide: #~ if provide:
if not provide.name in to_remove: #~ if not provide.name in to_remove:
to_remove.append(provide.name) #~ to_remove.append(provide.name)
if warning: #~ if warning:
warning = warning+'\n' #~ warning = warning+'\n'
warning = warning+provide.name+' will be replaced by '+pkg.name #~ warning = warning+provide.name+' will be replaced by '+pkg.name
for conflict in pkg.conflicts: #~ for conflict in pkg.conflicts:
provide = pyalpm.find_satisfier(localpkgs.values(), conflict) #~ provide = pyalpm.find_satisfier(localpkgs.values(), conflict)
if provide: #~ if provide:
if not provide.name in to_remove: #~ if not provide.name in to_remove:
to_remove.append(provide.name) #~ to_remove.append(provide.name)
if warning: #~ if warning:
warning = warning+'\n' #~ warning = warning+'\n'
warning = warning+pkg.name+' conflicts with '+provide.name #~ warning = warning+pkg.name+' conflicts with '+provide.name
provide = pyalpm.find_satisfier(depends[0], conflict) #~ provide = pyalpm.find_satisfier(depends[0], conflict)
if provide: #~ if provide:
if not common.format_pkg_name(conflict) in to_remove: #~ if not common.format_pkg_name(conflict) in to_remove:
if pkg.name in to_add and common.format_pkg_name(conflict) in to_add: #~ if pkg.name in to_add and common.format_pkg_name(conflict) in to_add:
to_add.remove(common.format_pkg_name(conflict)) #~ to_add.remove(common.format_pkg_name(conflict))
to_add.remove(pkg.name) #~ to_add.remove(pkg.name)
if warning: #~ if warning:
warning = warning+'\n' #~ warning = warning+'\n'
warning = warning+pkg.name+' conflicts with '+common.format_pkg_name(conflict)+'\nNone of them will be installed' #~ warning = warning+pkg.name+' conflicts with '+common.format_pkg_name(conflict)+'\nNone of them will be installed'
i = i + 1 #~ i = i + 1
for pkg in localpkgs.values(): #~ for pkg in localpkgs.values():
for conflict in pkg.conflicts: #~ for conflict in pkg.conflicts:
provide = pyalpm.find_satisfier(depends[0], conflict) #~ provide = pyalpm.find_satisfier(depends[0], conflict)
if provide: #~ if provide:
if not provide.name in to_remove: #~ if not provide.name in to_remove:
to_remove.append(pkg.name) #~ to_remove.append(pkg.name)
if warning: #~ if warning:
warning = warning+'\n' #~ warning = warning+'\n'
warning = warning+provide.name+' conflicts with '+pkg.name #~ warning = warning+provide.name+' conflicts with '+pkg.name
print('depends:',depends) #~ print('depends:',depends)
print('to provide:',to_provide) #~ print('to provide:',to_provide)
print('to add:',to_add) #~ print('to add:',to_add)
print('to remove:',to_remove) #~ print('to remove:',to_remove)
print(warning) #~ print(warning)