How to use the pybombs.utils.subproc.check_output 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 / packagers / zypper.py View on Github external
[self.fastcommand, "-q", 
                                    '--qf=%{NAME}\ %{VERSION}-%{RELEASE}\ %{ARCH}', 
                                    pkgname]).strip().split()
                if pkg == pkgname and (pkgarch is None or arch == pkgarch):
                    self.log.debug("Package {0} has version {1} in {2}".format(pkgname, ver, self.fastcommand))
                    return ver
            # exception for unpack error if package not found
            except subproc.CalledProcessError:
                pass
            except Exception as ex:
                self.log.error("Parsing `{0} list installed` failed.".format(self.fastcommand))
                self.log.trace(str(ex))
            return False
        try:
            # 'list installed' will return non-zero if package does not exist, thus will throw
            out = subproc.check_output(
                    [self.command, "search", "-is", pkgname],
                    stderr=subprocess.STDOUT
            ).strip().split("\n")
            # Output looks like this:
            # |||||
            # So, two steps:
            # 1) Check that pkgname is correct (and, if necessary, the package arch)
            # 2) return version
            match_pat = r"^(?P)\s+\|\s+(?P[^\.]+)\s+\| \
                        \s+(?P\S+)\s+\| \
                        \s+(?P[0-9]+([.-][0-9a-z]+))\s+\| \
                        \s+(?P\S+)\s+(\d+:)"
            matcher = re.compile(match_pat)
            for line in out:
                mobj = matcher.match(line)
                if mobj and mobj.group('pkg') == pkgname:
github gnuradio / pybombs / pybombs / packagers / pip.py View on Github external
def load_install_cache(self):
        """
        Populate the installed cache.
        """
        global PIP_INSTALLED_CACHE
        self.log.debug("Loading pip install cache.")
        PIP_INSTALLED_CACHE = {}
        try:
            installed_packages = \
                str(subproc.check_output([self.cmd, "list"])).strip().split("\n")
            for pkg in installed_packages:
                mobj = re.match(r'(?P\S+)\s+\((?P[^)]+)\)', str(pkg))
                if mobj is None:
                    continue
                PIP_INSTALLED_CACHE[mobj.group('pkg')] = mobj.group('ver')
            return
        except subproc.CalledProcessError as e:
            self.log.error("Could not run %s list. Hm.", self.cmd)
            self.log.error(str(e))
        except Exception as e:
            self.log.error("Some error while running %s list.", self.cmd)
            self.log.error(str(e))
github gnuradio / pybombs / pybombs / config_manager.py View on Github external
Run setup_env_file, return the new env
        FIXME make this portable!
        """
        self.log.debug('Loading environment from shell script: {0}'.format(setup_env_file))
        # It would be nice if we could do os.path.expandvars() with a custom
        # env, wouldn't it
        setup_env_file = setup_env_file.replace('${0}'.format(self.env_prefix_var), self.prefix_dir)
        setup_env_file = setup_env_file.replace('${{{0}}}'.format(self.env_prefix_var), self.prefix_dir)
        # TODO add some checks this is a legit script
        # Damn, I hate just running stuff :/
        # TODO unportable command:
        separator = '<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>'
        get_env_cmd = "source {env_file} && echo '{sep}' && env".format(env_file=setup_env_file, sep=separator)
        from pybombs.utils import subproc
        try:
            script_output = subproc.check_output(get_env_cmd, shell=True)
        except subproc.CalledProcessError:
            self.log.error("Trouble sourcing file {env_file}".format(env_file=setup_env_file))
            raise PBException("Could not source env file.")
        env_output = script_output.split(separator)[-1]
        # TODO assumption is that env_output now just holds the env output
        env_output = env_output.split('\n')
        env = {}
        for env_line in env_output:
            env_line = env_line.strip()
            if len(env_line) == 0:
                continue
            k, v = env_line.split('=', 1)
            env[k] = v
        return env
github gnuradio / pybombs / pybombs / packagers / pkgconfig.py View on Github external
def get_installed_version(self, pkgname):
        """
        Use pkg-config to determine and return the currently installed version.
        If pkgname is not installed, return None.
        """
        try:
            # pkg-config will return non-zero if package does not exist, thus will throw
            ver = subproc.check_output(["pkg-config", "--modversion", pkgname], stderr=subprocess.STDOUT).strip()
            self.log.debug("Package {0} has version {1} in pkg-config".format(pkgname, ver))
            return ver
        except subprocess.CalledProcessError:
            # This usually means the packet is not installed
            return False
        except Exception as e:
            self.log.error("Running `pkg-config --modversion` failed.")
            self.log.trace(str(e))
        return False
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 / port.py View on Github external
def get_available_version(self, pkgname):
        """
        Search for package with 'port search'
        """
        try:
            out = subproc.check_output(["port", "search", "--name", "--glob", pkgname]).strip()
            if "No match" in out:
                return False
            ver = re.search(r'@(?P[0-9,.]*)', str(out)).group('ver')
            return ver
        except subprocess.CalledProcessError:
            return False
        except Exception as e:
            self.log.error("Error running port search")
        return False
github gnuradio / pybombs / pybombs / fetchers / wget.py View on Github external
def get_md5(filename):
        " Return MD5 sum of filename using the md5sum tool "
        md5_exe = sysutils.which('md5sum')
        if md5_exe is not None:
            return subproc.check_output([md5_exe, filename])[0:32]
        return None
    from pybombs.utils import sysutils