Exemple #1
0
    def translate(self, check_build_environment: bool = True) -> str:
        """
        Translate repository location according to their URI type

        Depending on the URI type the provided location needs to
        be adapted e.g loop mounted in case of an ISO or updated
        by the service URL in case of an open buildservice project
        name

        :raises KiwiUriStyleUnknown: if the uri scheme can't be detected, is
            unknown or it is inconsistent with the build environment
        :param bool check_build_environment: specify if the uri translation
            should depend on the environment the build is called in. As of
            today this only effects the translation result if the image
            build happens inside of the Open Build Service

        :return: translated repository location

        :rtype: str
        """
        uri = urlparse(self.uri)
        if not uri.scheme:
            raise KiwiUriStyleUnknown(
                'URI scheme not detected {uri}'.format(uri=self.uri))
        elif uri.scheme == 'obs':
            if check_build_environment and Defaults.is_buildservice_worker():
                return self._buildservice_path(name=''.join(
                    [uri.netloc, uri.path]).replace(':/', ':'),
                                               fragment=uri.fragment,
                                               urischeme=uri.scheme)
            else:
                return self._obs_project_download_link(''.join(
                    [uri.netloc, uri.path]).replace(':/', ':'))
        elif uri.scheme == 'obsrepositories':
            if not Defaults.is_buildservice_worker():
                raise KiwiUriStyleUnknown(
                    'Only the buildservice can use the {0} schema'.format(
                        uri.scheme))
            return self._buildservice_path(name=''.join([uri.netloc, uri.path
                                                         ]).replace(':/', ':'),
                                           fragment=uri.fragment,
                                           urischeme=uri.scheme)
        elif uri.scheme == 'dir':
            return self._local_path(uri.path)
        elif uri.scheme == 'file':
            return self._local_path(uri.path)
        elif uri.scheme == 'iso':
            return self._iso_mount_path(uri.path)
        elif uri.scheme.startswith('http') or uri.scheme == 'ftp':
            if self._get_credentials_uri() or not uri.query:
                return ''.join([uri.scheme, '://', uri.netloc, uri.path])
            else:
                return ''.join(
                    [uri.scheme, '://', uri.netloc, uri.path, '?', uri.query])
        else:
            raise KiwiUriStyleUnknown('URI schema %s not supported' % self.uri)
Exemple #2
0
    def translate(self):
        """
        Translate repository location according to their URI type

        Depending on the URI type the provided location needs to
        be adapted e.g loop mounted in case of an ISO or updated
        by the service URL in case of an open buildservice project
        name
        """
        uri = urlparse(self.uri)
        if not uri.scheme:
            raise KiwiUriStyleUnknown(
                'URI scheme not detected {uri}'.format(uri=self.uri))

        if uri.scheme == 'obs' and self.repo_type == 'yast2':
            return self._obs_distribution(''.join([uri.netloc, uri.path]))
        elif uri.scheme == 'obs':
            return self._obs_project(''.join([uri.netloc, uri.path]))
        elif uri.scheme == 'obsrepositories':
            return self._suse_buildservice_path(name=''.join(
                [uri.netloc, uri.path]),
                                                fragment=uri.fragment,
                                                urischeme=uri.scheme)
        elif uri.scheme == 'ibs':
            return self._ibs_project(''.join([uri.netloc, uri.path]))
        elif uri.scheme == 'dir':
            return self._local_path(uri.path)
        elif uri.scheme == 'file':
            return self._local_path(uri.path)
        elif uri.scheme == 'iso':
            return self._iso_mount_path(uri.path)
        elif uri.scheme == 'suse':
            return self._suse_buildservice_path(name=''.join(
                [uri.netloc, uri.path]),
                                                fragment=uri.fragment,
                                                urischeme=uri.scheme)
        elif uri.scheme == 'http' or uri.scheme == 'https' or uri.scheme == 'ftp':
            return ''.join([uri.scheme, '://', uri.netloc, uri.path])
        else:
            raise KiwiUriStyleUnknown('URI schema %s not supported' % self.uri)
Exemple #3
0
    def is_remote(self):
        """
        Check if URI is a remote or local location

        :rtype: bool
        """
        uri = urlparse(self.uri)
        if not uri.scheme:
            raise KiwiUriStyleUnknown('URI scheme not detected %s' % self.uri)
        if uri.scheme in self.remote_uri_types:
            return True
        else:
            if uri.scheme in self.local_uri_type:
                return False
            else:
                raise KiwiUriTypeUnknown('URI type %s unknown' % uri.scheme)
Exemple #4
0
    def is_remote(self) -> bool:
        """
        Check if URI is a remote or local location

        :return: True|False

        :rtype: bool
        """
        uri = urlparse(self.uri)
        if not uri.scheme:
            raise KiwiUriStyleUnknown('URI scheme not detected %s' % self.uri)
        if uri.scheme == 'obs' and Defaults.is_buildservice_worker():
            return False
        elif uri.scheme in self.remote_uri_types:
            return True
        elif uri.scheme in self.local_uri_type:
            return False
        else:
            raise KiwiUriTypeUnknown('URI type %s unknown' % uri.scheme)