~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: 2007-01-20 02:01:04 UTC
  • mfrom: (2220.1.14 bzr.ab.integration)
  • Revision ID: pqm@pqm.ubuntu.com-20070120020104-a192555a9165b259
mv can also work on just inventory entry (Eichenberg, Kruger)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""
19
19
 
20
20
 
21
 
from bzrlib import symbol_versioning
22
 
from bzrlib.patches import (PatchSyntax, 
23
 
                            PatchConflict, 
24
 
                            MalformedPatchHeader,
25
 
                            MalformedHunkHeader,
26
 
                            MalformedLine,)
 
21
from bzrlib import (
 
22
    osutils,
 
23
    symbol_versioning,
 
24
    )
 
25
from bzrlib.patches import (
 
26
    MalformedHunkHeader,
 
27
    MalformedLine,
 
28
    MalformedPatchHeader,
 
29
    PatchConflict,
 
30
    PatchSyntax,
 
31
    )
27
32
 
28
33
 
29
34
# TODO: is there any value in providing the .args field used by standard
333
338
    _fmt = "File exists: %(path)r%(extra)s"
334
339
 
335
340
 
 
341
class RenameFailedFilesExist(BzrError):
 
342
    """Used when renaming and both source and dest exist."""
 
343
 
 
344
    _fmt = ("Could not rename %(source)s => %(dest)s because both files exist."
 
345
         "%(extra)s")
 
346
 
 
347
    def __init__(self, source, dest, extra=None):
 
348
        BzrError.__init__(self)
 
349
        self.source = str(source)
 
350
        self.dest = str(dest)
 
351
        if extra:
 
352
            self.extra = ' ' + str(extra)
 
353
        else:
 
354
            self.extra = ''
 
355
 
 
356
 
 
357
class NotADirectory(PathError):
 
358
 
 
359
    _fmt = "%(path)r is not a directory %(extra)s"
 
360
 
 
361
 
 
362
class NotInWorkingDirectory(PathError):
 
363
 
 
364
    _fmt = "%(path)r is not in the working directory %(extra)s"
 
365
 
 
366
 
336
367
class DirectoryNotEmpty(PathError):
337
368
 
338
369
    _fmt = "Directory not empty: %(path)r%(extra)s"
505
536
        self.repo_format = repo_format
506
537
 
507
538
 
 
539
class AlreadyVersionedError(BzrError):
 
540
    """Used when a path is expected not to be versioned, but it is."""
 
541
 
 
542
    _fmt = "%(context_info)s%(path)s is already versioned"
 
543
 
 
544
    def __init__(self, path, context_info=None):
 
545
        """Construct a new NotVersionedError.
 
546
 
 
547
        :param path: This is the path which is versioned,
 
548
        which should be in a user friendly form.
 
549
        :param context_info: If given, this is information about the context,
 
550
        which could explain why this is expected to not be versioned.
 
551
        """
 
552
        BzrError.__init__(self)
 
553
        self.path = path
 
554
        if context_info is None:
 
555
            self.context_info = ''
 
556
        else:
 
557
            self.context_info = context_info + ". "
 
558
 
 
559
 
508
560
class NotVersionedError(BzrError):
509
 
 
510
 
    _fmt = "%(path)s is not versioned"
511
 
 
512
 
    def __init__(self, path):
 
561
    """Used when a path is expected to be versioned, but it is not."""
 
562
 
 
563
    _fmt = "%(context_info)s%(path)s is not versioned"
 
564
 
 
565
    def __init__(self, path, context_info=None):
 
566
        """Construct a new NotVersionedError.
 
567
 
 
568
        :param path: This is the path which is not versioned,
 
569
        which should be in a user friendly form.
 
570
        :param context_info: If given, this is information about the context,
 
571
        which could explain why this is expected to be versioned.
 
572
        """
513
573
        BzrError.__init__(self)
514
574
        self.path = path
 
575
        if context_info is None:
 
576
            self.context_info = ''
 
577
        else:
 
578
            self.context_info = context_info + ". "
515
579
 
516
580
 
517
581
class PathsNotVersionedError(BzrError):
518
 
    # used when reporting several paths are not versioned
 
582
    """Used when reporting several paths which are not versioned"""
519
583
 
520
584
    _fmt = "Path(s) are not versioned: %(paths_as_string)s"
521
585
 
528
592
 
529
593
class PathsDoNotExist(BzrError):
530
594
 
531
 
    _fmt = "Path(s) do not exist: %(paths_as_string)s"
 
595
    _fmt = "Path(s) do not exist: %(paths_as_string)s%(extra)s"
532
596
 
533
597
    # used when reporting that paths are neither versioned nor in the working
534
598
    # tree
535
599
 
536
 
    def __init__(self, paths):
 
600
    def __init__(self, paths, extra=None):
537
601
        # circular import
538
602
        from bzrlib.osutils import quotefn
539
603
        BzrError.__init__(self)
540
604
        self.paths = paths
541
605
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
 
606
        if extra:
 
607
            self.extra = ': ' + str(extra)
 
608
        else:
 
609
            self.extra = ''
542
610
 
543
611
 
544
612
class BadFileKindError(BzrError):
1292
1360
    _fmt = "Moving the root directory is not supported at this time"
1293
1361
 
1294
1362
 
 
1363
class BzrMoveFailedError(BzrError):
 
1364
 
 
1365
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
 
1366
 
 
1367
    def __init__(self, from_path='', to_path='', extra=None):
 
1368
        BzrError.__init__(self)
 
1369
        if extra:
 
1370
            self.extra = ': ' + str(extra)
 
1371
        else:
 
1372
            self.extra = ''
 
1373
 
 
1374
        has_from = len(from_path) > 0
 
1375
        has_to = len(to_path) > 0
 
1376
        if has_from:
 
1377
            self.from_path = osutils.splitpath(from_path)[-1]
 
1378
        else:
 
1379
            self.from_path = ''
 
1380
 
 
1381
        if has_to:
 
1382
            self.to_path = osutils.splitpath(to_path)[-1]
 
1383
        else:
 
1384
            self.to_path = ''
 
1385
 
 
1386
        self.operator = ""
 
1387
        if has_from and has_to:
 
1388
            self.operator = " =>"
 
1389
        elif has_from:
 
1390
            self.from_path = "from " + from_path
 
1391
        elif has_to:
 
1392
            self.operator = "to"
 
1393
        else:
 
1394
            self.operator = "file"
 
1395
 
 
1396
 
 
1397
class BzrRenameFailedError(BzrMoveFailedError):
 
1398
 
 
1399
    _fmt = "Could not rename %(from_path)s%(operator)s %(to_path)s%(extra)s"
 
1400
 
 
1401
    def __init__(self, from_path, to_path, extra=None):
 
1402
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
 
1403
 
 
1404
 
1295
1405
class BzrBadParameterNotString(BzrBadParameter):
1296
1406
 
1297
1407
    _fmt = "Parameter %(param)s is not a string or unicode string."