How to use the pybombs.utils.subproc function in PyBOMBS

To help you get started, we’ve selected a few PyBOMBS examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gnuradio / pybombs / pybombs / commands / prefix.py View on Github external
r = recipe.get_recipe(sdkname, target='sdk')
        try:
            self.log.trace("Switching CWD to {0}".format(src_dir))
            if not op.isdir(src_dir):
                os.mkdir(src_dir)
            os.chdir(src_dir)
        except:
            self.log.error("Source dir required to install SDK.")
            return False
        ### Install the actual SDK file
        self.log.debug("Fetching SDK `{sdk}'".format(sdk=sdkname))
        fetcher.Fetcher().fetch(r)
        self.log.info("Installing SDK `{sdk}'".format(sdk=sdkname))
        # Install command
        cmd = r.var_replace_all(r.get_command('install'))
        if subproc.monitor_process(cmd, shell=True, env=os.environ) == 0:
            self.log.debug("Installation successful")
        else:
            self.log.error("Error installing SDK. Aborting.")
            return False
        # Clean up
        files_to_delete = [op.normpath(op.join(src_dir, r.var_replace_all(x))) for x in r.clean]
        if files_to_delete:
            self.log.info("Cleaning up files...")
        for ftd in files_to_delete:
            if op.commonprefix((src_dir, ftd)) != src_dir:
                self.log.warn("Not removing {ftd} -- outside source dir!".format(ftd=ftd))
                continue
            self.log.debug("Removing {ftd}...".format(ftd=ftd))
            if op.isdir(ftd):
                shutil.rmtree(ftd)
            elif op.isfile(ftd):
github gnuradio / pybombs / pybombs / packagers / portage.py View on Github external
def _run_cmd(self, pkgname, cmd):
        try:
            if cmd:
                subproc.monitor_process(["emerge","--quiet-build","y","--ask","n",cmd,pkgname], elevate=True )
            else:
                subproc.monitor_process(["emerge","--quiet-build","y","--ask","n",pkgname], elevate=True )
            return True
        except Exception as e:
            self.log.error("Running `emerge {0}` failed.".format(cmd))
            self.log.trace(str(e))
            return False
github gnuradio / pybombs / pybombs / packagers / zypper.py View on Github external
def _run_cmd(self, pkgname, cmd):
        """
        Call zypper with cmd.
        """
        try:
            subproc.monitor_process([self.command, cmd, "-y", pkgname], elevate=True)
            return True
        except Exception as ex:
            self.log.error("Running `{0} install' failed.".format(self.command))
            self.log.trace(str(ex))
            return False
github gnuradio / pybombs / pybombs / packagers / pip.py View on Github external
def _run_pip_install(self, pkgname, update=False):
        """
        Run pip install [--upgrade]
        """
        try:
            command = [self.cmd, "install"]
            if update:
                command.append('--upgrade')
            command.append(pkgname)
            self.log.debug("Calling `{cmd}'".format(cmd=" ".join(command)))
            subproc.monitor_process(command, elevate=True)
            self.load_install_cache()
            return True
        except Exception as ex:
            self.log.error("Running pip install failed.")
            self.log.debug(str(ex))
        return None
github gnuradio / pybombs / pybombs / fetchers / git.py View on Github external
def get_git_version():
    """
    Return the currently installed git version as a string.
    """
    try:
        return re.search(
            r'[0-9.]+',
            subproc.check_output(['git', '--version'])
        ).group(0)
    except OSError:
        raise PBException("Unable to execute git!")
    except subproc.CalledProcessError:
        raise PBException("Error executing 'git --version'!")
    except AttributeError:
        raise PBException("Unexpected output from 'git --version'!")
github gnuradio / pybombs / pybombs / packagers / zypper.py View on Github external
def get_available_version(self, pkgname):
        """
        Return a version that we can install through this package manager.
        """
        try:
            ver = subproc.match_output(
                [self.command, "info", pkgname],
                r'^Version\s+:\s+(?P.*$)',
                'ver',
                 env=utils.dict_merge(os.environ, {'LC_ALL': 'C'}),
            )
            if ver is None:
                return False
            self.log.debug("Package {0} has version {1} in {2}".format(pkgname, ver, self.command))
            return ver
        except subproc.CalledProcessError as ex:
            # This usually means the package was not found, so don't worry
            self.log.trace("`{0} info' returned non-zero exit status.".format(self.command))
            self.log.trace(str(ex))
            return False
        except Exception as ex:
            self.log.error("Error parsing {0} info".format(self.command))
            self.log.error(str(ex))
        return False
github gnuradio / pybombs / pybombs / packagers / portage.py View on Github external
def _run_cmd(self, pkgname, cmd):
        try:
            if cmd:
                subproc.monitor_process(["emerge","--quiet-build","y","--ask","n",cmd,pkgname], elevate=True )
            else:
                subproc.monitor_process(["emerge","--quiet-build","y","--ask","n",pkgname], elevate=True )
            return True
        except Exception as e:
            self.log.error("Running `emerge {0}` failed.".format(cmd))
            self.log.trace(str(e))
            return False
github gnuradio / pybombs / pybombs / packagers / brew.py View on Github external
def get_available_version(self, pkgname):
        """
        Check which version is currently installed.
        """
        try:
            self.log.trace("Checking homebrew for `{0}'".format(pkgname))
            out = subproc.check_output(["brew", "info", "--json=v1", pkgname])
            # Returns non-zero exit status if package does not exist in brew taps
            if len(out) >= 0:
                # Get the version.
                pkgdata = json.loads(out)[0]  # Wrapped in a list. get the first element.
                version = pkgdata["versions"]["stable"]
                return version
            else:
                return False
        except subproc.CalledProcessError:
            # This usually means the packet is not installed
            return False
        except Exception as e:
            self.log.error("Running brew info failed.")
            self.log.trace(str(e))
        return False