def _get_pip_info(*args, **kwargs): packages = args pip_exec = kwargs.get("pip_exec", None) _, out, _ = _pip.call("show", *packages, pip_exec = pip_exec, output = True) results = [strip(o) for o in out.split("---")] info = dict() for i, package in enumerate(packages): result = results[i] detail = dict((kebab_case(k), v.strip() if isinstance(v, string_types) else v) \ for k, v in \ iteritems( dict([(s + [""]) if len(s) == 1 else s \ for s in [re.split(r":\s?", o, maxsplit = 1) \ for o in result.split("\n")]] ) ) ) info[package] = detail return info
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]
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
async def save_proxies(proxies): while True: proxy = await proxies.get() if proxy is None: break values = [ ] for type_, level in iteritems(proxy.types): secure = int(type_ == "HTTPS") level = PROXY_LEVEL_CODES[ level ] if level else None value = (proxy.host, proxy.port, secure, level, proxy.geo.code, int(proxy.is_working), proxy.error_rate, proxy.avg_resp_time) values.append(value) save_proxies_to_db(values)
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)
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