~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2011-06-16 23:43:04 UTC
  • mto: This revision was merged to the branch mainline in revision 13268.
  • Revision ID: jelmer@canonical.com-20110616234304-mbbcift4yrkubld7
Initial work on supporting FAILURE_INVALID and FAILURE_UNSUPPORTED_FEATURE return types from imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    BzrDirFormat,
31
31
    )
32
32
from bzrlib.errors import (
 
33
    ConnectionError,
33
34
    NoSuchFile,
 
35
    NoRepositoryPresent,
34
36
    NotBranchError,
35
37
    )
36
38
from bzrlib.transport import get_transport
66
68
    FAILURE = 1
67
69
    SUCCESS_NOCHANGE = 2
68
70
    SUCCESS_PARTIAL = 3
 
71
    FAILURE_INVALID = 4
 
72
    FAILURE_UNSUPPORTED_FEATURE = 5
69
73
 
70
74
 
71
75
class BazaarBranchStore:
480
484
    def _doImport(self):
481
485
        """Perform the import.
482
486
 
483
 
        :return: True if the import actually imported some new revisions.
 
487
        :return: A CodeImportWorkerExitCode
484
488
        """
485
489
        raise NotImplementedError()
486
490
 
573
577
 
574
578
    needs_bzr_tree = False
575
579
 
 
580
    invalid_branch_exceptions = [
 
581
        NoRepositoryPresent,
 
582
        NotBranchError,
 
583
        ConnectionError,
 
584
        ]
 
585
 
 
586
    unsupported_feature_exceptions = [
 
587
        ]
 
588
 
576
589
    @property
577
590
    def probers(self):
578
591
        """The probers that should be tried for this import."""
606
619
            remote_branch_tip = remote_branch.last_revision()
607
620
            inter_branch = InterBranch.get(remote_branch, bazaar_branch)
608
621
            self._logger.info("Importing branch.")
609
 
            inter_branch.fetch(limit=self.getRevisionLimit())
610
 
            if bazaar_branch.repository.has_revision(remote_branch_tip):
611
 
                pull_result = inter_branch.pull(overwrite=True)
612
 
                if pull_result.old_revid != pull_result.new_revid:
613
 
                    result = CodeImportWorkerExitCode.SUCCESS
614
 
                else:
615
 
                    result = CodeImportWorkerExitCode.SUCCESS_NOCHANGE
616
 
            else:
617
 
                result = CodeImportWorkerExitCode.SUCCESS_PARTIAL
 
622
            try:
 
623
                inter_branch.fetch(limit=self.getRevisionLimit())
 
624
                if bazaar_branch.repository.has_revision(remote_branch_tip):
 
625
                    pull_result = inter_branch.pull(overwrite=True)
 
626
                    if pull_result.old_revid != pull_result.new_revid:
 
627
                        result = CodeImportWorkerExitCode.SUCCESS
 
628
                    else:
 
629
                        result = CodeImportWorkerExitCode.SUCCESS_NOCHANGE
 
630
                else:
 
631
                    result = CodeImportWorkerExitCode.SUCCESS_PARTIAL
 
632
            except Exception, e:
 
633
                if e.__class__ in self.unsupported_feature_exceptions:
 
634
                    self._logger.info(
 
635
                        "Unable to import branch because of limitations in Bazaar.")
 
636
                    self._logger.info(str(e))
 
637
                    result = CodeImportWorkerExitCode.FAILURE_UNSUPPORTED_FEATURE
 
638
                elif e.__class__ in self.invalid_branch_exceptions:
 
639
                    self._logger.info("Branch invalid: %s", e(str))
 
640
                    result = CodeImportWorkerExitCode.FAILURE_INVALID
 
641
                else:
 
642
                    raise
618
643
            self._logger.info("Pushing local import branch to central store.")
619
644
            self.pushBazaarBranch(bazaar_branch)
620
645
            self._logger.info("Job complete.")