From ed8deca51a7f17fac0882365d779f5618c3e1674 Mon Sep 17 00:00:00 2001 From: guinux Date: Sun, 3 Feb 2013 15:58:33 +0100 Subject: [PATCH] some updater fixes --- pamac/__init__.py | 0 pamac/common.py | 2 +- pamac/config.py | 0 pamac/manager.py | 10 ++--- pamac/pamac-daemon.py | 0 pamac/transaction.py | 37 ++--------------- pamac/tray.py | 0 pamac/updater.py | 23 ++++++++--- test.py | 92 +++++++++++++++++++++++++++++++++++++------ 9 files changed, 109 insertions(+), 55 deletions(-) mode change 100755 => 100644 pamac/__init__.py mode change 100755 => 100644 pamac/common.py mode change 100755 => 100644 pamac/config.py mode change 100755 => 100644 pamac/manager.py mode change 100755 => 100644 pamac/pamac-daemon.py mode change 100755 => 100644 pamac/transaction.py mode change 100755 => 100644 pamac/tray.py mode change 100755 => 100644 pamac/updater.py diff --git a/pamac/__init__.py b/pamac/__init__.py old mode 100755 new mode 100644 diff --git a/pamac/common.py b/pamac/common.py old mode 100755 new mode 100644 index 55b271d..2c49619 --- a/pamac/common.py +++ b/pamac/common.py @@ -16,4 +16,4 @@ def format_pkg_name(name): index = name.find(i) if index != -1: name = name[0:index] - return name + return name diff --git a/pamac/config.py b/pamac/config.py old mode 100755 new mode 100644 diff --git a/pamac/manager.py b/pamac/manager.py old mode 100755 new mode 100644 index 0aa9f5c..eaefa37 --- a/pamac/manager.py +++ b/pamac/manager.py @@ -327,7 +327,7 @@ def choose_provides(): break for target in to_check: for name in target.depends: - depends.append(common.format_pkg_name(name)) + depends.append(name) for installed_pkg in transaction.handle.get_localdb().pkgcache: if installed_pkg.name in depends: depends.remove(installed_pkg.name) @@ -340,7 +340,7 @@ def choose_provides(): for pkg in repo.pkgcache: for depend in depends: for name in pkg.provides: - if common.format_pkg_name(name) == depend: + if name == depend: if not provides.__contains__(depend): provides[depend] = [] if not pkg.name in provides.get(depend): @@ -375,7 +375,7 @@ def choose_provides(): already_provided = True for installed_pkg in transaction.handle.get_localdb().pkgcache: for name in installed_pkg.provides: - if common.format_pkg_name(name) == virtualdep: + if name == virtualdep: already_provided = True if already_provided: pass @@ -415,7 +415,7 @@ class Handler: print('Transaction locked') else: if transaction_type is "remove": - if transaction.init_transaction(cascade = True): + if transaction.init_transaction(cascade = True, unneeded = True): for pkgname in transaction_dict.keys(): transaction.Remove(pkgname) error = transaction.Prepare() @@ -498,7 +498,7 @@ class Handler: 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): + if transaction.init_transaction(noconflicts = True):#, nodeps = True): for pkgname in transaction.to_update: transaction.Add(pkgname) for pkgname in transaction.to_add: diff --git a/pamac/pamac-daemon.py b/pamac/pamac-daemon.py old mode 100755 new mode 100644 diff --git a/pamac/transaction.py b/pamac/transaction.py old mode 100755 new mode 100644 index 7fca769..892a437 --- a/pamac/transaction.py +++ b/pamac/transaction.py @@ -159,36 +159,6 @@ def get_to_add(): global to_add to_add = To_Add() -def do_refresh(): - """Sync databases like pacman -Sy""" - global t_lock - get_handle() - if t_lock is False: - t_lock = True - progress_label.set_text('Refreshing...') - action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/refresh-cache.png') - ProgressWindow.show_all() - while Gtk.events_pending(): - Gtk.main_iteration() - Refresh(reply_handler = handle_reply, error_handler = handle_error, timeout = 2000*1000) - -def handle_error(error): - global t_lock - if not 'DBus.Error.NoReply' in str(error): - transaction.ErrorDialog.format_secondary_text('Refresh Error:\n'+str(error)) - response = transaction.ErrorDialog.run() - if response: - transaction.ErrorDialog.hide() - t_lock = False - Release() - ProgressWindow.hide() - -def handle_reply(reply): - global t_lock - t_lock = False - Release() - ProgressWindow.hide() - def get_updates(): """Return a list of package objects in local db which can be updated""" global do_syncfirst @@ -197,9 +167,10 @@ def get_updates(): if config.syncfirst: for name in config.syncfirst: pkg = handle.get_localdb().get_pkg(name) - candidate = pyalpm.sync_newversion(pkg, handle.get_syncdbs()) - if candidate: - list_first.append(candidate) + if pkg: + candidate = pyalpm.sync_newversion(pkg, handle.get_syncdbs()) + if candidate: + list_first.append(candidate) if list_first: do_syncfirst = True return list_first diff --git a/pamac/tray.py b/pamac/tray.py old mode 100755 new mode 100644 diff --git a/pamac/updater.py b/pamac/updater.py old mode 100755 new mode 100644 index 03a3529..ca69234 --- a/pamac/updater.py +++ b/pamac/updater.py @@ -18,6 +18,18 @@ bottom_label = interface.get_object('bottom_label') update_listore = interface.get_object('update_list') update_label = interface.get_object('update_label') +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 have_updates(): available_updates = transaction.get_updates() update_listore.clear() @@ -90,11 +102,11 @@ def do_sysupgrade(): transaction.get_to_add() transaction.check_conflicts() transaction.Release() - if len(transaction.to_update) == 0: + if len(transaction.to_add) == 0: transaction.t_lock = False print("Nothing to update") else: - if transaction.init_transaction(noconflicts = True, nodeps = True): + if transaction.init_transaction(noconflicts = True): for pkgname in transaction.to_update: transaction.Add(pkgname) for pkgname in transaction.to_add: @@ -169,7 +181,7 @@ class Handler: def on_RefreshButton_clicked(self, *arg): transaction.do_refresh() - have_updates() + #have_updates() def on_TransCancelButton_clicked(self, *arg): ConfDialog.hide() @@ -187,8 +199,9 @@ class Handler: have_updates() def main(): - transaction.do_refresh() - have_updates() + do_refresh() + #have_updates() + update_label.set_markup("Available updates") interface.connect_signals(Handler()) UpdateWindow.show_all() while Gtk.events_pending(): diff --git a/test.py b/test.py index 77a4082..b24dfa0 100755 --- a/test.py +++ b/test.py @@ -1,20 +1,90 @@ #! /usr/bin/python # -*-coding:utf-8 -*- -from pamac import config - -syncpkgs = {} +import pyalpm +from pamac import config, common +from collections import OrderedDict +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 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) -print(virtualdeps) +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): + #~ if 'module' in name: + #~ if not virtualdeps.__contains__(name): + #~ 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)