srcanamdw/codescanner/pyinstaller/optik/errors.py
author noe\swadi
Thu, 18 Feb 2010 12:29:02 +0530
changeset 1 22878952f6e2
permissions -rw-r--r--
Committing the CodeScanner Core tool This component has been moved from the StaticAnaApps package. BUG : 5889 (http://developer.symbian.org/webbugs/show_bug.cgi?id=5889).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     1
"""optik.errors
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     2
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     3
Exception classes used by Optik.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     4
"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     5
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     6
# Copyright (c) 2001-2004 Gregory P. Ward.  All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     7
# See the README.txt distributed with Optik for licensing terms.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     8
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     9
import string
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    10
try:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    11
    from gettext import gettext
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    12
except ImportError:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    13
    def gettext(message):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    14
        return message
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    15
_ = gettext
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    16
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    17
__revision__ = "$Id: errors.py,v 1.1 2009/02/05 23:03:30 stechong Exp $"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    18
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    19
__all__ = ['OptikError', 'OptionError', 'OptionConflictError',
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    20
           'OptionValueError', 'BadOptionError']
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    21
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    22
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    23
class OptikError (Exception):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    24
    def __init__(self, msg):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    25
        self.msg = msg
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    26
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    27
    def __str__(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    28
        return self.msg
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    29
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    30
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    31
class OptionError (OptikError):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    32
    """
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    33
    Raised if an Option instance is created with invalid or
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    34
    inconsistent arguments.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    35
    """
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    36
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    37
    def __init__(self, msg, option):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    38
        self.msg = msg
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    39
        self.option_id = str(option)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    40
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    41
    def __str__(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    42
        if self.option_id:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    43
            return "option %s: %s" % (self.option_id, self.msg)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    44
        else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    45
            return self.msg
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    46
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    47
class OptionConflictError (OptionError):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    48
    """
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    49
    Raised if conflicting options are added to an OptionParser.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    50
    """
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    51
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    52
class OptionValueError (OptikError):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    53
    """
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    54
    Raised if an invalid option value is encountered on the command
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    55
    line.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    56
    """
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    57
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    58
class BadOptionError (OptikError):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    59
    """
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    60
    Raised if an invalid option is seen on the command line.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    61
    """
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    62
    def __init__(self, opt_str):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    63
        self.opt_str = opt_str
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    64
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    65
    def __str__(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    66
        return _("no such option: %s") % self.opt_str
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    67
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    68
class AmbiguousOptionError (BadOptionError):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    69
    """
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    70
    Raised if an ambiguous option is seen on the command line.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    71
    """
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    72
    def __init__(self, opt_str, possibilities):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    73
        BadOptionError.__init__(self, opt_str)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    74
        self.possibilities = possibilities
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    75
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    76
    def __str__(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    77
        return (_("ambiguous option: %s (%s?)")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    78
                % (self.opt_str, string.join(self.possibilities, ", ")))