~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

Merge safe-open branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
665
665
        """
666
666
        return None
667
667
 
 
668
    def _open_dir(self, url):
 
669
        """Simple BzrDir.open clone that only uses self.probers.
 
670
 
 
671
        :param url: URL to open
 
672
        :return: ControlDir instance
 
673
        """
 
674
        transport = get_transport(url)
 
675
        for prober_kls in self.probers:
 
676
            prober = prober_kls()
 
677
            try:
 
678
                format = prober.probe_transport(transport)
 
679
            except NotBranchError:
 
680
                pass
 
681
            else:
 
682
                return format.open(transport)
 
683
        else:
 
684
            raise NotBranchError("Not a valid branch")
 
685
 
668
686
    def _doImport(self):
669
687
        self._logger.info("Starting job.")
670
688
        saved_factory = bzrlib.ui.ui_factory
675
693
                "Getting exising bzr branch from central store.")
676
694
            bazaar_branch = self.getBazaarBranch()
677
695
            try:
678
 
                self._opener_policy.checkOneURL(self.source_details.url)
679
 
            except BadUrl, e:
680
 
                self._logger.info("Invalid URL: %s" % e)
681
 
                return CodeImportWorkerExitCode.FAILURE_FORBIDDEN
682
 
            transport = get_transport(self.source_details.url)
683
 
            for prober_kls in self.probers:
684
 
                prober = prober_kls()
685
 
                try:
686
 
                    format = prober.probe_transport(transport)
687
 
                    break
688
 
                except NotBranchError:
689
 
                    pass
690
 
            else:
 
696
                remote_branch = opener.open(
 
697
                    self.source_details.url, self._open_dir)
 
698
            except NotBranchError:
691
699
                self._logger.info("No branch found at remote location.")
692
700
                return CodeImportWorkerExitCode.FAILURE_INVALID
693
 
            remote_dir = format.open(transport)
694
 
            try:
695
 
                remote_branch = opener.runWithTransformFallbackLocationHookInstalled(
696
 
                    remote_dir.open_branch)
697
701
            except BadUrl, e:
698
702
                self._logger.info("Invalid URL: %s" % e)
699
703
                return CodeImportWorkerExitCode.FAILURE_FORBIDDEN