Beispiel #1
0
 def _doImport(self):
     self._logger.info("Starting job.")
     saved_factory = bzrlib.ui.ui_factory
     opener = SafeBranchOpener(self._opener_policy, self.probers)
     bzrlib.ui.ui_factory = LoggingUIFactory(logger=self._logger)
     try:
         self._logger.info(
             "Getting exising bzr branch from central store.")
         bazaar_branch = self.getBazaarBranch()
         try:
             remote_branch = opener.open(self.source_details.url)
         except TooManyRedirections:
             self._logger.info("Too many redirections.")
             return CodeImportWorkerExitCode.FAILURE_INVALID
         except NotBranchError:
             self._logger.info("No branch found at remote location.")
             return CodeImportWorkerExitCode.FAILURE_INVALID
         except BadUrl as e:
             self._logger.info("Invalid URL: %s" % e)
             return CodeImportWorkerExitCode.FAILURE_FORBIDDEN
         except ConnectionError as e:
             self._logger.info("Unable to open remote branch: %s" % e)
             return CodeImportWorkerExitCode.FAILURE_INVALID
         try:
             remote_branch_tip = remote_branch.last_revision()
             inter_branch = InterBranch.get(remote_branch, bazaar_branch)
             self._logger.info("Importing branch.")
             revision_limit = self.getRevisionLimit()
             inter_branch.fetch(limit=revision_limit)
             if bazaar_branch.repository.has_revision(remote_branch_tip):
                 pull_result = inter_branch.pull(overwrite=True)
                 if pull_result.old_revid != pull_result.new_revid:
                     result = CodeImportWorkerExitCode.SUCCESS
                 else:
                     result = CodeImportWorkerExitCode.SUCCESS_NOCHANGE
             else:
                 result = CodeImportWorkerExitCode.SUCCESS_PARTIAL
         except Exception as e:
             if e.__class__ in self.unsupported_feature_exceptions:
                 self._logger.info(
                     "Unable to import branch because of limitations in "
                     "Bazaar.")
                 self._logger.info(str(e))
                 return (
                     CodeImportWorkerExitCode.FAILURE_UNSUPPORTED_FEATURE)
             elif e.__class__ in self.invalid_branch_exceptions:
                 self._logger.info("Branch invalid: %s", str(e))
                 return CodeImportWorkerExitCode.FAILURE_INVALID
             elif e.__class__ in self.broken_remote_exceptions:
                 self._logger.info("Remote branch broken: %s", str(e))
                 return CodeImportWorkerExitCode.FAILURE_REMOTE_BROKEN
             else:
                 raise
         self._logger.info("Pushing local import branch to central store.")
         self.pushBazaarBranch(bazaar_branch)
         self._logger.info("Job complete.")
         return result
     finally:
         bzrlib.ui.ui_factory = saved_factory
Beispiel #2
0
    def __init__(self, policy, protocol=None, log=None):
        """Construct a branch opener with 'policy'.

        :param policy: A `BranchOpenPolicy` that tells us what URLs are valid
            and similar things.
        :param log: A callable which can be called with a format string and
            arguments to log messages in the scheduler, or None, in which case
            log messages are discarded.
        """
        self.policy = policy
        self.protocol = protocol
        self.opener = SafeBranchOpener(policy)
        if log is not None:
            self.log = log
        else:
            self.log = lambda *args: None
 def makeBranchOpener(self, allowed_urls, probers=None):
     policy = WhitelistPolicy(True, allowed_urls, True)
     return SafeBranchOpener(policy, probers)