Example #1
0
    def __init__(self, base, _from_transport=None):
        """Initialize the GIO transport and make sure the url is correct."""

        if not base.startswith('gio+'):
            raise ValueError(base)

        (scheme, netloc, path, params, query, fragment) = \
                urlparse.urlparse(base[len('gio+'):], allow_fragments=False)
        if '@' in netloc:
            user, netloc = netloc.rsplit('@', 1)
        #Seems it is not possible to list supported backends for GIO
        #so a hardcoded list it is then.
        gio_backends = ['dav', 'file', 'ftp', 'obex', 'sftp', 'ssh', 'smb']
        if scheme not in gio_backends:
            raise errors.InvalidURL(base,
                    extra="GIO support is only available for " + \
                    ', '.join(gio_backends))

        #Remove the username and password from the url we send to GIO
        #by rebuilding the url again.
        u = (scheme, netloc, path, '', '', '')
        self.url = urlparse.urlunparse(u)

        # And finally initialize super
        super(GioTransport, self).__init__(base,
                                           _from_transport=_from_transport)
Example #2
0
 def _resolve_via_xmlrpc(self, path, url, _request_factory):
     service = LaunchpadService.for_url(url)
     resolve = _request_factory(path)
     try:
         result = resolve.submit(service)
     except xmlrpclib.Fault, fault:
         raise errors.InvalidURL(path=url, extra=fault.faultString)
Example #3
0
 def _resolve(self,
              url,
              _request_factory=ResolveLaunchpadPathRequest,
              _lp_login=None):
     """Resolve the base URL for this transport."""
     result = urlsplit(url)
     # Perform an XMLRPC request to resolve the path
     lp_instance = result[1]
     if lp_instance == '':
         lp_instance = None
     elif lp_instance not in LaunchpadService.LAUNCHPAD_INSTANCE:
         raise errors.InvalidURL(path=url)
     resolve = _request_factory(result[2].strip('/'))
     service = LaunchpadService(lp_instance=lp_instance)
     try:
         result = resolve.submit(service)
     except xmlrpclib.Fault, fault:
         raise errors.InvalidURL(path=url, extra=fault.faultString)
 def for_url(cls, url, **kwargs):
     """Return the Launchpad service corresponding to the given URL."""
     result = urlsplit(url)
     lp_instance = result[1]
     if lp_instance == '':
         lp_instance = None
     elif lp_instance not in cls.LAUNCHPAD_INSTANCE:
         raise errors.InvalidURL(path=url)
     return cls(lp_instance=lp_instance, **kwargs)
Example #5
0
 def _expand_user(self, path, url, lp_login):
     if path.startswith('~/'):
         if lp_login is None:
             raise errors.InvalidURL(
                 path=url,
                 extra='Cannot resolve "~" to your username.'
                 ' See "bzr help launchpad-login"')
         path = '~' + lp_login + path[1:]
     return path
 def _guess_branch_path(self, branch_url, _request_factory=None):
     scheme, hostinfo, path = urlsplit(branch_url)[:3]
     if _request_factory is None:
         _request_factory = ResolveLaunchpadPathRequest
     if scheme == 'lp':
         resolve = _request_factory(path)
         try:
             result = resolve.submit(self)
         except xmlrpclib.Fault, fault:
             raise errors.InvalidURL(branch_url, str(fault))
         branch_url = result['urls'][0]
         path = urlsplit(branch_url)[2]
Example #7
0
    def _resolve(self,
                 url,
                 _request_factory=ResolveLaunchpadPathRequest,
                 _lp_login=None):
        """Resolve the base URL for this transport."""
        url, path = self._update_url_scheme(url)
        if _lp_login is None:
            _lp_login = get_lp_login()
        path = path.strip('/')
        path = self._expand_user(path, url, _lp_login)
        if _lp_login is not None:
            result = self._resolve_locally(path, url, _request_factory)
            if 'launchpad' in debug.debug_flags:
                local_res = result
                result = self._resolve_via_xmlrpc(path, url, _request_factory)
                trace.note(
                    gettext('resolution for {0}\n  local: {1}\n remote: {2}').
                    format(url, local_res['urls'], result['urls']))
        else:
            result = self._resolve_via_xmlrpc(path, url, _request_factory)

        if 'launchpad' in debug.debug_flags:
            trace.mutter("resolve_lp_path(%r) == %r", url, result)

        _warned_login = False
        for url in result['urls']:
            scheme, netloc, path, query, fragment = urlsplit(url)
            if self._requires_launchpad_login(scheme, netloc, path, query,
                                              fragment):
                # Only accept launchpad.net bzr+ssh URLs if we know
                # the user's Launchpad login:
                if _lp_login is not None:
                    break
                if _lp_login is None:
                    if not _warned_login:
                        trace.warning(
                            'You have not informed bzr of your Launchpad ID, and you must do this to\n'
                            'write to Launchpad or access private data.  See "bzr help launchpad-login".'
                        )
                        _warned_login = True
            else:
                # Use the URL if we can create a transport for it.
                try:
                    transport.get_transport(url)
                except (errors.PathError, errors.TransportError):
                    pass
                else:
                    break
        else:
            raise errors.InvalidURL(path=url, extra='no supported schemes')
        return url
 def __init__(
     self,
     branch_url,
     branch_name='',
     branch_title='',
     branch_description='',
     author_email='',
     product_name='',
 ):
     if not branch_url:
         raise errors.InvalidURL(
             branch_url, "You need to specify a non-empty branch URL.")
     self.branch_url = branch_url
     if branch_name:
         self.branch_name = branch_name
     else:
         self.branch_name = self._find_default_branch_name(self.branch_url)
     self.branch_title = branch_title
     self.branch_description = branch_description
     self.author_email = author_email
     self.product_name = product_name
Example #9
0
 def _update_url_scheme(self, url):
     # Do ubuntu: and debianlp: expansions.
     scheme, netloc, path, query, fragment = urlsplit(url)
     if scheme in ('ubuntu', 'debianlp'):
         if scheme == 'ubuntu':
             distro = 'ubuntu'
             distro_series = _ubuntu_series_shortcuts
         elif scheme == 'debianlp':
             distro = 'debian'
             # No shortcuts for Debian distroseries.
             distro_series = {}
         else:
             raise AssertionError('scheme should be ubuntu: or debianlp:')
         # Split the path.  It's either going to be 'project' or
         # 'series/project', but recognize that it may be a series we don't
         # know about.
         path_parts = path.split('/')
         if len(path_parts) == 1:
             # It's just a project name.
             lp_url_template = 'lp:%(distro)s/%(project)s'
             project = path_parts[0]
             series = None
         elif len(path_parts) == 2:
             # It's a series and project.
             lp_url_template = 'lp:%(distro)s/%(series)s/%(project)s'
             series, project = path_parts
         else:
             # There are either 0 or > 2 path parts, neither of which is
             # supported for these schemes.
             raise errors.InvalidURL('Bad path: %s' % url)
         # Expand any series shortcuts, but keep unknown series.
         series = distro_series.get(series, series)
         # Hack the url and let the following do the final resolution.
         url = lp_url_template % dict(
             distro=distro, series=series, project=project)
         scheme, netloc, path, query, fragment = urlsplit(url)
     return url, path
Example #10
0
class LaunchpadDirectory(object):
    def _requires_launchpad_login(self, scheme, netloc, path, query, fragment):
        """Does the URL require a Launchpad login in order to be reached?

        The URL is specified by its parsed components, as returned from
        urlsplit.
        """
        return (scheme in ('bzr+ssh', 'sftp')
                and (netloc.endswith('launchpad.net')
                     or netloc.endswith('launchpad.dev')))

    def look_up(self, name, url):
        """See DirectoryService.look_up"""
        return self._resolve(url)

    def _resolve(self,
                 url,
                 _request_factory=ResolveLaunchpadPathRequest,
                 _lp_login=None):
        """Resolve the base URL for this transport."""
        result = urlsplit(url)
        # Perform an XMLRPC request to resolve the path
        lp_instance = result[1]
        if lp_instance == '':
            lp_instance = None
        elif lp_instance not in LaunchpadService.LAUNCHPAD_INSTANCE:
            raise errors.InvalidURL(path=url)
        resolve = _request_factory(result[2].strip('/'))
        service = LaunchpadService(lp_instance=lp_instance)
        try:
            result = resolve.submit(service)
        except xmlrpclib.Fault, fault:
            raise errors.InvalidURL(path=url, extra=fault.faultString)

        if 'launchpad' in debug.debug_flags:
            trace.mutter("resolve_lp_path(%r) == %r", path, result)

        if _lp_login is None:
            _lp_login = get_lp_login()
        _warned_login = False
        for url in result['urls']:
            scheme, netloc, path, query, fragment = urlsplit(url)
            if self._requires_launchpad_login(scheme, netloc, path, query,
                                              fragment):
                # Only accept launchpad.net bzr+ssh URLs if we know
                # the user's Launchpad login:
                if _lp_login is None:
                    if not _warned_login:
                        trace.warning(
                            'You have not informed bzr of your '
                            'launchpad login. If you are attempting a\n'
                            'write operation and it fails, run '
                            '"bzr launchpad-login YOUR_ID" and try again.')
                        _warned_login = True
                    continue
                url = urlunsplit((scheme, '%s@%s' % (_lp_login, netloc), path,
                                  query, fragment))
                break
            else:
                # Use the URL if we can create a transport for it.
                try:
                    get_transport(url)
                except (errors.PathError, errors.TransportError):
                    pass
                else:
                    break
        else:
            raise errors.InvalidURL(path=url, extra='no supported schemes')
        return url
Example #11
0
 def __init__(self, path):
     if not path:
         raise errors.InvalidURL(path=path,
                                 extra="You must specify a project.")
     self.path = path
Example #12
0
 def _relpath_to_url(self, relpath):
     full_url = urlutils.join(self.url, relpath)
     if isinstance(full_url, unicode):
         raise errors.InvalidURL(full_url)
     return full_url