Esempio n. 1
0
def remoteComponentFor(name, version_required, registry='modules'):
    ''' Return a RemoteComponent sublclass for the specified component name and
        source url (or version specification)
        Raises an exception if any arguments are invalid.
    '''

    try:
        vs = sourceparse.parseSourceURL(version_required)
    except ValueError as e:
        raise access_common.Unavailable(
            '%s' % (e)
        )

    if vs.source_type == 'registry':
        if registry not in ('modules', 'targets'):
            raise Exception('no known registry namespace "%s"' % registry)
        return registry_access.RegistryThing.createFromSource(
            vs, name, registry=registry
        )
    elif vs.source_type == 'github':
        return github_access.GithubComponent.createFromSource(vs, name)
    elif vs.source_type == 'git':
        return git_access.GitComponent.createFromSource(vs, name)
    elif vs.source_type == 'hg':
        return hg_access.HGComponent.createFromSource(vs, name)
    else:
        raise Exception('unsupported module source: "%s"' % vs.source_type)
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
0
def satisfyFromAvailable(name, available, type='module'):
    # we don't need to pass the shrinkwrap to this function because if this
    # function finds a module we have already processed its dependencies for
    # another module - so the shrinkwrap could not be applied.
    # !!! FIXME: what about issuing warnings for things that don't match the
    # shrinkwrap though?
    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
Esempio n. 5
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
Esempio n. 6
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

            # we have passed a specific commit ID:
            v = remote_component.commitVersion()
            if v:
                return v

            raise access_common.Unavailable(
                'Github repository "%s" does not have any tags, branches or commits 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

            # we have passed a specific commit ID:
            v = local_clone.commitVersion(remote_component.tagOrBranchSpec())
            if v:
                return v

            raise access_common.Unavailable(
                '%s repository "%s" does not have any tags, branches or commits 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
Esempio n. 7
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':
        '''This function is changed from the default yotta functionality.
        This now raises an error if a module is not found locally (this 
        condition should not ever happen if the CLI is working correctly.
        All KubOS modules should be in the KubOS source download and linked
        locally into each project rather than fetched from a 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"' %
            (registry, name))
    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