Пример #1
0
        def foobar(*args, **kwargs):
            args = get_args()
            params = merge_dict(args, override)

            for k, v in iteritems(values):
                assert params[k] == v

            if initial:
                for k in iterkeys(initial):
                    assert initial[k] == args[k]
Пример #2
0
def popen(*args, **kwargs):
    output = kwargs.get("output", False)
    quiet = kwargs.get("quiet", False)
    directory = kwargs.get("cwd")
    environment = kwargs.get("env")
    shell = kwargs.get("shell", True)
    raise_err = kwargs.get("raise_err", True)

    environ = os.environ.copy()
    if environment:
        environ.update(environment)

    for k, v in iteritems(environ):
        environ[k] = str(v)

    command = " ".join([str(arg) for arg in args])
    logger.info("Executing command: %s" % command)

    if quiet:
        output = True

    proc = sp.Popen(command,
                    bufsize=-1,
                    stdin=sp.PIPE if output else kwargs.get("stdin"),
                    stdout=sp.PIPE if output else None,
                    stderr=sp.PIPE if output else None,
                    env=environ,
                    cwd=directory,
                    shell=shell)

    code = proc.wait()

    if code and raise_err:
        print("An error occurred while updating package:",
              PopenError(code, command))
        #raise PopenError(code, command)

    if output:
        output, error = proc.communicate()

        if output:
            output = safe_decode(output)
            output = strip(output)

        if error:
            error = safe_decode(error)
            error = strip(error)

        if quiet:
            return code
        else:
            return code, output, error
    else:
        return code
Пример #3
0
def to_params(kwargs):
    class O(object):
        pass

    params = O()

    kwargs = merge_dict(ARGUMENTS, kwargs)

    for k, v in iteritems(kwargs):
        setattr(params, k, v)

    return params
Пример #4
0
def popen(*args, **kwargs):
    output      = kwargs.get("output", False)
    quiet       = kwargs.get("quiet" , False)
    directory   = kwargs.get("cwd")
    environment = kwargs.get("env")
    shell       = kwargs.get("shell", True)
    raise_err   = kwargs.get("raise_err", True)

    environ     = os.environ.copy()
    if environment:
        environ.update(environment)

    for k, v in iteritems(environ):
        environ[k] = str(v)

    command     = " ".join([str(arg) for arg in args])

    if quiet:
        output  = True
    
    proc        = sp.Popen(command,
        stdin   = sp.PIPE if output else None,
        stdout  = sp.PIPE if output else None,
        stderr  = sp.PIPE if output else None,
        env     = environ,
        cwd     = directory,
        shell   = shell
    )

    code       = proc.wait()

    if code and raise_err:
        raise sp.CalledProcessError(code, command)

    if output:
        output, error = proc.communicate()

        if output:
            output = output.decode("utf-8")
            output = strip(output)

        if error:
            error  = error.decode("utf-8")
            error  = strip(error)

        if quiet:
            return code
        else:
            return code, output, error
    else:
        return code
Пример #5
0
def call(*args, **kwargs):
    pip_exec = kwargs.pop("pip_exec", _PIP_EXECUTABLE)

    params   = sequencify(pip_exec) + sequencify(args)
    
    for flag, value in iteritems(kwargs):
        if value != False:
            flag  = "--%s" % kebab_case(flag, delimiter = "_")
            params.append(flag)

            if not isinstance(value, bool):
                value = value_to_envval(value)
                params.append(value)

    return popen(*params, output = True)
Пример #6
0
def _build_packages_info_dict(packages, pip_exec = None):
    details         = _get_pip_info(*packages, pip_exec = pip_exec)

    requirements    = [ ]

    for name, detail in iteritems(details):
        if not name in _INFO_DICT:
            _INFO_DICT[name] = dict({
                     "version": detail["version"], 
                "dependencies": compact(detail["requires"].split(", "))
            })

            for requirement in _INFO_DICT[name]["dependencies"]:
                if requirement not in requirements:
                    requirements.append(requirement)

    if requirements:
        _build_packages_info_dict(requirements, pip_exec = pip_exec)
Пример #7
0
def call(*args, **kwargs):
    pip_exec = kwargs.pop("pip_exec", None) or _PIP_EXECUTABLE
    quiet = kwargs.pop("quiet", None) or False
    output = kwargs.pop("output", None) or False
    raise_err = kwargs.pop("raise_err", None) or True

    params = sequencify(pip_exec) + sequencify(args)

    for flag, value in iteritems(kwargs):
        if value != False:
            flag = "--%s" % kebab_case(flag, delimiter="_")
            params.append(flag)

            if not isinstance(value, bool):
                value = value_to_envval(value)
                params.append(value)

    output = output or quiet

    output = popen(*params, output=output, raise_err=raise_err)

    return output
Пример #8
0
 def _init(self):
     for k, v in iteritems(Settings._DEFAULTS):
         self.set(k, v)