Ejemplo n.º 1
0
 def wrapped(*args, **kwargs):
     try:
         return fn(*args, **kwargs)
     except requests.exceptions.HTTPError as e:
         if e.response.status_code == requests.codes.unauthorized:
             raise access_common.Unavailable(message)
         else:
             raise
Ejemplo n.º 2
0
 def _getTags(self):
     if self.tags is None:
         try:
             self.tags = _getTags(self.repo).items()
         except github.UnknownObjectException as e:
             raise access_common.Unavailable(
                 'could not locate github component "%s", either the name is misspelt, you do not have access to it, or it does not exist'
                 % self.repo)
     return self.tags
Ejemplo n.º 3
0
def satisfyFromAvailable(name, available, type='module'):
    if name in available and available[name]:
        logger.debug('satisfy %s from already installed %ss' % (name, type))
        r = available[name]
        if name != r.getName():
            raise access_common.Unavailable(
                '%s %s was installed as different name %s in %s' %
                (type, r.getName(), name, r.path))
        return r
    return None
Ejemplo n.º 4
0
def _listVersions(namespace, name):
    sources = _getSources()

    registry_urls = [
        s['url'] for s in sources if 'type' in s and s['type'] == 'registry'
    ]

    # look in the public registry last
    registry_urls.append(Registry_Base_URL)

    versions = []

    for registry in registry_urls:
        # list versions of the package:
        url = '%s/%s/%s/versions' % (registry, namespace, name)

        request_headers = _headersForRegistry(registry)

        logger.debug("GET %s, %s", url, request_headers)
        response = requests.get(url, headers=request_headers)

        if response.status_code == 404:
            continue

        # raise any other HTTP errors
        response.raise_for_status()

        for x in ordered_json.loads(response.text):
            rtv = RegistryThingVersion(x, namespace, name, registry=registry)
            if not rtv in versions:
                versions.append(rtv)

    if not len(versions):
        raise access_common.Unavailable(
            ('%s does not exist in the %s registry. ' +
             'Check that the name is correct, and that it has been published.')
            % (name, namespace))

    return versions
Ejemplo n.º 5
0
def latestSuitableVersion(name,
                          version_required,
                          registry='modules',
                          quiet=False):
    ''' Return a RemoteVersion object representing the latest suitable
        version of the named component or target.

        All RemoteVersion objects have a .unpackInto(directory) method.
    '''

    remote_component = remoteComponentFor(name, version_required, registry)

    if quiet:
        logger.debug('get versions for ' + name)
    else:
        logger.info('get versions for ' + name)

    if remote_component.remoteType() == 'registry':
        logger.debug('satisfy %s from %s registry' % (name, registry))
        vers = remote_component.availableVersions()
        spec = remote_component.versionSpec()
        v = spec.select(vers)
        logger.debug("%s selected %s from %s", spec, v, vers)
        if not v:
            raise access_common.Unavailable(
                'The %s registry does not provide a version of "%s" matching "%s"'
                % (registry, name, spec))
        return v
    elif remote_component.remoteType() == 'github':
        logger.debug('satisfy %s from github url' % name)
        spec = remote_component.versionSpec()
        if spec:
            vers = remote_component.availableVersions()
            if not len(vers):
                logger.warning(
                    'Github repository "%s" has no tagged versions, default branch will be used'
                    % (remote_component.repo))
                vers = [remote_component.tipVersion()]
            v = spec.select(vers)
            logger.debug("%s selected %s from %s", spec, v, vers)
            if not v:
                raise access_common.Unavailable(
                    'Github repository "%s" does not provide a version matching "%s"'
                    % (remote_component.repo, remote_component.spec))
            return v
        else:
            # we're fetching a specific tag, or the head of a branch:
            v = tagOrBranchVersion(remote_component.tagOrBranchSpec(),
                                   remote_component.availableTags(),
                                   remote_component.availableBranches(), name)
            if v:
                return v
            raise access_common.Unavailable(
                'Github repository "%s" does not have any tags or branches matching "%s"'
                % (version_required, remote_component.tagOrBranchSpec()))

    elif remote_component.remoteType() in ('git', 'hg'):
        clone_type = remote_component.remoteType()
        logger.debug('satisfy %s from %s url' % (name, clone_type))
        local_clone = remote_component.clone()
        if not local_clone:
            raise access_common.Unavailable(
                'Failed to clone %s URL %s to satisfy dependency %s' %
                (clone_type, version_required, name))
        spec = remote_component.versionSpec()
        if spec:
            vers = local_clone.availableVersions()
            if not len(vers):
                logger.warning(
                    '%s repository "%s" has no tagged versions, default branch will be used'
                    % (clone_type, version_required))
                vers = [local_clone.tipVersion()]
            v = spec.select(vers)
            logger.debug("%s selected %s from %s", spec, v, vers)
            if not v:
                raise access_common.Unavailable(
                    '%s repository "%s" does not provide a version matching "%s"'
                    % (clone_type, version_required, remote_component.spec))
            return v
        elif remote_component.remoteType() == 'git':
            v = tagOrBranchVersion(remote_component.tagOrBranchSpec(),
                                   local_clone.availableTags(),
                                   local_clone.availableBranches(), name)
            if v:
                return v
            raise access_common.Unavailable(
                '%s repository "%s" does not have any tags or branches matching "%s"'
                % (clone_type, version_required, spec))
        else:
            raise Exception(
                "invalid spec for hg source: tags/branches are not supported yet!"
            )

    # !!! FIXME: next: generic http urls to tarballs

    return None