def install(self, pkgs, conflicts=None, options=None): """ Install a list of packages like pacman -S """ if not conflicts: conflicts = [] if not options: options = {} if self.handle is None: logging.error("alpm is not initialised") raise pyalpm.error if len(pkgs) == 0: logging.error("Package list is empty") raise pyalpm.error # Discard duplicates pkgs = list(set(pkgs)) # `alpm.handle.get_syncdbs()` returns a list (the order is important) so we # have to ensure we don't clobber the priority of the repos. repos = OrderedDict() repo_order = [] one_repo_groups = ['cinnamon', 'mate', 'mate-extra'] db_match = [db for db in self.handle.get_syncdbs() if 'antergos' == db.name] antdb = OrderedDict() antdb[db_match[0].name] = db_match[1] one_repo_groups = [antdb.read_grp(one_repo_group) for one_repo_group in one_repo_groups] one_repo_pkgs = {pkg for one_repo_group in one_repo_groups for pkg in one_repo_group[1] if one_repo_group} for syncdb in self.handle.get_syncdbs(): repo_order.append(syncdb) repos[syncdb.name] = syncdb targets = [] logging.debug('REPO DB ORDER IS: %s', repo_order) for name in pkgs: _repos = repos if name in one_repo_pkgs: # pkg should be sourced from the antergos repo only. _repos = antdb result_ok, pkg = self.find_sync_package(name, _repos) if result_ok: # Check that added package is not in our conflicts list if pkg.name not in conflicts: targets.append(pkg.name) else: # Couldn't find the package, check if it's a group group_pkgs = self.get_group_pkgs(name) if group_pkgs is not None: # It's a group for group_pkg in group_pkgs: # Check that added package is not in our conflicts list # Ex: connman conflicts with netctl(openresolv), # which is installed by default with base group if group_pkg.name not in conflicts: targets.append(group_pkg.name) else: # No, it wasn't neither a package nor a group. As we don't # know if this error is fatal or not, we'll register it and # we'll allow to continue. logging.error("Can't find a package or group called '%s'", name) # Discard duplicates targets = list(set(targets)) logging.debug(targets) if len(targets) == 0: logging.error("No targets found") return False num_targets = len(targets) logging.debug("%d target(s) found", num_targets) # Maybe not all this packages will be downloaded, but it's # how many have to be there before starting the installation self.total_packages_to_download = num_targets transaction = self.init_transaction(options) if transaction is None: logging.error("Can't initialize alpm transaction") return False for i in range(0, num_targets): result_ok, pkg = self.find_sync_package(targets.pop(), repos) if result_ok: transaction.add_pkg(pkg) else: logging.warning(pkg) return self.finalize_transaction(transaction)