~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-01-15 05:43:42 UTC
  • mfrom: (4734.4.13 bug-440952-bzrdir)
  • Revision ID: pqm@pqm.ubuntu.com-20100115054342-o6ar5y4ch9tcnzyi
(andrew) Give 'location is a repository' hint for NotBranchError
        (#440952).

Show diffs side-by-side

added added

removed removed

Lines of Context:
702
702
# TODO: Probably this behavior of should be a common superclass
703
703
class NotBranchError(PathError):
704
704
 
705
 
    _fmt = 'Not a branch: "%(path)s".'
 
705
    _fmt = 'Not a branch: "%(path)s"%(detail)s.'
706
706
 
707
 
    def __init__(self, path):
 
707
    def __init__(self, path, detail=None, bzrdir=None):
708
708
       import bzrlib.urlutils as urlutils
709
 
       self.path = urlutils.unescape_for_display(path, 'ascii')
 
709
       path = urlutils.unescape_for_display(path, 'ascii')
 
710
       if detail is not None:
 
711
           detail = ': ' + detail
 
712
       self.detail = detail
 
713
       self.bzrdir = bzrdir
 
714
       PathError.__init__(self, path=path)
 
715
 
 
716
    def _format(self):
 
717
        # XXX: Ideally self.detail would be a property, but Exceptions in
 
718
        # Python 2.4 have to be old-style classes so properties don't work.
 
719
        # Instead we override _format.
 
720
        if self.detail is None:
 
721
            if self.bzrdir is not None:
 
722
                try:
 
723
                    self.bzrdir.open_repository()
 
724
                except NoRepositoryPresent:
 
725
                    self.detail = ''
 
726
                else:
 
727
                    self.detail = ': location is a repository'
 
728
            else:
 
729
                self.detail = ''
 
730
        return PathError._format(self)
710
731
 
711
732
 
712
733
class NoSubmitBranch(PathError):