def uninstall(self): platform = self.get_type() installed_platforms = PlatformFactory.get_platforms( installed=True).keys() if platform not in installed_platforms: raise exception.PlatformNotInstalledYet(platform) deppkgs = set() for item in installed_platforms: if item == platform: continue p = PlatformFactory.newPlatform(item) deppkgs = deppkgs.union(set(p.get_packages().keys())) pm = PackageManager() for name in self.get_packages().keys(): if not pm.is_installed(name) or name in deppkgs: continue pm.uninstall(name) # unregister installed platform installed_platforms.remove(platform) set_state_item("installed_platforms", installed_platforms) return True
def run(self, variables, targets, verbose): assert isinstance(variables, list) assert isinstance(targets, list) self._verbose_level = int(verbose) installed_platforms = PlatformFactory.get_platforms( installed=True).keys() installed_packages = PackageManager.get_installed() if self.get_type() not in installed_platforms: raise exception.PlatformNotInstalledYet(self.get_type()) if "clean" in targets: targets.remove("clean") targets.append("-c") if not any([v.startswith("BUILD_SCRIPT=") for v in variables]): variables.append("BUILD_SCRIPT=%s" % self.get_build_script()) for v in variables: if not v.startswith("BUILD_SCRIPT="): continue _, path = v.split("=", 2) if not isfile(path): raise exception.BuildScriptNotFound(path) # append aliases of the installed packages for name, options in self.get_packages().items(): if "alias" not in options or name not in installed_packages: continue variables.append("PIOPACKAGE_%s=%s" % (options['alias'].upper(), name)) self._found_error = False try: # test that SCons is installed correctly assert self.test_scons() result = util.exec_command([ "scons", "-Q", "-f", join(util.get_source_dir(), "builder", "main.py") ] + variables + targets, stdout=util.AsyncPipe(self.on_run_out), stderr=util.AsyncPipe(self.on_run_err)) except (OSError, AssertionError): raise exception.SConsNotInstalled() assert "returncode" in result # if self._found_error: # result['returncode'] = 1 if self._last_echo_line == ".": click.echo("") return result
def platform_show(platform): def _detail_version(version): if version.count(".") != 2: return version _, y = version.split(".")[:2] if int(y) < 100: return version if len(y) % 2 != 0: y = "0" + y parts = [str(int(y[i * 2:i * 2 + 2])) for i in range(len(y) / 2)] return "%s (%s)" % (version, ".".join(parts)) try: p = PlatformFactory.newPlatform(platform) except exception.UnknownPlatform: raise exception.PlatformNotInstalledYet(platform) click.echo("{name} ~ {title}".format(name=click.style(p.name, fg="cyan"), title=p.title)) click.echo("=" * (3 + len(p.name + p.title))) click.echo(p.description) click.echo() click.echo("Version: %s" % p.version) if p.homepage: click.echo("Home: %s" % p.homepage) if p.license: click.echo("License: %s" % p.license) if p.frameworks: click.echo("Frameworks: %s" % ", ".join(p.frameworks.keys())) if not p.packages: return installed_pkgs = p.get_installed_packages() for name, opts in p.packages.items(): click.echo() click.echo("Package %s" % click.style(name, fg="yellow")) click.echo("-" * (8 + len(name))) if p.get_package_type(name): click.echo("Type: %s" % p.get_package_type(name)) click.echo("Requirements: %s" % opts.get("version")) click.echo("Installed: %s" % ("Yes" if name in installed_pkgs else "No (optional)")) if name in installed_pkgs: for key, value in installed_pkgs[name].items(): if key in ("url", "version", "description"): if key == "version": value = _detail_version(value) click.echo("%s: %s" % (key.title(), value))
def _install_default_packages(self): installed_platforms = PlatformFactory.get_platforms( installed=True).keys() if (self.get_type() in installed_platforms and set(self.get_default_packages()) <= set( self.get_installed_packages())): return True if (not app.get_setting("enable_prompts") or self.get_type() in installed_platforms or click.confirm( "The platform '%s' has not been installed yet. " "Would you like to install it now?" % self.get_type())): return self.install() else: raise exception.PlatformNotInstalledYet(self.get_type())
def run(self, variables, targets): assert isinstance(variables, list) assert isinstance(targets, list) installed_platforms = PlatformFactory.get_platforms( installed=True).keys() installed_packages = PackageManager.get_installed() if self.get_name() not in installed_platforms: raise exception.PlatformNotInstalledYet(self.get_name()) if "clean" in targets: targets.remove("clean") targets.append("-c") if not any([v.startswith("BUILD_SCRIPT=") for v in variables]): variables.append("BUILD_SCRIPT=%s" % self.get_build_script()) for v in variables: if not v.startswith("BUILD_SCRIPT="): continue _, path = v.split("=", 2) if not isfile(path): raise exception.BuildScriptNotFound(path) # append aliases of the installed packages for name, options in self.get_packages().items(): if name not in installed_packages: continue variables.append("PIOPACKAGE_%s=%s" % (options['alias'].upper(), name)) try: result = exec_command([ "scons", "-Q", "-f", join(get_source_dir(), "builder", "main.py") ] + variables + targets) except OSError: raise exception.SConsNotInstalled() return self.after_run(result)
def platform_show(platform): try: p = PlatformFactory.newPlatform(platform) except exception.UnknownPlatform: raise exception.PlatformNotInstalledYet(platform) click.echo("{name} ~ {title}".format( name=click.style( p.name, fg="cyan"), title=p.title)) click.echo("=" * (3 + len(p.name + p.title))) click.echo(p.description) click.echo() click.echo("Version: %s" % p.version) if p.homepage: click.echo("Home: %s" % p.homepage) if p.license: click.echo("License: %s" % p.license) if p.frameworks: click.echo("Frameworks: %s" % ", ".join(p.frameworks.keys())) if not p.packages: return installed_pkgs = p.get_installed_packages() for name, opts in p.packages.items(): click.echo() click.echo("Package %s" % click.style(name, fg="yellow")) click.echo("-" * (8 + len(name))) if p.get_package_type(name): click.echo("Type: %s" % p.get_package_type(name)) click.echo("Requirements: %s" % opts.get("version")) click.echo("Installed: %s" % ("Yes" if name in installed_pkgs else "No (optional)")) if name in installed_pkgs: for key, value in installed_pkgs[name].items(): if key in ("url", "version", "description"): click.echo("%s: %s" % (key.title(), value))