~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/__init__.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-02-11 04:02:41 UTC
  • mfrom: (5017.2.2 tariff)
  • Revision ID: pqm@pqm.ubuntu.com-20100211040241-w6n021dz0uus341n
(mbp) add import-tariff tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008, 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
47
47
""")
48
48
 
49
49
from bzrlib.symbol_versioning import (
 
50
        deprecated_method,
 
51
        deprecated_function,
50
52
        DEPRECATED_PARAMETER,
51
53
        )
52
54
from bzrlib.trace import (
537
539
 
538
540
        This function will only be defined for Transports which have a
539
541
        physical local filesystem representation.
540
 
 
541
 
        :raises errors.NotLocalUrl: When no local path representation is
542
 
            available.
543
542
        """
544
543
        raise errors.NotLocalUrl(self.abspath(relpath))
545
544
 
1061
1060
        """
1062
1061
        source = self.clone(from_relpath)
1063
1062
        target = self.clone(to_relpath)
1064
 
 
1065
 
        # create target directory with the same rwx bits as source.
1066
 
        # use mask to ensure that bits other than rwx are ignored.
1067
 
        stat = self.stat(from_relpath)
1068
 
        target.mkdir('.', stat.st_mode & 0777)
 
1063
        target.mkdir('.')
1069
1064
        source.copy_tree_to_transport(target)
1070
1065
 
1071
1066
    def copy_tree_to_transport(self, to_transport):
1207
1202
        count = self._iterate_over(relpaths, gather, pb, 'stat', expand=False)
1208
1203
        return stats
1209
1204
 
1210
 
    def readlink(self, relpath):
1211
 
        """Return a string representing the path to which the symbolic link points."""
1212
 
        raise errors.TransportNotPossible("Dereferencing symlinks is not supported on %s" % self)
1213
 
 
1214
 
    def hardlink(self, source, link_name):
1215
 
        """Create a hardlink pointing to source named link_name."""
1216
 
        raise errors.TransportNotPossible("Hard links are not supported on %s" % self)
1217
 
 
1218
 
    def symlink(self, source, link_name):
1219
 
        """Create a symlink pointing to source named link_name."""
1220
 
        raise errors.TransportNotPossible("Symlinks are not supported on %s" % self)
1221
 
 
1222
1205
    def listable(self):
1223
1206
        """Return True if this store supports listing."""
1224
1207
        raise NotImplementedError(self.listable)
1286
1269
        # should be asked to ConnectedTransport only.
1287
1270
        return None
1288
1271
 
1289
 
    def disconnect(self):
1290
 
        # This is really needed for ConnectedTransport only, but it's easier to
1291
 
        # have Transport do nothing than testing that the disconnect should be
1292
 
        # asked to ConnectedTransport only.
1293
 
        pass
1294
 
 
1295
1272
    def _redirected_to(self, source, target):
1296
1273
        """Returns a transport suitable to re-issue a redirected request.
1297
1274
 
1556
1533
            transport = self.__class__(other_base, _from_transport=self)
1557
1534
        return transport
1558
1535
 
1559
 
    def disconnect(self):
1560
 
        """Disconnect the transport.
1561
 
 
1562
 
        If and when required the transport willl reconnect automatically.
1563
 
        """
1564
 
        raise NotImplementedError(self.disconnect)
1565
 
 
 
1536
 
 
1537
# We try to recognize an url lazily (ignoring user, password, etc)
 
1538
_urlRE = re.compile(r'^(?P<proto>[^:/\\]+)://(?P<rest>.*)$')
1566
1539
 
1567
1540
def get_transport(base, possible_transports=None):
1568
1541
    """Open a transport to access a URL or directory.
1582
1555
    base = directories.dereference(base)
1583
1556
 
1584
1557
    def convert_path_to_url(base, error_str):
1585
 
        if urlutils.is_url(base):
 
1558
        m = _urlRE.match(base)
 
1559
        if m:
1586
1560
            # This looks like a URL, but we weren't able to
1587
1561
            # instantiate it as such raise an appropriate error
1588
1562
            # FIXME: we have a 'error_str' unused and we use last_err below
1689
1663
class Server(object):
1690
1664
    """A Transport Server.
1691
1665
 
1692
 
    The Server interface provides a server for a given transport type.
 
1666
    The Server interface provides a server for a given transport. We use
 
1667
    these servers as loopback testing tools. For any given transport the
 
1668
    Servers it provides must either allow writing, or serve the contents
 
1669
    of os.getcwdu() at the time start_server is called.
 
1670
 
 
1671
    Note that these are real servers - they must implement all the things
 
1672
    that we want bzr transports to take advantage of.
1693
1673
    """
1694
1674
 
1695
1675
    def start_server(self):
1698
1678
    def stop_server(self):
1699
1679
        """Remove the server and cleanup any resources it owns."""
1700
1680
 
 
1681
    def get_url(self):
 
1682
        """Return a url for this server.
 
1683
 
 
1684
        If the transport does not represent a disk directory (i.e. it is
 
1685
        a database like svn, or a memory only transport, it should return
 
1686
        a connection to a newly established resource for this Server.
 
1687
        Otherwise it should return a url that will provide access to the path
 
1688
        that was os.getcwdu() when start_server() was called.
 
1689
 
 
1690
        Subsequent calls will return the same resource.
 
1691
        """
 
1692
        raise NotImplementedError
 
1693
 
 
1694
    def get_bogus_url(self):
 
1695
        """Return a url for this protocol, that will fail to connect.
 
1696
 
 
1697
        This may raise NotImplementedError to indicate that this server cannot
 
1698
        provide bogus urls.
 
1699
        """
 
1700
        raise NotImplementedError
 
1701
 
1701
1702
 
1702
1703
# None is the default transport, for things with no url scheme
1703
1704
register_transport_proto('file://',
1749
1750
register_lazy_transport('ftp://', 'bzrlib.transport.ftp', 'FtpTransport')
1750
1751
register_transport_proto('aftp://', help="Access using active FTP.")
1751
1752
register_lazy_transport('aftp://', 'bzrlib.transport.ftp', 'FtpTransport')
1752
 
register_transport_proto('gio+', help="Access using any GIO supported protocols.")
1753
 
register_lazy_transport('gio+', 'bzrlib.transport.gio_transport', 'GioTransport')
1754
 
 
1755
 
 
1756
 
# Default to trying GSSAPI authentication (if the kerberos module is
1757
 
# available)
1758
 
register_transport_proto('ftp+gssapi://', register_netloc=True)
1759
 
register_transport_proto('aftp+gssapi://', register_netloc=True)
1760
 
register_transport_proto('ftp+nogssapi://', register_netloc=True)
1761
 
register_transport_proto('aftp+nogssapi://', register_netloc=True)
1762
 
register_lazy_transport('ftp+gssapi://', 'bzrlib.transport.ftp._gssapi',
1763
 
                        'GSSAPIFtpTransport')
1764
 
register_lazy_transport('aftp+gssapi://', 'bzrlib.transport.ftp._gssapi',
1765
 
                        'GSSAPIFtpTransport')
1766
 
register_lazy_transport('ftp://', 'bzrlib.transport.ftp._gssapi',
1767
 
                        'GSSAPIFtpTransport')
1768
 
register_lazy_transport('aftp://', 'bzrlib.transport.ftp._gssapi',
1769
 
                        'GSSAPIFtpTransport')
1770
 
register_lazy_transport('ftp+nogssapi://', 'bzrlib.transport.ftp',
1771
 
                        'FtpTransport')
1772
 
register_lazy_transport('aftp+nogssapi://', 'bzrlib.transport.ftp',
1773
 
                        'FtpTransport')
 
1753
 
 
1754
try:
 
1755
    import kerberos
 
1756
    kerberos_available = True
 
1757
except ImportError:
 
1758
    kerberos_available = False
 
1759
 
 
1760
if kerberos_available:
 
1761
    # Default to trying GSSAPI authentication (if the kerberos module is
 
1762
    # available)
 
1763
    register_transport_proto('ftp+gssapi://', register_netloc=True)
 
1764
    register_lazy_transport('ftp+gssapi://', 'bzrlib.transport.ftp._gssapi',
 
1765
                            'GSSAPIFtpTransport')
 
1766
    register_transport_proto('aftp+gssapi://', register_netloc=True)
 
1767
    register_lazy_transport('aftp+gssapi://', 'bzrlib.transport.ftp._gssapi',
 
1768
                            'GSSAPIFtpTransport')
 
1769
    register_transport_proto('ftp+nogssapi://', register_netloc=True)
 
1770
    register_transport_proto('aftp+nogssapi://', register_netloc=True)
 
1771
 
 
1772
    register_lazy_transport('ftp://', 'bzrlib.transport.ftp._gssapi',
 
1773
                            'GSSAPIFtpTransport')
 
1774
    register_lazy_transport('aftp://', 'bzrlib.transport.ftp._gssapi',
 
1775
                            'GSSAPIFtpTransport')
 
1776
    register_lazy_transport('ftp+nogssapi://', 'bzrlib.transport.ftp',
 
1777
                            'FtpTransport')
 
1778
    register_lazy_transport('aftp+nogssapi://', 'bzrlib.transport.ftp',
 
1779
                            'FtpTransport')
1774
1780
 
1775
1781
register_transport_proto('memory://')
1776
1782
register_lazy_transport('memory://', 'bzrlib.transport.memory',
1852
1858
 
1853
1859
 
1854
1860
transport_server_registry = registry.Registry()
1855
 
transport_server_registry.register_lazy('bzr', 'bzrlib.smart.server',
 
1861
transport_server_registry.register_lazy('bzr', 'bzrlib.smart.server', 
1856
1862
    'serve_bzr', help="The Bazaar smart server protocol over TCP. (default port: 4155)")
1857
1863
transport_server_registry.default_key = 'bzr'