incredibily improve check conflicts
This commit is contained in:
parent
ed8deca51a
commit
5741cf9f5e
@ -17,3 +17,4 @@ def format_pkg_name(name):
|
||||
if index != -1:
|
||||
name = name[0:index]
|
||||
return name
|
||||
|
||||
|
290
pamac/manager.py
290
pamac/manager.py
@ -4,6 +4,7 @@
|
||||
from gi.repository import Gtk
|
||||
|
||||
import pyalpm
|
||||
from collections import OrderedDict
|
||||
from time import strftime, localtime
|
||||
|
||||
from pamac import config, common, transaction
|
||||
@ -35,7 +36,6 @@ installed_column.set_sort_column_id(1)
|
||||
name_column.set_sort_column_id(0)
|
||||
|
||||
transaction.get_handle()
|
||||
|
||||
tmp_list = []
|
||||
for repo in transaction.handle.get_syncdbs():
|
||||
for name, pkgs in repo.grpcache:
|
||||
@ -128,7 +128,6 @@ def refresh_packages_list():
|
||||
|
||||
def set_packages_list():
|
||||
global list_dict
|
||||
transaction.get_handle()
|
||||
if list_dict == "search":
|
||||
search_strings_list = search_entry.get_text().split()
|
||||
set_list_dict_search(*search_strings_list)
|
||||
@ -242,6 +241,7 @@ def handle_error(error):
|
||||
transaction.to_remove = []
|
||||
transaction_dict.clear()
|
||||
transaction_type = None
|
||||
transaction.get_handle()
|
||||
set_packages_list()
|
||||
print('error',error)
|
||||
|
||||
@ -253,26 +253,24 @@ def handle_reply(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.get_handle()
|
||||
if (transaction_type == "install") or (transaction_type == "remove"):
|
||||
transaction_type = None
|
||||
set_packages_list()
|
||||
else:
|
||||
transaction_type = None
|
||||
if transaction.get_updates():
|
||||
do_sysupgrade()
|
||||
do_syncfirst, updates = transaction.get_updates()
|
||||
if updates:
|
||||
do_sysupgrade(do_syncfirst, updates)
|
||||
|
||||
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...')
|
||||
@ -282,112 +280,183 @@ def do_refresh():
|
||||
Gtk.main_iteration()
|
||||
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
|
||||
"""Upgrade a system like pacman -Su"""
|
||||
if transaction.t_lock is False:
|
||||
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):
|
||||
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()
|
||||
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.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 choose_provides():
|
||||
to_check = []
|
||||
depends = []
|
||||
provides = {}
|
||||
already_provided = False
|
||||
if transaction.init_transaction(noconflicts = True):
|
||||
error = transaction.Sysupgrade()
|
||||
if error:
|
||||
handle_error(error)
|
||||
else:
|
||||
for pkgname in transaction.to_add:
|
||||
for repo in transaction.handle.get_syncdbs():
|
||||
pkg = repo.get_pkg(pkgname)
|
||||
if pkg:
|
||||
to_check.append(pkg)
|
||||
break
|
||||
for target in to_check:
|
||||
for name in target.depends:
|
||||
depends.append(name)
|
||||
for installed_pkg in transaction.handle.get_localdb().pkgcache:
|
||||
if installed_pkg.name in depends:
|
||||
depends.remove(installed_pkg.name)
|
||||
for repo in transaction.handle.get_syncdbs():
|
||||
for pkg in repo.pkgcache:
|
||||
if pkg.name in depends:
|
||||
depends.remove(pkg.name)
|
||||
if depends:
|
||||
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 not provides.__contains__(depend):
|
||||
provides[depend] = []
|
||||
if not pkg.name in provides.get(depend):
|
||||
provides.get(depend).append(pkg.name)
|
||||
if provides:
|
||||
for virtualdep, liste in provides.items():
|
||||
if ('-module' in virtualdep) or ('linux' in virtualdep):
|
||||
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()
|
||||
ConfDialog.show_all()
|
||||
|
||||
def check_conflicts(pkg_list):
|
||||
#~ global to_add
|
||||
#~ global to_remove
|
||||
#~ global to_provide
|
||||
depends = [pkg_list]
|
||||
warning = ''
|
||||
#transaction.get_handle()
|
||||
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:
|
||||
i = 0
|
||||
while depends[i]:
|
||||
depends.append([])
|
||||
for pkg in depends[i]:
|
||||
for depend in pkg.depends:
|
||||
provide = pyalpm.find_satisfier(transaction.localpkgs.values(), depend)
|
||||
if provide:
|
||||
print(i,'local',provide)
|
||||
if provide.name != common.format_pkg_name(depend):
|
||||
if ('linux' in depend) or ('-module' in depend):
|
||||
for pkg in transaction.syncpkgs.values():
|
||||
if not pkg.name in transaction.localpkgs.keys():
|
||||
for name in pkg.provides:
|
||||
for linux in installed_linux:
|
||||
if not transaction.handle.get_localdb().get_pkg(name):
|
||||
if linux in name:
|
||||
transaction.to_add.append(name)
|
||||
already_provided = True
|
||||
for installed_pkg in transaction.handle.get_localdb().pkgcache:
|
||||
for name in installed_pkg.provides:
|
||||
if name == virtualdep:
|
||||
already_provided = True
|
||||
if already_provided:
|
||||
pass
|
||||
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:
|
||||
choose_label.set_markup('<b>{} is provided by {} packages.\nPlease choose the one(s) you want to install:</b>'.format(virtualdep,str(len(liste))))
|
||||
provide = pyalpm.find_satisfier(transaction.syncpkgs.values(), depend)
|
||||
if provide:
|
||||
print(i,'sync',provide)
|
||||
if provide.name != common.format_pkg_name(depend):
|
||||
if ('linux' in depend) or ('-module' in depend):
|
||||
for pkg in transaction.syncpkgs.values():
|
||||
if not pkg.name in transaction.localpkgs.keys():
|
||||
for name in pkg.provides:
|
||||
for linux in installed_linux:
|
||||
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:
|
||||
to_add_to_depends = choose_provides(depend)
|
||||
print(to_add_to_depends)
|
||||
for pkg in to_add_to_depends:
|
||||
depends[i+1].append(pkg)
|
||||
transaction.to_add.append(pkg.name)
|
||||
else:
|
||||
depends[i+1].append(provide)
|
||||
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.to_remove:
|
||||
transaction.to_remove.append(provide.name)
|
||||
if warning:
|
||||
warning = warning+'\n'
|
||||
warning = warning+provide.name+' will be replaced by '+pkg.name
|
||||
for conflict in pkg.conflicts:
|
||||
provide = pyalpm.find_satisfier(transaction.localpkgs.values(), conflict)
|
||||
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 liste:
|
||||
for name in provides.keys():
|
||||
if transaction.handle.get_localdb().get_pkg(name):
|
||||
choose_list.append([True, name])
|
||||
else:
|
||||
choose_list.append([False, name])
|
||||
ChooseDialog.run()
|
||||
return [provides[pkgname] for pkgname in transaction.to_provide]
|
||||
|
||||
class Handler:
|
||||
def on_MainWindow_delete_event(self, *arg):
|
||||
@ -427,19 +496,12 @@ class Handler:
|
||||
set_transaction_sum()
|
||||
ConfDialog.show_all()
|
||||
if transaction_type is "install":
|
||||
if transaction.init_transaction(noconflicts = True):
|
||||
transaction.to_add = []
|
||||
for pkgname in transaction_dict.keys():
|
||||
transaction.Add(pkgname)
|
||||
error = transaction.Prepare()
|
||||
if error:
|
||||
handle_error(error)
|
||||
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):
|
||||
transaction.to_add.append(pkgname)
|
||||
transaction.to_remove = []
|
||||
check_conflicts(transaction_dict.values())
|
||||
if transaction.to_add:
|
||||
if transaction.init_transaction(noconflicts = True):
|
||||
for pkgname in transaction.to_add:
|
||||
transaction.Add(pkgname)
|
||||
@ -451,18 +513,14 @@ class Handler:
|
||||
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:
|
||||
transaction.WarningDialog.format_secondary_text('Nothing to do due to packages conflicts')
|
||||
transaction.WarningDialog.format_secondary_text('Nothing to do')
|
||||
response = transaction.WarningDialog.run()
|
||||
if response:
|
||||
transaction.WarningDialog.hide()
|
||||
transaction.t_lock = False
|
||||
else:
|
||||
transaction.t_lock = False
|
||||
|
||||
def on_EraseButton_clicked(self, *arg):
|
||||
global transaction_type
|
||||
@ -473,7 +531,7 @@ class Handler:
|
||||
refresh_packages_list()
|
||||
|
||||
def on_RefreshButton_clicked(self, *arg):
|
||||
transaction.do_refresh()
|
||||
do_refresh()
|
||||
set_packages_list()
|
||||
|
||||
def on_TransCancelButton_clicked(self, *arg):
|
||||
@ -490,25 +548,6 @@ class Handler:
|
||||
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":
|
||||
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()
|
||||
@ -599,14 +638,15 @@ class Handler:
|
||||
def on_ChooseButton_clicked(self, *arg):
|
||||
ChooseDialog.hide()
|
||||
line = 0
|
||||
transaction.to_provide = []
|
||||
while line < len(choose_list):
|
||||
if choose_list[line][0] is True:
|
||||
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 not choose_list[line][1] in transaction.to_provide:
|
||||
if not choose_list[line][1] in transaction.localpkgs.keys():
|
||||
transaction.to_provide.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])
|
||||
if choose_list[line][1] in transaction.to_provide:
|
||||
transaction.to_provide.remove(choose_list[line][1])
|
||||
line += 1
|
||||
|
||||
def main():
|
||||
|
@ -198,6 +198,7 @@ class PamacDBusService(dbus.service.Object):
|
||||
error = ''
|
||||
try:
|
||||
t.sysupgrade(downgrade=False)
|
||||
print('to_upgrade:',t.to_add)
|
||||
except pyalpm.error:
|
||||
error = traceback.format_exc()
|
||||
finally:
|
||||
|
@ -4,6 +4,7 @@
|
||||
from gi.repository import Gtk
|
||||
|
||||
import pyalpm
|
||||
from collections import OrderedDict
|
||||
import dbus
|
||||
from dbus.mainloop.glib import DBusGMainLoop
|
||||
|
||||
@ -22,16 +23,29 @@ action_icon = interface.get_object('action_icon')
|
||||
ProgressCancelButton = interface.get_object('ProgressCancelButton')
|
||||
|
||||
t_lock = False
|
||||
do_syncfirst = False
|
||||
list_first = []
|
||||
to_remove = []
|
||||
to_add = []
|
||||
to_provide = []
|
||||
to_update = []
|
||||
handle = None
|
||||
syncpkgs = OrderedDict()
|
||||
localpkgs = OrderedDict()
|
||||
|
||||
def get_handle():
|
||||
global handle
|
||||
global syncpkgs
|
||||
global localpkgs
|
||||
syncpkgs = OrderedDict()
|
||||
localpkgs = OrderedDict()
|
||||
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)
|
||||
bus = dbus.SystemBus()
|
||||
@ -88,69 +102,6 @@ def init_transaction(**options):
|
||||
ErrorDialog.hide()
|
||||
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():
|
||||
global to_remove
|
||||
to_remove = To_Remove()
|
||||
@ -161,30 +112,31 @@ def get_to_add():
|
||||
|
||||
def get_updates():
|
||||
"""Return a list of package objects in local db which can be updated"""
|
||||
global do_syncfirst
|
||||
global list_first
|
||||
get_handle()
|
||||
do_syncfirst = False
|
||||
list_first = []
|
||||
#get_handle()
|
||||
if config.syncfirst:
|
||||
for name in config.syncfirst:
|
||||
pkg = handle.get_localdb().get_pkg(name)
|
||||
if pkg:
|
||||
candidate = pyalpm.sync_newversion(pkg, handle.get_syncdbs())
|
||||
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:
|
||||
do_syncfirst = True
|
||||
return list_first
|
||||
return do_syncfirst, list_first
|
||||
result = []
|
||||
installed_pkglist = handle.get_localdb().pkgcache
|
||||
for pkg in installed_pkglist:
|
||||
candidate = pyalpm.sync_newversion(pkg, handle.get_syncdbs())
|
||||
if candidate:
|
||||
result.append(candidate)
|
||||
return result
|
||||
|
||||
def get_new_version_available(pkgname):
|
||||
for repo in handle.get_syncdbs():
|
||||
pkg = repo.get_pkg(pkgname)
|
||||
if pkg is not None:
|
||||
return pkg.version
|
||||
pkg = repo.get_pkg(candidate.name)
|
||||
if pkg:
|
||||
result.append(pkg)
|
||||
break
|
||||
return do_syncfirst, result
|
||||
|
161
test.py
161
test.py
@ -4,17 +4,28 @@
|
||||
import pyalpm
|
||||
from pamac import config, common
|
||||
from collections import OrderedDict
|
||||
syncpkgs = OrderedDict()
|
||||
localpkgs = OrderedDict()
|
||||
virtualdeps = {}
|
||||
#~ syncpkgs = OrderedDict()
|
||||
#~ localpkgs = OrderedDict()
|
||||
#~ virtualdeps = {}
|
||||
|
||||
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
|
||||
class MyOrderedDict(OrderedDict):
|
||||
def keys(self):
|
||||
return [i for i in self]
|
||||
def values(self):
|
||||
return [self[i] for i in self]
|
||||
|
||||
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 name in pkg.depends:
|
||||
#~ 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.get(name).append(pkg.name)
|
||||
|
||||
to_add = ['libreoffice-writer', 'anjuta']
|
||||
depends = [[syncpkgs['libreoffice-writer'],syncpkgs['anjuta']]]
|
||||
to_provide = []
|
||||
to_remove = []
|
||||
warning = ''
|
||||
i = 0
|
||||
while depends[i]:
|
||||
depends.append([])
|
||||
for pkg in depends[i]:
|
||||
for depend in pkg.depends:
|
||||
provide = pyalpm.find_satisfier(localpkgs.values(), depend)
|
||||
if provide:
|
||||
print(i,'local',provide)
|
||||
if provide.name != common.format_pkg_name(depend):
|
||||
if ('-module' in depend) or ('linux' in depend):
|
||||
to_provide.append(depend)
|
||||
else:
|
||||
provide = pyalpm.find_satisfier(syncpkgs.values(), depend)
|
||||
if provide:
|
||||
print(i,'sync',provide)
|
||||
if provide.name != common.format_pkg_name(depend):
|
||||
print(provide.name,common.format_pkg_name(depend))
|
||||
to_provide.append(depend)
|
||||
else:
|
||||
depends[i+1].append(provide)
|
||||
for replace in pkg.replaces:
|
||||
provide = pyalpm.find_satisfier(localpkgs.values(), replace)
|
||||
if provide:
|
||||
if not provide.name in to_remove:
|
||||
to_remove.append(provide.name)
|
||||
if warning:
|
||||
warning = warning+'\n'
|
||||
warning = warning+provide.name+' will be replaced by '+pkg.name
|
||||
for conflict in pkg.conflicts:
|
||||
provide = pyalpm.find_satisfier(localpkgs.values(), conflict)
|
||||
if provide:
|
||||
if not provide.name in to_remove:
|
||||
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 to_remove:
|
||||
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(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 = i + 1
|
||||
for pkg in localpkgs.values():
|
||||
for conflict in pkg.conflicts:
|
||||
provide = pyalpm.find_satisfier(depends[0], conflict)
|
||||
if provide:
|
||||
if not provide.name in to_remove:
|
||||
to_remove.append(pkg.name)
|
||||
if warning:
|
||||
warning = warning+'\n'
|
||||
warning = warning+provide.name+' conflicts with '+pkg.name
|
||||
print('depends:',depends)
|
||||
print('to provide:',to_provide)
|
||||
print('to add:',to_add)
|
||||
print('to remove:',to_remove)
|
||||
print(warning)
|
||||
#~ to_add = ['libreoffice-writer', 'anjuta']
|
||||
#~ depends = [[syncpkgs['libreoffice-writer'],syncpkgs['anjuta']]]
|
||||
#~ to_provide = []
|
||||
#~ to_remove = []
|
||||
#~ warning = ''
|
||||
#~ i = 0
|
||||
#~ while depends[i]:
|
||||
#~ depends.append([])
|
||||
#~ for pkg in depends[i]:
|
||||
#~ for depend in pkg.depends:
|
||||
#~ provide = pyalpm.find_satisfier(localpkgs.values(), depend)
|
||||
#~ if provide:
|
||||
#~ print(i,'local',provide)
|
||||
#~ if provide.name != common.format_pkg_name(depend):
|
||||
#~ if ('-module' in depend) or ('linux' in depend):
|
||||
#~ to_provide.append(depend)
|
||||
#~ else:
|
||||
#~ provide = pyalpm.find_satisfier(syncpkgs.values(), depend)
|
||||
#~ if provide:
|
||||
#~ print(i,'sync',provide)
|
||||
#~ if provide.name != common.format_pkg_name(depend):
|
||||
#~ print(provide.name,common.format_pkg_name(depend))
|
||||
#~ to_provide.append(depend)
|
||||
#~ else:
|
||||
#~ depends[i+1].append(provide)
|
||||
#~ for replace in pkg.replaces:
|
||||
#~ provide = pyalpm.find_satisfier(localpkgs.values(), replace)
|
||||
#~ if provide:
|
||||
#~ if not provide.name in to_remove:
|
||||
#~ to_remove.append(provide.name)
|
||||
#~ if warning:
|
||||
#~ warning = warning+'\n'
|
||||
#~ warning = warning+provide.name+' will be replaced by '+pkg.name
|
||||
#~ for conflict in pkg.conflicts:
|
||||
#~ provide = pyalpm.find_satisfier(localpkgs.values(), conflict)
|
||||
#~ if provide:
|
||||
#~ if not provide.name in to_remove:
|
||||
#~ 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 to_remove:
|
||||
#~ 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(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 = i + 1
|
||||
#~ for pkg in localpkgs.values():
|
||||
#~ for conflict in pkg.conflicts:
|
||||
#~ provide = pyalpm.find_satisfier(depends[0], conflict)
|
||||
#~ if provide:
|
||||
#~ if not provide.name in to_remove:
|
||||
#~ to_remove.append(pkg.name)
|
||||
#~ if warning:
|
||||
#~ warning = warning+'\n'
|
||||
#~ warning = warning+provide.name+' conflicts with '+pkg.name
|
||||
#~ print('depends:',depends)
|
||||
#~ print('to provide:',to_provide)
|
||||
#~ print('to add:',to_add)
|
||||
#~ print('to remove:',to_remove)
|
||||
#~ print(warning)
|
||||
|
Loading…
Reference in New Issue
Block a user