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 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 cli(): for name, pkgs in PackageManager.get_installed().items(): echo("{name:<20} with packages: {pkgs}".format( name=style(name, fg="cyan"), pkgs=", ".join(pkgs.keys()) ))
def cli(): for platform in PackageManager.get_installed().keys(): echo("\nPlatform %s" % style(platform, fg="cyan")) echo("--------") p = PlatformFactory().newPlatform(platform) p.update()
def platforms_show(ctx, platform): installed_platforms = PlatformFactory.get_platforms( installed=True).keys() if platform not in installed_platforms: if (not app.get_setting("enable_prompts") or click.confirm("The platform '%s' has not been installed yet. " "Would you like to install it now?" % platform)): ctx.invoke(platforms_install, platforms=[platform]) else: raise PlatformNotInstalledYet(platform) p = PlatformFactory.newPlatform(platform) click.echo("{name:<20} - {description} [ {url} ]".format( name=click.style(p.get_type(), fg="cyan"), description=p.get_description(), url=p.get_vendor_url())) installed_packages = PackageManager.get_installed() for name in p.get_installed_packages(): data = installed_packages[name] pkgalias = p.get_pkg_alias(name) click.echo("----------") click.echo("Package: %s" % click.style(name, fg="yellow")) if pkgalias: click.echo("Alias: %s" % pkgalias) click.echo("Version: %d" % int(data['version'])) click.echo("Installed: %s" % datetime.fromtimestamp( data['time']).strftime("%Y-%m-%d %H:%M:%S"))
def run(self, variables, targets, verbose): assert isinstance(variables, dict) assert isinstance(targets, list) self.configure_default_packages(variables, targets) self._install_default_packages() self._verbose_level = int(verbose) if "clean" in targets: targets.remove("clean") targets.append("-c") if "build_script" not in variables: variables['build_script'] = self.get_build_script() if not isfile(variables['build_script']): raise exception.BuildScriptNotFound(variables['build_script']) # append aliases of the installed packages installed_packages = PackageManager.get_installed() for name, options in self.get_packages().items(): if "alias" not in options or name not in installed_packages: continue variables['piopackage_%s' % options['alias']] = name self._found_error = False result = self._run_scons(variables, targets) assert "returncode" in result # if self._found_error: # result['returncode'] = 1 if self._last_echo_line == ".": click.echo("") return result
def cli(): for name, pkgs in PackageManager.get_installed().items(): echo("{name:<20} with packages: {pkgs}".format(name=style(name, fg="cyan"), pkgs=", ".join( pkgs.keys())))
def platforms_show(ctx, platform): installed_platforms = PlatformFactory.get_platforms( installed=True).keys() if platform not in installed_platforms: if (not app.get_setting("enable_prompts") or click.confirm("The platform '%s' has not been installed yet. " "Would you like to install it now?" % platform)): ctx.invoke(platforms_install, platforms=[platform]) else: raise PlatformNotInstalledYet(platform) p = PlatformFactory.newPlatform(platform) click.echo("{name:<20} - {description} [ {url} ]".format( name=click.style(p.get_type(), fg="cyan"), description=p.get_description(), url=p.get_vendor_url())) installed_packages = PackageManager.get_installed() for name in p.get_installed_packages(): data = installed_packages[name] pkgalias = p.get_package_alias(name) click.echo("----------") click.echo("Package: %s" % click.style(name, fg="yellow")) if pkgalias: click.echo("Alias: %s" % pkgalias) click.echo("Version: %d" % int(data['version'])) click.echo("Installed: %s" % datetime.fromtimestamp( data['time']).strftime("%Y-%m-%d %H:%M:%S"))
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 util.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.SConsNotInstalledError() assert "returncode" in result # if self._found_error: # result['returncode'] = 1 if self._last_echo_line == ".": click.echo("") return result
def uninstall(self): platform = self.get_name() pm = PackageManager(platform) for package, data in pm.get_installed(platform).items(): pm.uninstall(package, data['path']) pm.unregister_platform(platform) rmtree(pm.get_platform_dir()) return True
def cli(platform): p = PlatformFactory().newPlatform(platform) if platform not in PackageManager.get_installed(): raise PlatformNotInstalledYet(platform) # print info about platform echo("{name:<20} - {info}".format(name=style(p.get_name(), fg="cyan"), info=p.get_short_info())) pm = PackageManager(platform) for name, data in pm.get_installed(platform).items(): pkgalias = p.get_pkg_alias(name) echo("----------") echo("Package: %s" % style(name, fg="yellow")) if pkgalias: echo("Alias: %s" % pkgalias) echo("Location: %s" % join(pm.get_platform_dir(), data['path'])) echo("Version: %d" % int(data['version']))
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 cli(platforms): for platform in platforms: if platform not in PackageManager.get_installed(): raise PlatformNotInstalledYet(platform) p = PlatformFactory().newPlatform(platform) if p.uninstall(): secho("The platform '%s' has been successfully " "uninstalled!" % platform, fg="green")
def install(self, with_packages, without_packages, skip_default_packages): with_packages = set(self.pkg_aliases_to_names(with_packages)) without_packages = set(self.pkg_aliases_to_names(without_packages)) upkgs = with_packages | without_packages ppkgs = set(self.PACKAGES.keys()) if not upkgs.issubset(ppkgs): raise UnknownPackage(", ".join(upkgs - ppkgs)) requirements = [] for name, opts in self.PACKAGES.items(): if name in without_packages: continue elif (name in with_packages or (not skip_default_packages and opts['default'])): requirements.append((name, opts['path'])) pm = PackageManager(self.get_name()) for (package, path) in requirements: pm.install(package, path) return len(requirements)
def run(self, variables, targets, verbose): assert isinstance(variables, list) assert isinstance(targets, list) envoptions = {} for v in variables: _name, _value = v.split("=", 1) envoptions[_name.lower()] = _value self.configure_default_packages(envoptions, targets) self._install_default_packages() self._verbose_level = int(verbose) if "clean" in targets: targets.remove("clean") targets.append("-c") if "build_script" not in envoptions: variables.append("BUILD_SCRIPT=%s" % self.get_build_script()) for v in variables: if not v.startswith("BUILD_SCRIPT="): continue _, path = v.split("=", 1) if not isfile(path): raise exception.BuildScriptNotFound(path) # append aliases of the installed packages installed_packages = PackageManager.get_installed() 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 result = self._run_scons(variables, targets) assert "returncode" in result # if self._found_error: # result['returncode'] = 1 if self._last_echo_line == ".": click.echo("") return result
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 run(self, variables, targets, verbose): assert isinstance(variables, list) assert isinstance(targets, list) envoptions = {} for v in variables: _name, _value = v.split("=", 1) envoptions[_name.lower()] = _value self.configure_default_packages(envoptions, targets) self._install_default_packages() self._verbose_level = int(verbose) if "clean" in targets: targets.remove("clean") targets.append("-c") if "build_script" not in envoptions: variables.append("BUILD_SCRIPT=%s" % self.get_build_script()) for v in variables: if not v.startswith("BUILD_SCRIPT="): continue _, path = v.split("=", 1) if not isfile(path): raise exception.BuildScriptNotFound(path) # append aliases of the installed packages installed_packages = PackageManager.get_installed() 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 util.test_scons() result = util.exec_command( [ "scons", "-Q", "-j %d" % self.get_job_nums(), "--warn=no-no-parallel-support", "-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.SConsNotInstalledError() assert "returncode" in result # if self._found_error: # result['returncode'] = 1 if self._last_echo_line == ".": click.echo("") return result
def is_outdated(self): pm = PackageManager() obsolated = pm.get_outdated() return not set(self.get_packages().keys()).isdisjoint(set(obsolated))
def update(self): pm = PackageManager() for name in self.get_installed_packages(): pm.update(name)
def update(self): platform = self.get_name() pm = PackageManager(platform) for package in pm.get_installed(platform).keys(): pm.update(package)
def get_installed_packages(self): pm = PackageManager() return [n for n in self.get_packages().keys() if pm.is_installed(n)]
def run(self, variables, targets, verbose): assert isinstance(variables, list) assert isinstance(targets, list) envoptions = {} for v in variables: _name, _value = v.split("=", 1) envoptions[_name.lower()] = _value self.configure_default_packages(envoptions, targets) self._install_default_packages() self._verbose_level = int(verbose) if "clean" in targets: targets.remove("clean") targets.append("-c") if "build_script" not in envoptions: variables.append("BUILD_SCRIPT=%s" % self.get_build_script()) for v in variables: if not v.startswith("BUILD_SCRIPT="): continue _, path = v.split("=", 1) if not isfile(path): raise exception.BuildScriptNotFound(path) # append aliases of the installed packages installed_packages = PackageManager.get_installed() 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 args = [] try: args = ( [ os.path.relpath(PathsManager.EXECUTABLE_FILE), # [JORGE_GARCIA] modified for scons compatibility "-Q", "-j %d" % self.get_job_nums(), "--warn=no-no-parallel-support", "-f", join(util.get_source_dir(), "builder", "main.py"), ] + variables + targets + [os.getcwd()] ) if PathsManager.EXECUTABLE_FILE.endswith(".py"): args = ["python"] + args # test that SCons is installed correctly # assert util.test_scons() log.debug("Executing: {}".format("\n".join(args))) result = util.exec_command( args, stdout=util.AsyncPipe(self.on_run_out), stderr=util.AsyncPipe(self.on_run_err) ) except (OSError, AssertionError) as e: log.exception("error running scons with \n{}".format(args)) raise exception.SConsNotInstalledError() assert "returncode" in result # if self._found_error: # result['returncode'] = 1 if self._last_echo_line == ".": click.echo("") return result
def run(self, variables, targets, verbose): assert isinstance(variables, list) assert isinstance(targets, list) envoptions = {} for v in variables: _name, _value = v.split("=", 1) envoptions[_name.lower()] = _value self.configure_default_packages(envoptions, targets) self._install_default_packages() self._verbose_level = int(verbose) if "clean" in targets: targets.remove("clean") targets.append("-c") if "build_script" not in envoptions: variables.append("BUILD_SCRIPT=%s" % self.get_build_script()) for v in variables: if not v.startswith("BUILD_SCRIPT="): continue _, path = v.split("=", 1) if not isfile(path): raise exception.BuildScriptNotFound(path) # append aliases of the installed packages installed_packages = PackageManager.get_installed() 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 args = [] try: args = [os.path.relpath(PathsManager.EXECUTABLE_FILE), # [JORGE_GARCIA] modified for scons compatibility "-Q", "-j %d" % self.get_job_nums(), "--warn=no-no-parallel-support", "-f", join(util.get_source_dir(), "builder", "main.py") ] + variables + targets + [os.getcwd()] if PathsManager.EXECUTABLE_FILE.endswith(".py"): args = ["python"] + args # test that SCons is installed correctly # assert util.test_scons() log.debug("Executing: {}".format("\n".join(args))) result = util.exec_command(args, stdout=util.AsyncPipe(self.on_run_out), stderr=util.AsyncPipe(self.on_run_err)) except (OSError, AssertionError) as e: log.exception("error running scons with \n{}".format(args)) raise exception.SConsNotInstalledError() assert "returncode" in result # if self._found_error: # result['returncode'] = 1 if self._last_echo_line == ".": click.echo("") return result