~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/__init__.py

  • Committer: Danny van Heumen
  • Date: 2010-03-09 21:42:11 UTC
  • mto: (4634.139.5 2.0)
  • mto: This revision was merged to the branch mainline in revision 5160.
  • Revision ID: danny@dannyvanheumen.nl-20100309214211-iqh42x6qcikgd9p3
Reverted now-useless TODO list.

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 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 (
88
90
                modules.add(factory._module_name)
89
91
            else:
90
92
                modules.add(factory._obj.__module__)
91
 
    # Add chroot and pathfilter directly, because there is no handler
92
 
    # registered for it.
 
93
    # Add chroot directly, because there is no handler registered for it.
93
94
    modules.add('bzrlib.transport.chroot')
94
 
    modules.add('bzrlib.transport.pathfilter')
95
95
    result = list(modules)
96
96
    result.sort()
97
97
    return result
106
106
    register_transport_provider( ) ( and the "lazy" variant )
107
107
 
108
108
    This is needed because:
109
 
    a) a single provider can support multiple protocols ( like the ftp
 
109
    a) a single provider can support multple protcol ( like the ftp
110
110
    provider which supports both the ftp:// and the aftp:// protocols )
111
111
    b) a single protocol can have multiple providers ( like the http://
112
112
    protocol which is supported by both the urllib and pycurl provider )
537
537
 
538
538
        This function will only be defined for Transports which have a
539
539
        physical local filesystem representation.
540
 
 
541
 
        :raises errors.NotLocalUrl: When no local path representation is
542
 
            available.
543
540
        """
544
541
        raise errors.NotLocalUrl(self.abspath(relpath))
545
542
 
1061
1058
        """
1062
1059
        source = self.clone(from_relpath)
1063
1060
        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)
 
1061
        target.mkdir('.')
1069
1062
        source.copy_tree_to_transport(target)
1070
1063
 
1071
1064
    def copy_tree_to_transport(self, to_transport):
1207
1200
        count = self._iterate_over(relpaths, gather, pb, 'stat', expand=False)
1208
1201
        return stats
1209
1202
 
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
1203
    def listable(self):
1223
1204
        """Return True if this store supports listing."""
1224
1205
        raise NotImplementedError(self.listable)
1286
1267
        # should be asked to ConnectedTransport only.
1287
1268
        return None
1288
1269
 
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
1270
    def _redirected_to(self, source, target):
1296
1271
        """Returns a transport suitable to re-issue a redirected request.
1297
1272
 
1556
1531
            transport = self.__class__(other_base, _from_transport=self)
1557
1532
        return transport
1558
1533
 
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
 
 
 
1534
 
 
1535
# We try to recognize an url lazily (ignoring user, password, etc)
 
1536
_urlRE = re.compile(r'^(?P<proto>[^:/\\]+)://(?P<rest>.*)$')
1566
1537
 
1567
1538
def get_transport(base, possible_transports=None):
1568
1539
    """Open a transport to access a URL or directory.
1582
1553
    base = directories.dereference(base)
1583
1554
 
1584
1555
    def convert_path_to_url(base, error_str):
1585
 
        if urlutils.is_url(base):
 
1556
        m = _urlRE.match(base)
 
1557
        if m:
1586
1558
            # This looks like a URL, but we weren't able to
1587
1559
            # instantiate it as such raise an appropriate error
1588
1560
            # FIXME: we have a 'error_str' unused and we use last_err below
1689
1661
class Server(object):
1690
1662
    """A Transport Server.
1691
1663
 
1692
 
    The Server interface provides a server for a given transport type.
 
1664
    The Server interface provides a server for a given transport. We use
 
1665
    these servers as loopback testing tools. For any given transport the
 
1666
    Servers it provides must either allow writing, or serve the contents
 
1667
    of os.getcwdu() at the time setUp is called.
 
1668
 
 
1669
    Note that these are real servers - they must implement all the things
 
1670
    that we want bzr transports to take advantage of.
1693
1671
    """
1694
1672
 
1695
 
    def start_server(self):
 
1673
    def setUp(self):
1696
1674
        """Setup the server to service requests."""
1697
1675
 
1698
 
    def stop_server(self):
 
1676
    def tearDown(self):
1699
1677
        """Remove the server and cleanup any resources it owns."""
1700
1678
 
 
1679
    def get_url(self):
 
1680
        """Return a url for this server.
 
1681
 
 
1682
        If the transport does not represent a disk directory (i.e. it is
 
1683
        a database like svn, or a memory only transport, it should return
 
1684
        a connection to a newly established resource for this Server.
 
1685
        Otherwise it should return a url that will provide access to the path
 
1686
        that was os.getcwdu() when setUp() was called.
 
1687
 
 
1688
        Subsequent calls will return the same resource.
 
1689
        """
 
1690
        raise NotImplementedError
 
1691
 
 
1692
    def get_bogus_url(self):
 
1693
        """Return a url for this protocol, that will fail to connect.
 
1694
 
 
1695
        This may raise NotImplementedError to indicate that this server cannot
 
1696
        provide bogus urls.
 
1697
        """
 
1698
        raise NotImplementedError
 
1699
 
1701
1700
 
1702
1701
# None is the default transport, for things with no url scheme
1703
1702
register_transport_proto('file://',
1749
1748
register_lazy_transport('ftp://', 'bzrlib.transport.ftp', 'FtpTransport')
1750
1749
register_transport_proto('aftp://', help="Access using active FTP.")
1751
1750
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')
 
1751
 
 
1752
try:
 
1753
    import kerberos
 
1754
    kerberos_available = True
 
1755
except ImportError:
 
1756
    kerberos_available = False
 
1757
 
 
1758
if kerberos_available:
 
1759
    # Default to trying GSSAPI authentication (if the kerberos module is
 
1760
    # available)
 
1761
    register_transport_proto('ftp+gssapi://', register_netloc=True)
 
1762
    register_lazy_transport('ftp+gssapi://', 'bzrlib.transport.ftp._gssapi',
 
1763
                            'GSSAPIFtpTransport')
 
1764
    register_transport_proto('aftp+gssapi://', register_netloc=True)
 
1765
    register_lazy_transport('aftp+gssapi://', 'bzrlib.transport.ftp._gssapi',
 
1766
                            'GSSAPIFtpTransport')
 
1767
    register_transport_proto('ftp+nogssapi://', register_netloc=True)
 
1768
    register_transport_proto('aftp+nogssapi://', register_netloc=True)
 
1769
 
 
1770
    register_lazy_transport('ftp://', 'bzrlib.transport.ftp._gssapi',
 
1771
                            'GSSAPIFtpTransport')
 
1772
    register_lazy_transport('aftp://', 'bzrlib.transport.ftp._gssapi',
 
1773
                            'GSSAPIFtpTransport')
 
1774
    register_lazy_transport('ftp+nogssapi://', 'bzrlib.transport.ftp',
 
1775
                            'FtpTransport')
 
1776
    register_lazy_transport('aftp+nogssapi://', 'bzrlib.transport.ftp',
 
1777
                            'FtpTransport')
1774
1778
 
1775
1779
register_transport_proto('memory://')
1776
1780
register_lazy_transport('memory://', 'bzrlib.transport.memory',
1852
1856
 
1853
1857
 
1854
1858
transport_server_registry = registry.Registry()
1855
 
transport_server_registry.register_lazy('bzr', 'bzrlib.smart.server',
 
1859
transport_server_registry.register_lazy('bzr', 'bzrlib.smart.server', 
1856
1860
    'serve_bzr', help="The Bazaar smart server protocol over TCP. (default port: 4155)")
1857
1861
transport_server_registry.default_key = 'bzr'