~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/codehosting/codeimport/worker.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-12-15 10:35:32 UTC
  • mfrom: (14517.1.3 new-bzr)
  • Revision ID: launchpad@pqm.canonical.com-20111215103532-q2m4uyk0r8ugiayx
[r=sinzui, poolie][bug=509016] Always load foreign plugins,
 but restrict probers to avoid accidentally opening foreign branches.
 (re-land)

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
    TooManyRedirections,
41
41
    )
42
42
from bzrlib.transport import (
43
 
    do_catching_redirections,
44
43
    get_transport_from_path,
45
44
    get_transport_from_url,
46
45
    )
66
65
    branch_id_alias,
67
66
    compose_public_url,
68
67
    )
 
68
import lp.codehosting # for bzr plugins
69
69
from lp.codehosting.codeimport.foreigntree import (
70
70
    CVSWorkingTree,
71
71
    SubversionWorkingTree,
711
711
        """
712
712
        return None
713
713
 
714
 
    def _open_dir(self, url):
715
 
        """Simple BzrDir.open clone that only uses self.probers.
716
 
 
717
 
        :param url: URL to open
718
 
        :return: ControlDir instance
719
 
        """
720
 
        def redirected(transport, e, redirection_notice):
721
 
            self._opener_policy.checkOneURL(e.target)
722
 
            redirected_transport = transport._redirected_to(
723
 
                e.source, e.target)
724
 
            if redirected_transport is None:
725
 
                raise NotBranchError(e.source)
726
 
            self._logger.info('%s is%s redirected to %s',
727
 
                 transport.base, e.permanently, redirected_transport.base)
728
 
            return redirected_transport
729
 
 
730
 
        def find_format(transport):
731
 
            last_error = None
732
 
            for prober_kls in self.probers:
733
 
                prober = prober_kls()
734
 
                try:
735
 
                    return transport, prober.probe_transport(transport)
736
 
                except NotBranchError, e:
737
 
                    last_error = e
738
 
            else:
739
 
                raise last_error
740
 
        transport = get_transport_from_url(url)
741
 
        transport, format = do_catching_redirections(find_format, transport,
742
 
            redirected)
743
 
        return format.open(transport)
744
 
 
745
714
    def _doImport(self):
746
715
        self._logger.info("Starting job.")
747
716
        saved_factory = bzrlib.ui.ui_factory
748
 
        opener = SafeBranchOpener(self._opener_policy)
 
717
        opener = SafeBranchOpener(self._opener_policy, self.probers)
749
718
        bzrlib.ui.ui_factory = LoggingUIFactory(logger=self._logger)
750
719
        try:
751
720
            self._logger.info(
752
721
                "Getting exising bzr branch from central store.")
753
722
            bazaar_branch = self.getBazaarBranch()
754
723
            try:
755
 
                remote_branch = opener.open(
756
 
                    self.source_details.url, self._open_dir)
 
724
                remote_branch = opener.open(self.source_details.url)
757
725
            except TooManyRedirections:
758
726
                self._logger.info("Too many redirections.")
759
727
                return CodeImportWorkerExitCode.FAILURE_INVALID