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.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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))