~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Marius Kruger
  • Date: 2006-12-22 18:22:50 UTC
  • mto: (2220.1.1 bzr.enhanced_move)
  • mto: This revision was merged to the branch mainline in revision 2241.
  • Revision ID: amanic@gmail.com-20061222182250-mq33oq8fs45fx4sb
* Change move/rename errors yet again
  - added new exception classes BzrMoveFailedError and BzrRenameFailedError
  - convert the move/rename methods to raise these new exceptions,
    and pass more specefic exceptions as extra.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""
19
19
 
20
20
 
21
 
from bzrlib import symbol_versioning
 
21
from bzrlib import (symbol_versioning, 
 
22
                    osutils,)
22
23
from bzrlib.patches import (PatchSyntax, 
23
24
                            PatchConflict, 
24
25
                            MalformedPatchHeader,
339
340
        else:
340
341
            self.plural = ''
341
342
 
 
343
 
342
344
class NotADirectory(PathError):
343
345
 
344
346
    _fmt = "%(path)r is not a directory %(extra)s"
1321
1323
    _fmt = "Moving the root directory is not supported at this time"
1322
1324
 
1323
1325
 
 
1326
class BzrMoveFailedError(BzrError):
 
1327
    
 
1328
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
 
1329
 
 
1330
    def __init__(self, from_path, to_path, extra=None):
 
1331
        BzrError.__init__(self)
 
1332
        if extra:
 
1333
            self.extra = ': ' + str(extra)
 
1334
        else:
 
1335
            self.extra = ''
 
1336
            
 
1337
        has_from = len(from_path) > 0
 
1338
        has_to = len(to_path) > 0
 
1339
        if has_from:
 
1340
            self.from_path = osutils.splitpath(from_path)[-1]
 
1341
        else:
 
1342
            self.from_path = ''
 
1343
            
 
1344
        if has_to:
 
1345
            self.to_path = osutils.splitpath(to_path)[-1]
 
1346
        else:
 
1347
            self.to_path = ''
 
1348
 
 
1349
        self.operator = ""
 
1350
        if has_from and has_to:
 
1351
            self.operator = " =>"
 
1352
        elif has_from:            
 
1353
            self.from_path = "from " + from_path
 
1354
        elif has_to:
 
1355
            self.operator = "to"
 
1356
        else:
 
1357
            self.operator = "file"
 
1358
 
 
1359
 
 
1360
class BzrRenameFailedError(BzrMoveFailedError):
 
1361
    
 
1362
    _fmt = "Could not rename %(from_path)s%(operator)s %(to_path)s%(extra)s"
 
1363
    
 
1364
    def __init__(self, from_path, to_path, extra=None):
 
1365
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
 
1366
 
 
1367
 
1324
1368
class BzrBadParameterNotString(BzrBadParameter):
1325
1369
 
1326
1370
    _fmt = "Parameter %(param)s is not a string or unicode string."