示例#1
0
文件: pin.py 项目: srowe/planex
def populate_pinfile(pinfile, resources):
    """
    Update [pinfile] in place with content of resources.
    """
    for name, source in resources.items():
        # Exclude secondary resources
        if name not in ("Archive0", "PatchQueue0", "Source0"):
            continue

        pinfile[name] = {}
        if source.is_repo:
            url = source.url
            commitish = source.commitish
            prefix = source.prefix
        else:
            repo = Repository(source.url)
            commitish = repo.commitish_tag_or_branch()
            url = repo.repository_url()
            prefix = None

        if commitish is None:
            pinfile[name] = {"URL": source.url}
        else:
            pinfile[name] = {
                "URL": url,
                "commitish": commitish
            }

        if prefix is not None:
            pinfile[name]["prefix"] = prefix
        if isinstance(source, Archive):
            pinfile[name]["prefix"] = source.prefix
示例#2
0
def populate_pinfile(pinfile, resources):
    """
    Update [pinfile] in place with content of resources.
    """
    for name, source in resources.items():
        # Exclude secondary resources
        if name not in ("Archive0", "PatchQueue0", "Source0"):
            continue

        pinfile[name] = {}
        if source.is_repo:
            url = source.url
            commitish = source.commitish
            prefix = source.prefix
        else:
            repo = Repository(source.url)
            commitish = repo.commitish_tag_or_branch()
            url = repo.repository_url()
            prefix = None

        if commitish is None:
            pinfile[name] = {"URL": source.url}
        else:
            pinfile[name] = {"URL": url, "commitish": commitish}

        if prefix is not None:
            pinfile[name]["prefix"] = prefix
        if isinstance(source, Archive):
            pinfile[name]["prefix"] = source.prefix
示例#3
0
def repository_of(spec_or_link):
    """Return the Repository of the provided Spec source url or Link url.
       None if spec_or_link is None"""
    if isinstance(spec_or_link, Spec):
        return Repository(spec_or_link.source_urls()[0])
    if isinstance(spec_or_link, Link):
        return Repository(spec_or_link.url)
    if spec_or_link is None:
        return None
    else:
        print("repository_of: got unexpected object {}")
        sys.exit(1)
示例#4
0
文件: pin.py 项目: herrold/planex
def populate_pinfile(pinfile, args, resources):
    """
    Update [pinfile] in place with content of resources.
    """
    for name, source in resources.items():

        # If we are overriding Source0, we still need to keep other
        # eventual sources
        if args.source is not None \
                and (name == "Source0" or "Source" not in name):
            continue
        # When we override PatchQueue0, we get rid of all the other
        # patchqueues
        if args.patchqueue is not None and "PatchQueue" in name:
            continue
        # Patches are defined in the spec and could be overridden with
        # Archives, but we do not put them in the link and pin files
        if "Patch" in name and "PatchQueue" not in name:
            continue

        pinfile[name] = {}
        if source.is_repo:
            url = source.url
            commitish = source.commitish
            prefix = source.prefix
        else:
            # heuristically try to get a repo
            repo = Repository(source.url)
            commitish = repo.commitish_tag_or_branch()
            url = repo.repository_url()
            # for some archives the commitish_tag_or_branch function
            # does not work properly
            parsed_url = urlparse(source.url)
            at_val = parse_qs(parsed_url.query).get('at', [None]).pop()
            if at_val is not None and at_val != commitish:
                commitish = at_val
            if name == "Source0":
                prefix = parse_qs(urlparse(source.url).query).get(
                    "prefix", None)
                if prefix and isinstance(prefix, list):
                    prefix = prefix.pop()
            else:
                prefix = None

        if commitish is None:
            pinfile[name] = {"URL": source.url}
        else:
            pinfile[name] = {"URL": url, "commitish": commitish}

        if prefix is not None:
            pinfile[name]["prefix"] = prefix
        if isinstance(source, Archive):
            pinfile[name]["prefix"] = source.prefix
示例#5
0
def fetch_http(url, filename, retries):
    """
    Download the file at url and store it as filename
    """

    url_string = urlunparse(url)
    logging.debug("Fetching %s to %s", url_string, filename)

    useragent = "planex-fetch/%s" % pkg_resources.require("planex")[0].version

    # We need this because centos ships requests 2.8.0
    # It can be greatly simplified with requests >= 2.18.0
    headers = requests.utils.default_headers()
    headers.update({
        "user-agent": useragent,
    })

    # See if we have any additional custom headers
    add_custom_headers_for_url(url[1], headers)

    # Once we use requests >= 2.18.0, we should change this into
    # with requests.get ... as r:
    req = requests_retry_session(retries).get(url_string,
                                              headers=headers,
                                              timeout=30,
                                              stream=True)
    req.raise_for_status()

    with open(filename, 'wb') as out:
        shutil.copyfileobj(req.raw, out)
    best_effort_file_verify(filename)

    # pylint: disable=W0703
    # best-effort get git commitish
    try:
        repo = Repository(url_string)
        sha = repo.sha1
    except Exception:
        sha = None

    write_originfile(filename, url_string, sha)
示例#6
0
def generate_manifest(spec, link=None, pin=None):
    """Record info of all remote sources in the spec/link files.

    Args:
        spec (planex.spec.Spec): package's spec file
        link (dict/None): package's link file, if applicable

    Returns:
        (dict): manifest of the remote sources
                needed to create the SRPM.
        Format:
        {
            "spec": {
                "source0": {
                    "url": <source0_url>,
                    "sha1": <source0_sha1>
                },
                "source1": ...
                .
                .
            },
            "lnk": {
                "url": <lnk_url>,
                "sha1": <lnk_sha1>
            },
            "pin": {
                "url": <pin_url>,
                "sha1": <pin_sha1>
            }
        }
    """

    manifest = {'spec': {}}
    source_urls = [url for url in spec.source_urls() if '://' in url]

    for i, url in enumerate(source_urls):
        # Sources taken from artifactory do not have SHA1
        if 'repo.citrite.net' not in url:
            repo_ref = Repository(url)
            sha1 = repo_ref.sha1
        else:
            sha1 = None

        manifest['spec']['source' + str(i)] = {'url': url, 'sha1': sha1}

    if link is not None:
        repo_ref = Repository(link.url)
        sha1 = repo_ref.sha1
        manifest['lnk'] = {'url': link.url, 'sha1': sha1}

    if pin is not None:
        with open(pin) as pinfile:
            pin_dict = json.load(pinfile)
            url = pin_dict['URL']
            # pylint: disable=broad-except
            try:
                repo_ref = Repository(url)
                sha1 = repo_ref.sha1
            except Exception:
                sha1 = None
            manifest['pin'] = {'url': url, 'sha1': sha1}

    return manifest