def makeClient(self, expiry_time=None, seen_new_branch_hook=None):
        """Make a `BranchFileSystemClient`.

        The created client interacts with the InMemoryFrontend.
        """
        return BranchFileSystemClient(
            self._xmlrpc_client, self.user.id, expiry_time=expiry_time,
            seen_new_branch_hook=seen_new_branch_hook,
            _now=self.fake_time.now)
Example #2
0
    def __init__(self,
                 scheme,
                 codehosting_api,
                 user_id,
                 seen_new_branch_hook=None):
        """Construct a LaunchpadServer.

        :param scheme: The URL scheme to use.
        :param codehosting_api: An XML-RPC client that implements callRemote.
        :param user_id: The database ID for the user who is accessing
            branches.
        :param seen_new_branch_hook: A callable that will be called once for
            each branch accessed via this server.
        """
        AsyncVirtualServer.__init__(self, scheme)
        self._branchfs_client = BranchFileSystemClient(
            codehosting_api,
            user_id,
            seen_new_branch_hook=seen_new_branch_hook)
        self._is_start_server = False
Example #3
0
class _BaseLaunchpadServer(AsyncVirtualServer):
    """Bazaar `Server` for translating Lanuchpad paths via XML-RPC.

    This server provides facilities for transports that use a virtual
    filesystem, backed by an XML-RPC server.

    For more information, see the module docstring.

    :ivar _branchfs_client: An object that has a method 'translatePath' that
        returns a Deferred that fires information about how a path can be
        translated into a transport. See `IBranchFilesystem['translatePath']`.

    :ivar _transport_dispatch: An `ITransportDispatch` provider used to
        convert the data from the branchfs client into an actual transport and
        path on that transport.
    """

    def __init__(self, scheme, codehosting_api, user_id, seen_new_branch_hook=None):
        """Construct a LaunchpadServer.

        :param scheme: The URL scheme to use.
        :param codehosting_api: An XML-RPC client that implements callRemote.
        :param user_id: The database ID for the user who is accessing
            branches.
        :param seen_new_branch_hook: A callable that will be called once for
            each branch accessed via this server.
        """
        AsyncVirtualServer.__init__(self, scheme)
        self._branchfs_client = BranchFileSystemClient(
            codehosting_api, user_id, seen_new_branch_hook=seen_new_branch_hook
        )
        self._is_start_server = False

    def translateVirtualPath(self, virtual_url_fragment):
        """See `AsyncVirtualServer.translateVirtualPath`.

        Call 'translatePath' on the branchfs client with the fragment and then
        use 'makeTransport' on the _transport_dispatch to translate that
        result into a transport and trailing path.
        """
        deferred = self._branchfs_client.translatePath("/" + virtual_url_fragment)

        def path_not_translated(fail):
            trap_fault(fail, faults.PathTranslationError, faults.PermissionDenied)
            return failure.Failure(NoSuchFile(virtual_url_fragment))

        def unknown_transport_type(fail):
            fail.trap(UnknownTransportType)
            return failure.Failure(NoSuchFile(virtual_url_fragment))

        deferred.addCallbacks(no_traceback_failures(self._transport_dispatch.makeTransport), path_not_translated)
        deferred.addErrback(unknown_transport_type)
        return deferred
Example #4
0
    def __init__(self, scheme, codehosting_api, user_id, seen_new_branch_hook=None):
        """Construct a LaunchpadServer.

        :param scheme: The URL scheme to use.
        :param codehosting_api: An XML-RPC client that implements callRemote.
        :param user_id: The database ID for the user who is accessing
            branches.
        :param seen_new_branch_hook: A callable that will be called once for
            each branch accessed via this server.
        """
        AsyncVirtualServer.__init__(self, scheme)
        self._branchfs_client = BranchFileSystemClient(
            codehosting_api, user_id, seen_new_branch_hook=seen_new_branch_hook
        )
        self._is_start_server = False
Example #5
0
class _BaseLaunchpadServer(AsyncVirtualServer):
    """Bazaar `Server` for translating Lanuchpad paths via XML-RPC.

    This server provides facilities for transports that use a virtual
    filesystem, backed by an XML-RPC server.

    For more information, see the module docstring.

    :ivar _branchfs_client: An object that has a method 'translatePath' that
        returns a Deferred that fires information about how a path can be
        translated into a transport. See `IBranchFilesystem['translatePath']`.

    :ivar _transport_dispatch: An `ITransportDispatch` provider used to
        convert the data from the branchfs client into an actual transport and
        path on that transport.
    """
    def __init__(self,
                 scheme,
                 codehosting_api,
                 user_id,
                 seen_new_branch_hook=None):
        """Construct a LaunchpadServer.

        :param scheme: The URL scheme to use.
        :param codehosting_api: An XML-RPC client that implements callRemote.
        :param user_id: The database ID for the user who is accessing
            branches.
        :param seen_new_branch_hook: A callable that will be called once for
            each branch accessed via this server.
        """
        AsyncVirtualServer.__init__(self, scheme)
        self._branchfs_client = BranchFileSystemClient(
            codehosting_api,
            user_id,
            seen_new_branch_hook=seen_new_branch_hook)
        self._is_start_server = False

    def translateVirtualPath(self, virtual_url_fragment):
        """See `AsyncVirtualServer.translateVirtualPath`.

        Call 'translatePath' on the branchfs client with the fragment and then
        use 'makeTransport' on the _transport_dispatch to translate that
        result into a transport and trailing path.
        """
        deferred = self._branchfs_client.translatePath('/' +
                                                       virtual_url_fragment)

        def path_not_translated(fail):
            trap_fault(fail, faults.PathTranslationError,
                       faults.PermissionDenied)
            return failure.Failure(NoSuchFile(virtual_url_fragment))

        def unknown_transport_type(fail):
            fail.trap(UnknownTransportType)
            return failure.Failure(NoSuchFile(virtual_url_fragment))

        deferred.addCallbacks(
            no_traceback_failures(self._transport_dispatch.makeTransport),
            path_not_translated)
        deferred.addErrback(unknown_transport_type)
        return deferred