~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/__init__.py

Push the transport permutations list into each transport module allowing for automatic testing of new modules that are registered as transports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
        _protocol_handlers[prefix] = klass
44
44
 
45
45
 
 
46
def _get_protocol_handlers():
 
47
    """Return a dictionary of prefix:transport-factories."""
 
48
    return _protocol_handlers
 
49
 
 
50
 
 
51
def _set_protocol_handlers(new_handlers):
 
52
    """Replace the current protocol handlers dictionary.
 
53
 
 
54
    WARNING this will remove all build in protocols. Use with care.
 
55
    """
 
56
    global _protocol_handlers
 
57
    _protocol_handlers = new_handlers
 
58
 
 
59
 
 
60
def _get_transport_modules():
 
61
    """Return a list of the modules providing transports."""
 
62
    modules = set()
 
63
    for prefix, factory in _protocol_handlers.items():
 
64
        if factory.__module__ == "bzrlib.transport":
 
65
            # this is a lazy load transport, because no real ones
 
66
            # are directlry in bzrlib.transport
 
67
            modules.add(factory.module)
 
68
        else:
 
69
            modules.add(factory.__module__)
 
70
    return list(modules)
 
71
 
 
72
 
46
73
class Transport(object):
47
74
    """This class encapsulates methods for retrieving or putting a file
48
75
    from/to a storage location.
425
452
        mod = __import__(module, globals(), locals(), [classname])
426
453
        klass = getattr(mod, classname)
427
454
        return klass(base)
 
455
    _loader.module = module
428
456
    register_transport(scheme, _loader)
429
457
 
430
458
 
476
504
            result.addTest(new_test)
477
505
        return result
478
506
 
 
507
    def get_transport_test_permutations(self, module):
 
508
        """Get the permutations module wants to have tested."""
 
509
        return module.get_test_permutations()
 
510
 
479
511
    def _test_permutations(self):
480
512
        """Return a list of the klass, server_factory pairs to test."""
481
 
        from bzrlib.transport.local import (LocalTransport,
482
 
                                            LocalRelpathServer,
483
 
                                            LocalAbspathServer,
484
 
                                            LocalURLServer
485
 
                                            )
486
 
        from bzrlib.transport.sftp import (SFTPTransport,
487
 
                                           SFTPAbsoluteServer,
488
 
                                           SFTPHomeDirServer,
489
 
                                           SFTPSiblingAbsoluteServer,
490
 
                                           )
491
 
        from bzrlib.transport.http import (HttpTransport,
492
 
                                           HttpServer
493
 
                                           )
494
 
        from bzrlib.transport.ftp import FtpTransport
495
 
        from bzrlib.transport.memory import (MemoryTransport,
496
 
                                             MemoryServer
497
 
                                             )
498
 
        return [(LocalTransport, LocalRelpathServer),
499
 
                (LocalTransport, LocalAbspathServer),
500
 
                (LocalTransport, LocalURLServer),
501
 
                (SFTPTransport, SFTPAbsoluteServer),
502
 
                (SFTPTransport, SFTPHomeDirServer),
503
 
                (SFTPTransport, SFTPSiblingAbsoluteServer),
504
 
                (HttpTransport, HttpServer),
505
 
                (MemoryTransport, MemoryServer),
506
 
                ]
 
513
        result = []
 
514
        for module in _get_transport_modules():
 
515
            result.extend(self.get_transport_test_permutations(reduce(getattr, 
 
516
                (module).split('.')[1:],
 
517
                 __import__(module))))
 
518
        return result
507
519
        
508
520
 
509
521
# None is the default transport, for things with no url scheme
514
526
register_lazy_transport('https://', 'bzrlib.transport.http', 'HttpTransport')
515
527
register_lazy_transport('ftp://', 'bzrlib.transport.ftp', 'FtpTransport')
516
528
register_lazy_transport('aftp://', 'bzrlib.transport.ftp', 'FtpTransport')
 
529
register_lazy_transport('memory://', 'bzrlib.transport.memory', 'MemoryTransport')