def install_packages(self, with_packages=None, without_packages=None, skip_default_package=False, silent=False): with_packages = set(self.pkg_types_to_names(with_packages or [])) without_packages = set(self.pkg_types_to_names(without_packages or [])) upkgs = with_packages | without_packages ppkgs = set(self.packages.keys()) if not upkgs.issubset(ppkgs): raise exception.UnknownPackage(", ".join(upkgs - ppkgs)) for name, opts in self.packages.items(): if name in without_packages: continue elif (name in with_packages or not (skip_default_package or opts.get("optional", False))): if any([s in opts.get("version", "") for s in ("\\", "/")]): self.pm.install( "%s=%s" % (name, opts['version']), silent=silent) else: self.pm.install(name, opts.get("version"), silent=silent) return True
def _install_from_piorepo(self, name, requirements): pkg_dir = None pkgdata = None versions = None last_exc = None for versions in PackageRepoIterator(name, self.repositories): pkgdata = self.max_satisfying_repo_version(versions, requirements) if not pkgdata: continue try: pkg_dir = self._install_from_url(name, pkgdata["url"], requirements, pkgdata.get("sha1")) break except Exception as e: # pylint: disable=broad-except last_exc = e click.secho("Warning! Package Mirror: %s" % e, fg="yellow") click.secho("Looking for another mirror...", fg="yellow") if versions is None: util.internet_on(raise_exception=True) raise exception.UnknownPackage(name + (". Error -> %s" % last_exc if last_exc else "")) if not pkgdata: raise exception.UndefinedPackageVersion(requirements or "latest", util.get_systype()) return pkg_dir
def install_packages( # pylint: disable=too-many-arguments self, with_packages=None, without_packages=None, skip_default_package=False, silent=False, force=False, ): with_packages = set(self.find_pkg_names(with_packages or [])) without_packages = set(self.find_pkg_names(without_packages or [])) upkgs = with_packages | without_packages ppkgs = set(self.packages) if not upkgs.issubset(ppkgs): raise exception.UnknownPackage(", ".join(upkgs - ppkgs)) for name, opts in self.packages.items(): version = opts.get("version", "") if name in without_packages: continue if name in with_packages or not (skip_default_package or opts.get("optional", False)): if ":" in version: self.pm.install("%s=%s" % (name, version), silent=silent, force=force) else: self.pm.install(name, version, silent=silent, force=force) return True
def install(self, with_packages=None, without_packages=None, skip_default_packages=False): with_packages = set( self.pkg_aliases_to_names(with_packages or [])) without_packages = set( self.pkg_aliases_to_names(without_packages or [])) upkgs = with_packages | without_packages ppkgs = set(self.get_packages().keys()) if not upkgs.issubset(ppkgs): raise exception.UnknownPackage(", ".join(upkgs - ppkgs)) requirements = [] for name, opts in self.get_packages().items(): if name in without_packages: continue elif (name in with_packages or (not skip_default_packages and opts.get("default"))): requirements.append(name) pm = PackageManager() for name in requirements: pm.install(name) # register installed platform data = get_state_item("installed_platforms", []) if self.get_type() not in data: data.append(self.get_type()) set_state_item("installed_platforms", data) return len(requirements)
def install_packages(self, with_packages=None, without_packages=None, skip_default_package=False, silent=False): with_packages = set(self.find_pkg_names(with_packages or [])) without_packages = set(self.find_pkg_names(without_packages or [])) upkgs = with_packages | without_packages ppkgs = set(self.packages.keys()) if not upkgs.issubset(ppkgs): raise exception.UnknownPackage(", ".join(upkgs - ppkgs)) for name, opts in self.packages.items(): version = opts.get("version", "") if name in without_packages: continue elif (name in with_packages or not (skip_default_package or opts.get("optional", False))): if self.is_valid_requirements(version): self.pm.install(name, version, silent=silent) else: requirements = None if "@" in version: version, requirements = version.rsplit("@", 1) self.pm.install("%s=%s" % (name, version), requirements, silent=silent) return True
def update( # pylint: disable=too-many-return-statements self, package, requirements=None, only_check=False): if isdir(package): pkg_dir = package else: pkg_dir = self.get_package_dir(*self.parse_pkg_input(package)) if not pkg_dir: raise exception.UnknownPackage("%s @ %s" % (package, requirements or "*")) manifest = self.load_manifest(pkg_dir) name = manifest['name'] click.echo( "{} {:<40} @ {:<15}".format( "Checking" if only_check else "Updating", click.style(manifest['name'], fg="cyan"), manifest['version']), nl=False) if not util.internet_on(): click.echo("[%s]" % (click.style("Off-line", fg="yellow"))) return latest = self.outdated(pkg_dir, requirements) if latest: click.echo("[%s]" % (click.style(latest, fg="red"))) elif latest is False: click.echo("[%s]" % (click.style("Up-to-date", fg="green"))) else: click.echo("[%s]" % (click.style("Skip", fg="yellow"))) if only_check or not latest: return if "__src_url" in manifest: vcs = VCSClientFactory.newClient(pkg_dir, manifest['__src_url']) assert vcs.update() self._update_src_manifest( dict(version=vcs.get_current_revision()), vcs.storage_dir) else: self.uninstall(pkg_dir, trigger_event=False) self.install(name, latest, trigger_event=False) telemetry.on_event( category=self.__class__.__name__, action="Update", label=manifest['name']) return True
def update(self, package, requirements=None, only_check=False): self.cache_reset() if isdir(package) and self.get_package_by_dir(package): pkg_dir = package else: pkg_dir = self.get_package_dir(*self.parse_pkg_uri(package)) if not pkg_dir: raise exception.UnknownPackage("%s @ %s" % (package, requirements or "*")) manifest = self.load_manifest(pkg_dir) name = manifest["name"] click.echo( "{} {:<40} @ {:<15}".format( "Checking" if only_check else "Updating", click.style(manifest["name"], fg="cyan"), manifest["version"], ), nl=False, ) if not util.internet_on(): click.echo("[%s]" % (click.style("Off-line", fg="yellow"))) return None latest = self.outdated(pkg_dir, requirements) if latest: click.echo("[%s]" % (click.style(latest, fg="red"))) elif latest is False: click.echo("[%s]" % (click.style("Up-to-date", fg="green"))) else: click.echo("[%s]" % (click.style("Detached", fg="yellow"))) if only_check or not latest: return True if "__src_url" in manifest: vcs = VCSClientFactory.newClient(pkg_dir, manifest["__src_url"]) assert vcs.update() self._update_src_manifest(dict(version=vcs.get_current_revision()), vcs.storage_dir) else: self.uninstall(pkg_dir, after_update=True) self.install(name, latest, after_update=True) return True
def get_info(self, name, version=None): manifest = self.get_manifest() if name not in manifest: raise exception.UnknownPackage(name) # check system platform systype = get_systype() builds = ([b for b in manifest[name] if b['system'] == "all" or systype in b['system']]) if not builds: raise exception.NonSystemPackage(name, systype) if version: for b in builds: if b['version'] == version: return b raise exception.InvalidPackageVersion(name, version) else: return sorted(builds, key=lambda s: s['version'])[-1]
def uninstall(self, package, requirements=None, after_update=False): # interprocess lock with LockFile(self.package_dir): self.cache_reset() if isdir(package) and self.get_package_by_dir(package): pkg_dir = package else: name, requirements, url = self.parse_pkg_uri( package, requirements) pkg_dir = self.get_package_dir(name, requirements, url) if not pkg_dir: raise exception.UnknownPackage("%s @ %s" % (package, requirements or "*")) manifest = self.load_manifest(pkg_dir) click.echo("Uninstalling %s @ %s: \t" % (click.style( manifest['name'], fg="cyan"), manifest['version']), nl=False) if islink(pkg_dir): os.unlink(pkg_dir) else: fs.rmtree(pkg_dir) self.cache_reset() # unfix package with the same name pkg_dir = self.get_package_dir(manifest['name']) if pkg_dir and "@" in pkg_dir: shutil.move( pkg_dir, join(self.package_dir, self.get_install_dirname(manifest))) self.cache_reset() click.echo("[%s]" % click.style("OK", fg="green")) if not after_update: telemetry.on_event(category=self.__class__.__name__, action="Uninstall", label=manifest['name']) return True
def uninstall( self, package, requirements=None, after_update=False ): # pylint: disable=unused-argument # interprocess lock with LockFile(self.package_dir): self.cache_reset() if isdir(package) and self.get_package_by_dir(package): pkg_dir = package else: name, requirements, url = self.parse_pkg_uri(package, requirements) pkg_dir = self.get_package_dir(name, requirements, url) if not pkg_dir: raise exception.UnknownPackage( "%s @ %s" % (package, requirements or "*") ) manifest = self.load_manifest(pkg_dir) click.echo( "Uninstalling %s @ %s: \t" % (click.style(manifest["name"], fg="cyan"), manifest["version"]), nl=False, ) if islink(pkg_dir): os.unlink(pkg_dir) else: fs.rmtree(pkg_dir) self.cache_reset() # unfix package with the same name pkg_dir = self.get_package_dir(manifest["name"]) if pkg_dir and "@" in pkg_dir: shutil.move( pkg_dir, join(self.package_dir, self.get_install_dirname(manifest)) ) self.cache_reset() click.echo("[%s]" % click.style("OK", fg="green")) return True