Changeset 3288

Show
Ignore:
Timestamp:
01/11/08 19:08:24 (17 years ago)
Author:
jerome
Message:

Moved all exceptions definitions to a dedicated module.

Location:
pykota/trunk
Files:
32 modified
1 copied

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/autopykota

    r3275 r3288  
    2626import os 
    2727 
    28 from pykota.tool import PyKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 
     28from pykota.errors import PyKotaToolError, PyKotaCommandLineError 
     29from pykota.tool import PyKotaTool, crashed, N_ 
    2930 
    3031__doc__ = N_("""autopykota v%(__version__)s (c) %(__years__)s %(__author__)s 
  • pykota/trunk/bin/cupspykota

    r3276 r3288  
    4444from mx import DateTime 
    4545 
    46 from pykota.tool import PyKotaTool, PyKotaToolError, crashed 
     46from pykota.errors import PyKotaToolError 
     47from pykota.tool import PyKotaTool, crashed 
    4748from pykota.accounter import openAccounter 
    4849from pykota import cups 
  • pykota/trunk/bin/dumpykota

    r3275 r3288  
    2424import sys 
    2525 
    26 from pykota.tool import PyKotaCommandLineError, crashed, N_ 
     26from pykota.errors import PyKotaCommandLineError 
     27from pykota.tool import crashed, N_ 
    2728from pykota.dumper import DumPyKota 
    2829 
  • pykota/trunk/bin/edpykota

    r3275 r3288  
    2424import sys 
    2525 
    26 from pykota.tool import Percent, PyKotaTool, PyKotaCommandLineError, crashed, N_ 
     26from pykota.errors import PyKotaCommandLineError 
     27from pykota.tool import Percent, PyKotaTool, crashed, N_ 
    2728from pykota.storage import StorageUserPQuota, StorageGroupPQuota 
    2829 
  • pykota/trunk/bin/pkbanner

    r3275 r3288  
    3333    from reportlab.lib.units import cm 
    3434except ImportError :     
    35     hasRL = 0 
     35    hasRL = False 
    3636else :     
    37     hasRL = 1 
     37    hasRL = True 
    3838     
    3939try : 
    4040    import PIL.Image  
    4141except ImportError :     
    42     hasPIL = 0 
     42    hasPIL = False 
    4343else :     
    44     hasPIL = 1 
     44    hasPIL = True 
    4545     
    46 from pykota.tool import Tool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 
     46from pykota.errors import PyKotaToolError, PyKotaCommandLineError 
     47from pykota.tool import Tool, crashed, N_ 
    4748 
    4849__doc__ = N_("""pkbanner v%(__version__)s (c) %(__years__)s %(__author__)s 
  • pykota/trunk/bin/pkbcodes

    r3275 r3288  
    2626import pwd 
    2727 
    28 from pykota.tool import Percent, PyKotaTool, PyKotaCommandLineError, crashed, N_ 
     28from pykota.errors import PyKotaCommandLineError 
     29from pykota.tool import Percent, PyKotaTool, crashed, N_ 
    2930from pykota.storage import StorageBillingCode 
    3031 
  • pykota/trunk/bin/pkinvoice

    r3276 r3288  
    3333    from reportlab.lib.units import cm 
    3434except ImportError :     
    35     hasRL = 0 
     35    hasRL = False 
    3636else :     
    37     hasRL = 1 
     37    hasRL = True 
    3838     
    3939try : 
    4040    import PIL.Image  
    4141except ImportError :     
    42     hasPIL = 0 
     42    hasPIL = False 
    4343else :     
    44     hasPIL = 1 
    45  
    46 from pykota.tool import Percent, PyKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 
     44    hasPIL = True 
     45 
     46from pykota.errors import PyKotaToolError, PyKotaCommandLineError 
     47from pykota.tool import Percent, PyKotaTool, crashed, N_ 
    4748 
    4849__doc__ = N_("""pkinvoice v%(__version__)s (c) %(__years__)s %(__author__)s 
  • pykota/trunk/bin/pkmail

    r3275 r3288  
    3131import email.Utils 
    3232 
    33 from pykota.tool import PyKotaTool, PyKotaCommandLineError, crashed, N_ 
     33from pykota.errors import PyKotaCommandLineError 
     34from pykota.tool import PyKotaTool, crashed, N_ 
    3435     
    3536__doc__ = N_("""pkmail v%(__version__)s (c) %(__years__)s %(__author__)s 
  • pykota/trunk/bin/pknotify

    r3276 r3288  
    3131    import PAM 
    3232except ImportError :     
    33     hasPAM = 0 
     33    hasPAM = False 
    3434else :     
    35     hasPAM = 1 
    36  
    37 from pykota.tool import Tool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 
     35    hasPAM = True 
     36 
     37from pykota.errors import PyKotaToolError, PyKotaCommandLineError 
     38from pykota.tool import Tool, crashed, N_ 
    3839 
    3940__doc__ = N_("""pknotify v%(__version__)s (c) %(__years__)s %(__author__)s 
  • pykota/trunk/bin/pkprinters

    r3276 r3288  
    2626import pwd 
    2727 
    28 from pykota.tool import Percent, PyKotaTool, PyKotaCommandLineError, crashed, N_ 
     28from pykota.errors import PyKotaCommandLineError 
     29from pykota.tool import Percent, PyKotaTool, crashed, N_ 
    2930from pykota.storage import StoragePrinter 
    3031 
  • pykota/trunk/bin/pkrefund

    r3276 r3288  
    3333    from reportlab.lib.units import cm 
    3434except ImportError :     
    35     hasRL = 0 
     35    hasRL = False 
    3636else :     
    37     hasRL = 1 
     37    hasRL = True 
    3838     
    3939try : 
    4040    import PIL.Image  
    4141except ImportError :     
    42     hasPIL = 0 
     42    hasPIL = False 
    4343else :     
    44     hasPIL = 1 
    45  
    46 from pykota.tool import Percent, PyKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 
     44    hasPIL = True 
     45 
     46from pykota.errors import PyKotaToolError, PyKotaCommandLineError 
     47from pykota.tool import Percent, PyKotaTool, crashed, N_ 
    4748 
    4849__doc__ = N_("""pkrefund v%(__version__)s (c) %(__years__)s %(__author__)s 
  • pykota/trunk/bin/pkturnkey

    r3275 r3288  
    2929import signal 
    3030 
    31 from pykota.tool import Tool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 
     31from pykota.errors import PyKotaToolError, PyKotaCommandLineError 
     32from pykota.tool import Tool, crashed, N_ 
    3233 
    3334__doc__ = N_("""pkturnkey v%(__version__)s (c) %(__years__)s %(__author__)s 
  • pykota/trunk/bin/pkusers

    r3275 r3288  
    2626import grp 
    2727 
    28 from pykota.tool import Percent, PyKotaTool, PyKotaCommandLineError, crashed, N_ 
     28from pykota.errors import PyKotaCommandLineError 
     29from pykota.tool import Percent, PyKotaTool, crashed, N_ 
    2930from pykota.storage import StorageUser, StorageGroup 
    3031 
  • pykota/trunk/bin/pykosd

    r3275 r3288  
    3333    sys.exit(-1) 
    3434 
    35 from pykota.tool import PyKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 
     35from pykota.errors import PyKotaToolError, PyKotaCommandLineError 
     36from pykota.tool import PyKotaTool, crashed, N_ 
    3637 
    3738__doc__ = N_("""pykosd v%(__version__)s (c) %(__years__)s %(__author__)s 
  • pykota/trunk/bin/pykotme

    r3275 r3288  
    2626import pwd 
    2727 
    28 from pykota.tool import PyKotaTool, PyKotaCommandLineError, crashed, N_ 
     28from pykota.errors import PyKotaCommandLineError 
     29from pykota.tool import PyKotaTool, crashed, N_ 
    2930from pykota.accounter import openAccounter 
    3031     
  • pykota/trunk/bin/repykota

    r3275 r3288  
    2828from mx import DateTime 
    2929 
    30 from pykota.tool import PyKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 
     30from pykota.errors import PyKotaToolError, PyKotaCommandLineError 
     31from pykota.tool import PyKotaTool, crashed, N_ 
    3132from pykota import reporter 
    3233 
  • pykota/trunk/bin/warnpykota

    r3275 r3288  
    2626import pwd 
    2727 
    28 from pykota.tool import PyKotaTool, PyKotaCommandLineError, crashed, N_ 
     28from pykota.errors import PyKotaCommandLineError 
     29from pykota.tool import PyKotaTool, crashed, N_ 
    2930 
    3031__doc__ = N_("""warnpykota v%(__version__)s (c) %(__years__)s %(__author__)s 
  • pykota/trunk/pykota/accounter.py

    r3275 r3288  
    2727import imp 
    2828 
    29 class PyKotaAccounterError(Exception): 
    30     """An exception for Accounter related stuff.""" 
    31     def __init__(self, message = ""): 
    32         self.message = message 
    33         Exception.__init__(self, message) 
    34     def __repr__(self): 
    35         return self.message 
    36     __str__ = __repr__ 
    37      
     29from pykota.errors import PyKotaAccounterError 
     30 
    3831class AccounterBase :     
    3932    """A class to account print usage by querying printers.""" 
  • pykota/trunk/pykota/accounters/hardware.py

    r3275 r3288  
    2525import popen2 
    2626 
    27 from pykota.accounter import AccounterBase, PyKotaAccounterError 
     27from pykota.errors import PyKotaAccounterError 
     28from pykota.accounter import AccounterBase 
    2829from pykota.accounters import snmp, pjl 
    2930 
  • pykota/trunk/pykota/accounters/ink.py

    r3275 r3288  
    2121# 
    2222 
     23"""This module handles ink accounting in PyKota.""" 
     24 
    2325import os 
    24 from pykota.accounter import AccounterBase, PyKotaAccounterError 
    2526 
     27from pykota.errors import PyKotaAccounterError 
     28from pykota.accounter import AccounterBase 
    2629 
    2730class Accounter(AccounterBase) : 
     
    5053        colorspace = colorspace.lower() 
    5154        if colorspace not in ("cmyk", "bw", "cmy", "rgb", "gc") : 
    52             raise PyKotaAccounterError, "Invalid parameters for ink accounter : [%s]" % self.arguments 
     55            raise PyKotaAccounterError, _("Invalid parameters for ink accounter : [%s]") % self.arguments 
    5356             
    5457        try :     
  • pykota/trunk/pykota/accounters/software.py

    r3285 r3288  
    2121# 
    2222 
     23"""This module handles software page counting for PyKota.""" 
     24 
    2325import os 
    2426import popen2 
    25 from pykota.accounter import AccounterBase, PyKotaAccounterError 
     27 
     28from pykota.errors import PyKotaAccounterError 
     29from pykota.accounter import AccounterBase 
    2630 
    2731class Accounter(AccounterBase) : 
  • pykota/trunk/pykota/config.py

    r3284 r3288  
    2727import ConfigParser 
    2828 
    29 class PyKotaConfigError(Exception): 
    30     """An exception for PyKota config related stuff.""" 
    31     def __init__(self, message = ""): 
    32         self.message = message 
    33         Exception.__init__(self, message) 
    34     def __repr__(self): 
    35         return self.message 
    36     __str__ = __repr__ 
    37      
     29from pykota.errors import PyKotaConfigError     
     30 
    3831class PyKotaConfig : 
    3932    """A class to deal with PyKota's configuration.""" 
  • pykota/trunk/pykota/cups.py

    r3275 r3288  
    2222"""This module implements some CUPS specific classes.""" 
    2323 
    24 from pykota.tool import PyKotaToolError 
     24from pykota.errors import PyKotaToolError 
    2525try : 
    2626    from pkipplib import pkipplib 
  • pykota/trunk/pykota/dumper.py

    r3275 r3288  
    3535    sys.stderr.write("The jaxml Python module is not installed. XML output is disabled.\n") 
    3636    sys.stderr.write("Download jaxml from http://www.librelogiciel.com/software/ or from your Debian archive of choice\n") 
    37     hasJAXML = 0 
     37    hasJAXML = False 
    3838else :     
    39     hasJAXML = 1 
     39    hasJAXML = True 
    4040 
    4141from pykota import version 
    42 from pykota.tool import PyKotaTool, PyKotaToolError, PyKotaCommandLineError, N_ 
     42from pykota.tool import PyKotaTool, N_ 
     43from pykota.errors import PyKotaToolError, PyKotaCommandLineError 
    4344 
    4445class DumPyKota(PyKotaTool) :         
  • pykota/trunk/pykota/errors.py

    r3275 r3288  
    2020# 
    2121 
    22 """This module implements some CUPS specific classes.""" 
     22"""This module defines ALL PyKota specific exceptions.""" 
    2323 
    24 from pykota.tool import PyKotaToolError 
    25 try : 
    26     from pkipplib import pkipplib 
    27 except ImportError :         
    28     raise RuntimeError, "The python-pkipplib module is now mandatory. You can download pkipplib from http://www.pykota.com/" 
    29  
    30 class JobTicket :     
    31     """A class to hold CUPS print job informations.""" 
    32     def __init__(self, jobid=None, printername=None, copies=1, filename=None, \ 
    33                        options=None) : 
    34         """Initializes a print job's information.""" 
    35         self.JobId = jobid 
    36         self.PrinterName = printername 
    37         self.Copies = copies 
    38         self.FileName = filename 
    39         self.Options = options 
    40         self.Charset = None 
    41         self.OriginatingUserName = None 
    42         self.OriginalUserName = None 
    43         self.Title = None 
    44         self.BillingCode = None 
    45         self.OriginatingHostName = None 
    46         self.TimeAtCreation = None 
    47         self.TimeAtProcessing = None 
    48         self.MimeType = None 
    49         self.UUID = None 
    50         if self.JobId is not None : 
    51             self.retrieveAttributesFromCUPS() 
     24class PyKotaError(Exception) : 
     25    """Mother class of all PyKota exceptions.""" 
     26    def __init__(self, value) : 
     27        """Saves the value passed as a parameter.""" 
     28        self.value = value 
    5229         
    53     def getAttributeTypeAndValue(self, ippanswer, attribute, category="job") :     
    54         """Retrieves a particular attribute's type and value from an IPP answer. 
     30    def __str__(self) :     
     31        """Returns an unicode string representation.""" 
     32        try : 
     33            return unicode(self.value, errors="replace") 
     34        except TypeError :     
     35            return unicode(self.value) # None and strings which are already unicode 
    5536         
    56            Returns a tuple of the form (type, value). 
    57         """ 
    58         try : 
    59             return getattr(ippanswer, category)[attribute][0] 
    60         except KeyError :     
    61             return (None, None) 
    62              
    63     def retrieveAttributesFromCUPS(self) : 
    64         """Retrieve attribute's values from CUPS.""" 
    65         server = pkipplib.CUPS() # TODO : username and password and/or encryption 
    66         answer = server.getJobAttributes(self.JobId) 
    67         if answer is None : 
    68             raise PyKotaToolError, "Network error while querying the CUPS server : %s" \ 
    69                                       % server.lastErrorMessage 
    70         (dummy, self.Charset) = self.getAttributeTypeAndValue(answer, "attributes-charset", "operation") 
    71         (dummy, self.OriginatingUserName) = self.getAttributeTypeAndValue(answer, "job-originating-user-name") 
    72         (dummy, self.Title) = self.getAttributeTypeAndValue(answer, "job-name") 
    73         (dummy, self.BillingCode) = self.getAttributeTypeAndValue(answer, "job-billing") 
    74         (dummy, self.OriginatingHostName) = self.getAttributeTypeAndValue(answer, "job-originating-host-name") 
    75         (dummy, self.UUID) = self.getAttributeTypeAndValue(answer, "job-uuid") 
    76         (dummy, self.TimeAtCreation) = self.getAttributeTypeAndValue(answer, "time-at-creation") 
    77         (dummy, self.TimeAtProcessing) = self.getAttributeTypeAndValue(answer, "time-at-processing") 
    78         (dummy, self.MimeType) = self.getAttributeTypeAndValue(answer, "document-format") 
    79          
    80         for attrib in ("OriginatingUserName",  
    81                        "OriginatingHostName", 
    82                        "Title",  
    83                        "BillingCode", 
    84                        "PrinterName", 
    85                        "Options", 
    86                        "Charset", 
    87                        "UUID", 
    88                        "MimeType") : 
    89             try :            
    90                 setattr(self, attrib,  
    91                               getattr(self, attrib).decode("UTF-8", "replace")) 
    92             except AttributeError :                   
    93                 pass 
    94                  
    95         self.OriginalUserName = self.OriginatingUserName[:] 
     37class PyKotaToolError(PyKotaError) : 
     38    """PyKota Exception for all executables.""" 
     39    pass 
    9640     
    97 if __name__ == "__main__" :     
    98     import sys 
    99     if len(sys.argv) != 2 : 
    100         sys.stderr.write("usage : python cups.py jobid\n") 
    101     else :     
    102         job = JobTicket(int(sys.argv[1]), "FakePrinter") 
    103         for attribute in ("PrinterName", "Charset", "JobId", "Copies",  
    104                           "FileName", "OriginatingUserName",  
    105                           "Title", "BillingCode", "OriginatingHostName",  
    106                           "TimeAtCreation", "TimeAtProcessing", "UUID",  
    107                           "MimeType") : 
    108             sys.stdout.write("%s : %s\n" % (attribute, repr(getattr(job, attribute)))) 
     41class PyKotaToolError(PyKotaError) : 
     42    """PyKota Exception for all executables.""" 
     43    pass 
     44     
     45class PyKotaCommandLineError(PyKotaToolError) : 
     46    """PyKota Exception for errors on executables' command line.""" 
     47    pass 
     48     
     49class PyKotaStorageError(PyKotaError) : 
     50    """PyKota Exception for database backend related errors.""" 
     51    pass 
     52     
     53class PyKotaConfigError(PyKotaError) : 
     54    """PyKota Exception for errors in PyKota's configuration.""" 
     55    pass 
     56     
     57class PyKotaAccounterError(PyKotaError) : 
     58    """PyKota Exception for errors in PyKota accounters.""" 
     59    pass 
     60     
     61class PyKotaReporterError(PyKotaError) : 
     62    """PyKota Exception for errors in PyKota report generators.""" 
     63    pass 
     64     
     65class PyKotaLoggingError(PyKotaError) : 
     66    """PyKota Exception for errors in PyKota logging.""" 
     67    pass 
  • pykota/trunk/pykota/logger.py

    r3275 r3288  
    2626import imp 
    2727 
    28 class PyKotaLoggingError(Exception): 
    29     """An exception for logging related stuff.""" 
    30     def __init__(self, message = ""): 
    31         self.message = message 
    32         Exception.__init__(self, message) 
    33     def __repr__(self): 
    34         return self.message 
    35     __str__ = __repr__ 
     28from pykota.errors import PyKotaLoggingError 
    3629 
    3730def openLogger(backend) : 
  • pykota/trunk/pykota/reporter.py

    r3275 r3288  
    2727from mx import DateTime 
    2828 
    29 class PyKotaReporterError(Exception): 
    30     """An exception for Reporter related stuff.""" 
    31     def __init__(self, message = ""): 
    32         self.message = message 
    33         Exception.__init__(self, message) 
    34     def __repr__(self): 
    35         return self.message 
    36     __str__ = __repr__ 
     29from pykota.errors import PyKotaReporterError 
    3730     
    3831class BaseReporter :     
  • pykota/trunk/pykota/storage.py

    r3276 r3288  
    2727from mx import DateTime 
    2828 
    29 class PyKotaStorageError(Exception): 
    30     """An exception for database related stuff.""" 
    31     def __init__(self, message = ""): 
    32         self.message = message 
    33         Exception.__init__(self, message) 
    34     def __repr__(self): 
    35         return self.message 
    36     __str__ = __repr__ 
    37          
    38          
     29from pykota.errors import PyKotaStorageError 
     30 
    3931class StorageObject : 
    4032    """Object present in the database.""" 
  • pykota/trunk/pykota/storages/ldapstorage.py

    r3275 r3288  
    3737from mx import DateTime 
    3838 
    39 from pykota.storage import PyKotaStorageError, BaseStorage, \ 
     39from pykota.errors import PyKotaStorageError 
     40from pykota.storage import BaseStorage, \ 
    4041                           StorageUser, StorageGroup, StoragePrinter, \ 
    4142                           StorageJob, StorageLastJob, StorageUserPQuota, \ 
  • pykota/trunk/pykota/storages/mysqlstorage.py

    r3275 r3288  
    2525import time 
    2626 
    27 from pykota.storage import PyKotaStorageError, BaseStorage 
     27from pykota.errors import PyKotaStorageError 
     28from pykota.storage import BaseStorage 
    2829from pykota.storages.sql import SQLStorage 
    2930 
  • pykota/trunk/pykota/storages/pgstorage.py

    r3275 r3288  
    2626from types import StringType 
    2727 
    28 from pykota.storage import PyKotaStorageError, BaseStorage 
     28from pykota.errors import PyKotaStorageError 
     29from pykota.storage import BaseStorage 
    2930from pykota.storages.sql import SQLStorage 
    3031 
  • pykota/trunk/pykota/storages/sqlitestorage.py

    r3275 r3288  
    2525import time 
    2626 
    27 from pykota.storage import PyKotaStorageError, BaseStorage 
     27from pykota.errors import PyKotaStorageError 
     28from pykota.storage import BaseStorage 
    2829from pykota.storages.sql import SQLStorage 
    2930 
  • pykota/trunk/pykota/tool.py

    r3287 r3288  
    3939from mx import DateTime 
    4040 
     41from pykota.errors import PyKotaCommandLineError 
    4142from pykota import config, storage, logger 
    4243from pykota.version import __version__, __author__, __years__, __gplblurb__ 
     
    4647    return message 
    4748 
    48 class PyKotaToolError(Exception): 
    49     """An exception for PyKota related stuff.""" 
    50     def __init__(self, message = ""): 
    51         self.message = message 
    52         Exception.__init__(self, message) 
    53     def __repr__(self): 
    54         return self.message.encode(sys.stdout.encoding or "UTF-8", "replace") 
    55     __str__ = __repr__ 
    56      
    57 class PyKotaCommandLineError(PyKotaToolError) :     
    58     """An exception for Pykota command line tools.""" 
    59     pass 
    60      
    6149def crashed(message="Bug in PyKota") :     
    6250    """Minimal crash method."""