def get_updates(): """Return a list of package objects in local db which can be updated""" 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: 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 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: for repo in handle.get_syncdbs(): pkg = repo.get_pkg(candidate.name) if pkg: result.append(pkg) break return do_syncfirst, result
def CheckUpdates(self, success, nosuccess): success('') syncfirst = False updates = [] _ignorepkgs = set() self.get_handle() for group in self.handle.ignoregrps: db = self.localdb grp = db.read_grp(group) if grp: name, pkg_list = grp for pkg in pkg_list: _ignorepkgs.add(pkg.name) for name in self.handle.ignorepkgs: pkg = self.localdb.get_pkg(name) if pkg: _ignorepkgs.add(pkg.name) if config.syncfirst: for name in config.syncfirst: pkg = self.localdb.get_pkg(name) if pkg: candidate = pyalpm.sync_newversion(pkg, self.syncdbs) if candidate: syncfirst = True updates.append( (candidate.name, candidate.version, candidate.db.name, '', candidate.download_size)) if not updates: if config.enable_aur: if not self.aur_updates_checked: self.get_local_packages() self.local_packages -= _ignorepkgs for pkg in self.localdb.pkgcache: if not pkg.name in _ignorepkgs: candidate = pyalpm.sync_newversion(pkg, self.syncdbs) if candidate: updates.append( (candidate.name, candidate.version, candidate.db.name, '', candidate.download_size)) self.local_packages.discard(pkg.name) if config.enable_aur: if not self.aur_updates_checked: if self.local_packages: self.aur_updates_pkgs = aur.multiinfo( self.local_packages) self.aur_updates_checked = True for aur_pkg in self.aur_updates_pkgs: if self.localdb.get_pkg(aur_pkg.name): comp = pyalpm.vercmp( aur_pkg.version, self.localdb.get_pkg(aur_pkg.name).version) if comp == 1: updates.append((aur_pkg.name, aur_pkg.version, aur_pkg.db.name, aur_pkg.tarpath, aur_pkg.download_size)) self.EmitAvailableUpdates((syncfirst, updates))
def update_members(self): self.syncdbs = { p.name:p for p in self.handle.get_syncdbs() } self.repos = [ p.name for p in self.handle.get_syncdbs() ] self.groupcaches = [ (db,self.syncdbs[db].grpcache) for db in self.syncdbs ] self.groups = { gc[0]:[ g[0] for g in gc[1]] for gc in self.groupcaches } self.group_pkgs = { gc[0]:{ g[0]:g[1] for g in gc[1]} for gc in self.groupcaches } self.all_pkg = [ p for repo in self.handle.get_syncdbs() for p in repo.pkgcache] self.all_pkg_n = [ p.name for repo in self.handle.get_syncdbs() for p in repo.pkgcache] self.upgradable_n= [ p.name for p in self.handle.get_localdb().pkgcache if pyalpm.sync_newversion(p, self.handle.get_syncdbs())] self.upgradable = [ p for p in self.handle.get_localdb().pkgcache if pyalpm.sync_newversion(p, self.handle.get_syncdbs())] self.localpkgs_n = [ p.name for p in self.handle.get_localdb().pkgcache ]
def CheckUpdates(self, success, nosuccess, loop): #success('') syncfirst = False updates = [] _ignorepkgs = set() self.get_handle() for group in self.handle.ignoregrps: db = self.localdb grp = db.read_grp(group) if grp: name, pkg_list = grp for pkg in pkg_list: _ignorepkgs.add(pkg.name) for name in self.handle.ignorepkgs: pkg = self.localdb.get_pkg(name) if pkg: _ignorepkgs.add(pkg.name) if config.syncfirst: for name in config.syncfirst: pkg = self.localdb.get_pkg(name) if pkg: candidate = pyalpm.sync_newversion(pkg, self.syncdbs) if candidate: syncfirst = True updates.append((candidate.name, candidate.version, candidate.db.name, '', candidate.download_size)) if not updates: if config.enable_aur: if not self.aur_updates_checked: self.get_local_packages() self.local_packages -= _ignorepkgs for pkg in self.localdb.pkgcache: if not pkg.name in _ignorepkgs: candidate = pyalpm.sync_newversion(pkg, self.syncdbs) if candidate: updates.append((candidate.name, candidate.version, candidate.db.name, '', candidate.download_size)) self.local_packages.discard(pkg.name) if config.enable_aur: if not self.aur_updates_checked: if self.local_packages: self.aur_updates_pkgs = aur.multiinfo(self.local_packages) self.aur_updates_checked = True for aur_pkg in self.aur_updates_pkgs: if self.localdb.get_pkg(aur_pkg.name): comp = pyalpm.vercmp(aur_pkg.version, self.localdb.get_pkg(aur_pkg.name).version) if comp == 1: updates.append((aur_pkg.name, aur_pkg.version, aur_pkg.db.name, aur_pkg.tarpath, aur_pkg.download_size)) self.EmitAvailableUpdates(syncfirst, updates) loop.quit()
def get_updates(): """Return a list of package objects in local db which can be updated""" global do_syncfirst global list_first if config.syncfirst: for name in config.syncfirst: pkg = config.handle.get_localdb().get_pkg(name) candidate = pyalpm.sync_newversion(pkg, config.handle.get_syncdbs()) if candidate: list_first.append(candidate) if list_first: do_syncfirst = True return list_first result = [] installed_pkglist = config.handle.get_localdb().pkgcache for pkg in installed_pkglist: candidate = pyalpm.sync_newversion(pkg, config.handle.get_syncdbs()) if candidate: result.append(candidate) return result
def apply_marked(self): print("[pacman] Applying changes... please don't wait, not implemented yet") t = self._t_init_from_options(None) # adding pkgs to transaction for p in self._to_install: t.add_pkg(self.get_package(p[0], p[1])) for p in self._to_upgrade: t.add_pkg(pyalpm.sync_newversion(self.get_package("local", p), self.handle.get_syncdbs())) for p in self._to_remove: t.remove_pkg(self.get_package("local", p)) self._t_finalize(t) #t.release() self.update_members()
def find_repo_updates() -> List[PackageUpdate]: repo_packages_updates = [] for local_pkg in PackageDB.get_local_list(): repo_pkg = pyalpm.sync_newversion( local_pkg, PackageDB.get_alpm_handle().get_syncdbs()) if not repo_pkg: continue repo_packages_updates.append( PackageUpdate( Name=local_pkg.name, New_Version=repo_pkg.version, Current_Version=local_pkg.version, Description=repo_pkg.desc, Repository=repo_pkg.db.name, )) return repo_packages_updates
def filter_pkglist(pkglist, options): result = [] if options.foreign: syncpkgs = set() for db in handle.get_syncdbs(): syncpkgs |= set(p.name for p in db.pkgcache) for pkg in pkglist: if options.deps and pkg.reason == pyalpm.PKG_REASON_EXPLICIT: continue if options.explicit and pkg.reason == pyalpm.PKG_REASON_DEPEND: continue if options.unrequired and len(pkg.compute_requiredby()) > 0: continue if options.foreign and pkg.name in syncpkgs: continue if options.upgrades and pyalpm.sync_newversion(pkg, handle.get_syncdbs()) is None: continue result.append(pkg) return result
def filter_pkglist(pkglist, options): result = [] if options.foreign: syncpkgs = set() for db in handle.get_syncdbs(): syncpkgs |= set(p.name for p in db.pkgcache) for pkg in pkglist: if options.deps and pkg.reason == pyalpm.PKG_REASON_EXPLICIT: continue if options.explicit and pkg.reason == pyalpm.PKG_REASON_DEPEND: continue if options.unrequired and len(pkg.compute_requiredby()) > 0: continue if options.foreign and pkg.name in syncpkgs: continue if options.upgrades and pyalpm.sync_newversion( pkg, handle.get_syncdbs()) is None: continue result.append(pkg) return result
def checkupdates(): count = 0 options = PacmanConf() tempdir = mkdtemp(dir='/tmp') options.dbpath = tempdir symlink('/var/lib/pacman/local', f'{tempdir}/local') # Workaround for passing a different DBPath but with the system pacman.conf handle = init_with_config_and_options(options) for db in handle.get_syncdbs(): db.update(False) db = handle.get_localdb() for pkg in db.pkgcache: if sync_newversion(pkg, handle.get_syncdbs()) is None: continue count += 1 rmtree(tempdir) return count
def on_list_treeview_button_press_event(treeview, event): global right_click_menu liststore = packages_list_treeview.get_model() # Check if right mouse button was clicked if event.type == Gdk.EventType.BUTTON_PRESS and event.button == 3: while Gtk.events_pending(): Gtk.main_iteration() treepath, viewcolumn, x, y = treeview.get_path_at_pos( int(event.x), int(event.y)) treeiter = liststore.get_iter(treepath) if treeiter: if liststore[treeiter][0] != _( 'No package found' ) and not liststore[treeiter][0].name in config.holdpkg: right_click_menu = Gtk.Menu() if liststore[treeiter][ 0].name in transaction.to_add | transaction.to_remove or liststore[ treeiter][0] in transaction.to_build: item = Gtk.ImageMenuItem(_('Deselect')) item.set_image( Gtk.Image.new_from_stock('gtk-undo', Gtk.IconSize.MENU)) item.connect('activate', mark_to_deselect, liststore[treeiter][0]) right_click_menu.append(item) elif liststore[treeiter][0].db.name == 'local': item = Gtk.ImageMenuItem(_('Remove')) item.set_image(Gtk.Image.new_from_pixbuf(to_remove_icon)) item.connect('activate', mark_to_remove, liststore[treeiter][0]) right_click_menu.append(item) if transaction.get_syncpkg(liststore[treeiter][0].name): if not pyalpm.sync_newversion(liststore[treeiter][0], transaction.syncdbs): item = Gtk.ImageMenuItem(_('Reinstall')) item.set_image( Gtk.Image.new_from_pixbuf(to_reinstall_icon)) item.connect('activate', mark_to_reinstall, liststore[treeiter][0]) right_click_menu.append(item) optdeps_strings = liststore[treeiter][0].optdepends if optdeps_strings: available_optdeps = [] for optdep_string in optdeps_strings: if not pyalpm.find_satisfier( transaction.localdb.pkgcache, optdep_string.split(':')[0]): available_optdeps.append(optdep_string) if available_optdeps: item = Gtk.ImageMenuItem( _('Install optional deps')) item.set_image( Gtk.Image.new_from_pixbuf(to_install_icon)) item.connect('activate', select_optdeps, liststore[treeiter][0], available_optdeps) right_click_menu.append(item) if liststore[treeiter][ 0].reason == pyalpm.PKG_REASON_DEPEND: item = Gtk.MenuItem(_('Mark as explicitly installed')) item.connect('activate', mark_explicitly_installed, liststore[treeiter][0]) right_click_menu.append(item) else: item = Gtk.ImageMenuItem(_('Install')) item.set_image(Gtk.Image.new_from_pixbuf(to_install_icon)) item.connect('activate', mark_to_install, liststore[treeiter][0]) right_click_menu.append(item) optdeps_strings = liststore[treeiter][0].optdepends if optdeps_strings: available_optdeps = [] for optdep_string in optdeps_strings: if not pyalpm.find_satisfier( transaction.localdb.pkgcache, optdep_string.split(':')[0]): available_optdeps.append(optdep_string) if available_optdeps: item = Gtk.ImageMenuItem( _('Install with optional deps')) item.set_image( Gtk.Image.new_from_pixbuf(to_install_icon)) item.connect('activate', install_with_optdeps, liststore[treeiter][0], available_optdeps) right_click_menu.append(item) treeview.grab_focus() treeview.set_cursor(treepath, viewcolumn, 0) right_click_menu.show_all() right_click_menu.popup(None, None, None, None, event.button, event.time) return True
def test_sync_newversion_error(): with pytest.raises(TypeError) as excinfo: pyalpm.sync_newversion() assert 'takes a Package and a list of DBs' in str(excinfo.value)
def test_sync_newversion(syncdb, package): assert pyalpm.sync_newversion(package, [syncdb]) is None
def on_list_treeview_button_press_event(treeview, event): global right_click_menu liststore = packages_list_treeview.get_model() # Check if right mouse button was clicked if event.type == Gdk.EventType.BUTTON_PRESS and event.button == 3: while Gtk.events_pending(): Gtk.main_iteration() treepath, viewcolumn, x, y = treeview.get_path_at_pos(int(event.x), int(event.y)) treeiter = liststore.get_iter(treepath) if treeiter: if liststore[treeiter][0] != _('No package found') and not liststore[treeiter][0].name in config.holdpkg: right_click_menu = Gtk.Menu() if liststore[treeiter][0].name in transaction.to_add | transaction.to_remove or liststore[treeiter][0] in transaction.to_build: item = Gtk.ImageMenuItem(_('Deselect')) item.set_image(Gtk.Image.new_from_stock('gtk-undo', Gtk.IconSize.MENU)) item.connect('activate', mark_to_deselect, liststore[treeiter][0]) right_click_menu.append(item) elif liststore[treeiter][0].db.name == 'local': item = Gtk.ImageMenuItem(_('Remove')) item.set_image(Gtk.Image.new_from_pixbuf(to_remove_icon)) item.connect('activate', mark_to_remove, liststore[treeiter][0]) right_click_menu.append(item) if transaction.get_syncpkg(liststore[treeiter][0].name): if not pyalpm.sync_newversion(liststore[treeiter][0], transaction.syncdbs): item = Gtk.ImageMenuItem(_('Reinstall')) item.set_image(Gtk.Image.new_from_pixbuf(to_reinstall_icon)) item.connect('activate', mark_to_reinstall, liststore[treeiter][0]) right_click_menu.append(item) optdeps_strings = liststore[treeiter][0].optdepends if optdeps_strings: available_optdeps = [] for optdep_string in optdeps_strings: if not pyalpm.find_satisfier(transaction.localdb.pkgcache, optdep_string.split(':')[0]): available_optdeps.append(optdep_string) if available_optdeps: item = Gtk.ImageMenuItem(_('Install optional deps')) item.set_image(Gtk.Image.new_from_pixbuf(to_install_icon)) item.connect('activate', select_optdeps, liststore[treeiter][0], available_optdeps) right_click_menu.append(item) if liststore[treeiter][0].reason == pyalpm.PKG_REASON_DEPEND: item = Gtk.MenuItem(_('Mark as explicitly installed')) item.connect('activate', mark_explicitly_installed, liststore[treeiter][0]) right_click_menu.append(item) else: item = Gtk.ImageMenuItem(_('Install')) item.set_image(Gtk.Image.new_from_pixbuf(to_install_icon)) item.connect('activate', mark_to_install, liststore[treeiter][0]) right_click_menu.append(item) optdeps_strings = liststore[treeiter][0].optdepends if optdeps_strings: available_optdeps = [] for optdep_string in optdeps_strings: if not pyalpm.find_satisfier(transaction.localdb.pkgcache, optdep_string.split(':')[0]): available_optdeps.append(optdep_string) if available_optdeps: item = Gtk.ImageMenuItem(_('Install with optional deps')) item.set_image(Gtk.Image.new_from_pixbuf(to_install_icon)) item.connect('activate', install_with_optdeps, liststore[treeiter][0], available_optdeps) right_click_menu.append(item) treeview.grab_focus() treeview.set_cursor(treepath, viewcolumn, 0) right_click_menu.show_all() right_click_menu.popup(None, None, None, None, event.button, event.time) return True