Changeset 2210

Show
Ignore:
Timestamp:
04/19/05 23:36:31 (19 years ago)
Author:
jerome
Message:

Early errors now finally generate meaningful error messages,
this will greatly help first timers during the setup phase.

Location:
pykota/trunk
Files:
20 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/autopykota

    r2147 r2210  
    108108        # Initializes the command line tool 
    109109        automat = AutoPyKota(doc=__doc__) 
     110        automat.deferredInit() 
    110111         
    111112        # parse and checks the command line 
  • pykota/trunk/bin/cupspykota

    r2177 r2210  
    705705    else :     
    706706        try : 
    707             try : 
    708                 # Initializes the backend 
    709                 kotabackend = PyKotaBackend()     
    710             except SystemExit :     
    711                 retcode = -1 
    712             except :     
    713                 crashed("cupspykota backend initialization failed") 
    714                 retcode = 1 
    715             else :     
    716                 retcode = kotabackend.mainWork() 
    717                 kotabackend.storage.close() 
    718                 kotabackend.closeJobDataStream()     
     707            # Initializes the backend 
     708            kotabackend = PyKotaBackend()     
     709            kotabackend.deferredInit() 
     710            retcode = kotabackend.mainWork() 
     711            kotabackend.storage.close() 
     712            kotabackend.closeJobDataStream()     
     713        except SystemExit :     
     714            retcode = -1 
    719715        except : 
    720716            try : 
  • pykota/trunk/bin/dumpykota

    r2147 r2210  
    138138        # Initializes the command line tool 
    139139        dumper = DumPyKota(doc=__doc__) 
     140        dumper.deferredInit() 
    140141         
    141142        # parse and checks the command line 
  • pykota/trunk/bin/edpykota

    r2147 r2210  
    506506        # Initializes the command line tool 
    507507        editor = EdPyKota(doc=__doc__) 
     508        editor.deferredInit() 
    508509         
    509510        # parse and checks the command line 
  • pykota/trunk/bin/lprngpykota

    r2147 r2210  
    268268    retcode = JSUCC 
    269269    try : 
    270         try : 
    271             # Initializes the backend 
    272             kotabackend = PyKotaFilter()     
    273         except SystemExit :     
    274             retcode = JABORT 
    275         except :     
    276             crashed("lprngpykota filter initialization failed") 
    277             retcode = JABORT 
    278         else :     
    279             retcode = kotabackend.mainWork() 
    280             kotabackend.storage.close() 
    281             kotabackend.closeJobDataStream()     
     270        # Initializes the backend 
     271        kotabackend = PyKotaFilter()     
     272        kotabackend.deferredInit() 
     273        retcode = kotabackend.mainWork() 
     274        kotabackend.storage.close() 
     275        kotabackend.closeJobDataStream()     
     276    except SystemExit :     
     277        retcode = JABORT 
    282278    except : 
    283279        try : 
  • pykota/trunk/bin/pkbanner

    r2193 r2210  
    303303        # Initializes the command line tool 
    304304        banner = PyKotaBanner(doc=__doc__) 
     305        banner.deferredInit() 
    305306         
    306307        # parse and checks the command line 
  • pykota/trunk/bin/pkhint

    r2147 r2210  
    2828import os 
    2929 
    30 from pykota.tool import PyKotaTool, PyKotaToolError, crashed, N_ 
    31 from pykota.config import PyKotaConfigError 
    32 from pykota.storage import PyKotaStorageError 
     30from pykota.tool import Tool, PyKotaToolError, crashed, N_ 
    3331try : 
    3432    import pysnmp 
     
    8987              ] 
    9088               
    91 class PKHint(PyKotaTool) : 
     89class PKHint(Tool) : 
    9290    """A class to autodetect the best accounting method for printers.""" 
    9391    def extractPrintersInformation(self) :     
     
    237235        # Initializes the command line tool 
    238236        manager = PKHint(doc=__doc__) 
     237        manager.deferredInit() 
    239238         
    240239        (options, args) = manager.parseCommandline(sys.argv[1:], short_options, long_options) 
     
    260259            crashed("pkhint failed") 
    261260        retcode = -1 
    262  
    263     try : 
    264         manager.storage.close() 
    265     except (TypeError, NameError, AttributeError) :     
    266         pass 
    267261         
    268262    sys.exit(retcode)     
  • pykota/trunk/bin/pkmail

    r2147 r2210  
    158158        # Initializes the command line tool 
    159159        mailparser = PKMail(doc=__doc__) 
     160        mailparser.deferredInit() 
    160161         
    161162        # parse and checks the command line 
  • pykota/trunk/bin/pkprinters

    r2147 r2210  
    206206        # Initializes the command line tool 
    207207        manager = PKPrinters(doc=__doc__) 
     208        manager.deferredInit() 
    208209         
    209210        # parse and checks the command line 
  • pykota/trunk/bin/pykosd

    r2147 r2210  
    167167         
    168168        cmd = PyKOSD(doc=__doc__) 
     169        cmd.deferredInit() 
    169170         
    170171        # parse and checks the command line 
  • pykota/trunk/bin/pykotme

    r2147 r2210  
    131131        # Initializes the command line tool 
    132132        sender = PyKotMe(doc=__doc__) 
     133        sender.deferredInit() 
    133134         
    134135        # parse and checks the command line 
  • pykota/trunk/bin/repykota

    r2147 r2210  
    138138        # Initializes the command line tool 
    139139        reportTool = RePyKota(doc=__doc__) 
     140        reportTool.deferredInit() 
    140141         
    141142        # parse and checks the command line 
  • pykota/trunk/bin/warnpykota

    r2147 r2210  
    153153        # Initializes the command line tool 
    154154        sender = WarnPyKota(doc=__doc__) 
     155        sender.deferredInit() 
    155156         
    156157        # parse and checks the command line 
  • pykota/trunk/cgi-bin/dumpykota.cgi

    r2174 r2210  
    177177    os.environ["LC_ALL"] = getLanguagePreference() 
    178178    admin = PyKotaDumperGUI(lang=os.environ["LC_ALL"], charset=getCharsetPreference()) 
     179    admin.deferredInit() 
    179180    admin.form = cgi.FieldStorage() 
    180181    admin.options = { "output" : "-", 
  • pykota/trunk/cgi-bin/printquota.cgi

    r2174 r2210  
    231231    os.environ["LC_ALL"] = getLanguagePreference() 
    232232    admin = PyKotaReportGUI(lang=os.environ["LC_ALL"], charset=getCharsetPreference()) 
     233    admin.deferredInit() 
    233234    admin.form = cgi.FieldStorage() 
    234235    admin.guiAction() 
  • pykota/trunk/cgi-bin/pykotme.cgi

    r2174 r2210  
    137137    os.environ["LC_ALL"] = getLanguagePreference() 
    138138    admin = PyKotMeGUI(lang=os.environ["LC_ALL"], charset=getCharsetPreference()) 
     139    admin.deferredInit() 
    139140    admin.form = cgi.FieldStorage() 
    140141    admin.guiAction() 
  • pykota/trunk/NEWS

    r2202 r2210  
    2222PyKota NEWS : 
    2323        
     24    - 1.22alpha6 : 
     25     
     26        - Early errors now produce meaningful error messages (finally !) 
     27         
    2428    - 1.22alpha5 : 
    2529        
  • pykota/trunk/pykota/storages/pgstorage.py

    r2147 r2210  
    4848            port = -1         # Use PostgreSQL's default tcp/ip port (5432). 
    4949         
    50         try : 
    51             self.database = pg.connect(host=host, port=port, dbname=dbname, user=user, passwd=passwd) 
    52         except PGError, msg : 
    53             raise PyKotaStorageError, str(msg) 
    54         else :     
    55             self.closed = 0 
    56             self.tool.logdebug("Database opened (host=%s, port=%s, dbname=%s, user=%s)" % (host, port, dbname, user)) 
     50        self.database = pg.connect(host=host, port=port, dbname=dbname, user=user, passwd=passwd) 
     51        self.closed = 0 
     52        self.tool.logdebug("Database opened (host=%s, port=%s, dbname=%s, user=%s)" % (host, port, dbname, user)) 
    5753             
    5854    def close(self) :     
  • pykota/trunk/pykota/tool.py

    r2195 r2210  
    7474         
    7575        # locale stuff 
    76         defaultToCLocale = 0 
     76        self.defaultToCLocale = 0 
    7777        try : 
    7878            locale.setlocale(locale.LC_ALL, lang) 
    7979        except (locale.Error, IOError) : 
    8080            locale.setlocale(locale.LC_ALL, "C") 
    81             defaultToCLocale = 1 
     81            self.defaultToCLocale = 1 
    8282        try : 
    8383            gettext.install("pykota") 
     
    109109        self.documentation = doc 
    110110         
     111    def deferredInit(self) :         
     112        """Deferred initialization.""" 
    111113        # try to find the configuration files in user's 'pykota' home directory. 
    112114        try : 
     
    120122            missingUser = 0 
    121123             
    122         try : 
    123             self.config = config.PyKotaConfig(confdir) 
    124         except ConfigParser.ParsingError, msg :     
    125             sys.stderr.write("ERROR: Problem encountered while parsing configuration file : %s\n" % msg) 
    126             sys.stderr.flush() 
    127             sys.exit(-1) 
    128              
    129         try : 
    130             self.debug = self.config.getDebug() 
    131             self.smtpserver = self.config.getSMTPServer() 
    132             self.maildomain = self.config.getMailDomain() 
    133             self.logger = logger.openLogger(self.config.getLoggingBackend()) 
    134         except (config.PyKotaConfigError, logger.PyKotaLoggingError, storage.PyKotaStorageError), msg : 
    135             self.crashed(msg) 
    136             raise 
     124        self.config = config.PyKotaConfig(confdir) 
     125        self.debug = self.config.getDebug() 
     126        self.smtpserver = self.config.getSMTPServer() 
     127        self.maildomain = self.config.getMailDomain() 
     128        self.logger = logger.openLogger(self.config.getLoggingBackend()) 
    137129             
    138130        # now drop priviledge if possible 
     
    143135        self.softwareJobPrice = 0.0 
    144136         
    145         if defaultToCLocale : 
     137        if self.defaultToCLocale : 
    146138            self.printInfo("Incorrect locale settings. PyKota falls back to the 'C' locale.", "warn") 
    147139        if missingUser :      
     
    201193        sys.stderr.flush() 
    202194         
     195    def matchString(self, s, patterns) : 
     196        """Returns 1 if the string s matches one of the patterns, else 0.""" 
     197        for pattern in patterns : 
     198            if fnmatch.fnmatchcase(s, pattern) : 
     199                return 1 
     200        return 0 
     201         
    203202    def display_version_and_quit(self) : 
    204203        """Displays version number, then exists successfully.""" 
     
    302301        """Initializes the command line tool and opens the database.""" 
    303302        Tool.__init__(self, lang, charset, doc) 
    304         try : 
    305             self.storage = storage.openConnection(self) 
    306         except storage.PyKotaStorageError, msg : 
    307             self.crashed(msg) 
    308             raise 
     303         
     304    def deferredInit(self) :     
     305        """Deferred initialization.""" 
     306        Tool.deferredInit(self) 
     307        self.storage = storage.openConnection(self) 
     308        if self.config.isAdmin : # TODO : We don't know this before, fix this ! 
     309            self.logdebug("Beware : running as a PyKota administrator !") 
    309310        else :     
    310             if self.config.isAdmin : # TODO : We don't know this before, fix this ! 
    311                 self.logdebug("Beware : running as a PyKota administrator !") 
    312             else :     
    313                 self.logdebug("Don't Panic : running as a mere mortal !") 
     311            self.logdebug("Don't Panic : running as a mere mortal !") 
    314312         
    315313    def clean(self) :     
     
    327325                return 0 
    328326        return 1         
    329          
    330     def matchString(self, s, patterns) : 
    331         """Returns 1 if the string s matches one of the patterns, else 0.""" 
    332         for pattern in patterns : 
    333             if fnmatch.fnmatchcase(s, pattern) : 
    334                 return 1 
    335         return 0 
    336327         
    337328    def sendMessage(self, adminmail, touser, fullmessage) : 
     
    655646         self.originalbackend) = self.extractInfoFromCupsOrLprng() 
    656647          
     648    def deferredInit(self) : 
     649        """Deferred initialization.""" 
     650        PyKotaTool.deferredInit(self) 
     651         
    657652        arguments = " ".join(['"%s"' % arg for arg in sys.argv]) 
    658653        self.logdebug(_("Printing system %s, args=%s") % (str(self.printingsystem), arguments)) 
  • pykota/trunk/pykota/version.py

    r2202 r2210  
    2222# 
    2323 
    24 __version__ = "1.22alpha5_unofficial" 
     24__version__ = "1.22alpha6_unofficial" 
    2525 
    2626__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""