Changeset 2797 for pykota/trunk

Show
Ignore:
Timestamp:
03/20/06 16:45:50 (19 years ago)
Author:
jerome
Message:

Now uses the 'mailto' directive when user doesn't exist or doesn't have a print quota entry,
or when printer doesn't exist. NB : UNTESTED !

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/cupspykota

    r2786 r2797  
    4949from pykota.storage import PyKotaStorageError 
    5050         
     51class FakeObject :         
     52    def __init__(self, name) : 
     53        """Fake init.""" 
     54        self.Name = name 
     55         
     56class FakePrinter(FakeObject) :         
     57    """Fake printer instance.""" 
     58    pass 
     59     
     60class FakeUser(FakeObject) :     
     61    """Fake user instance.""" 
     62    def __init__(self, name) : 
     63        """Fake init.""" 
     64        self.Email = name 
     65        FakeObject.__init__(self, name) 
     66     
    5167class CUPSBackend(PyKotaTool) : 
    5268    """Base class for tools with no database access.""" 
     
    256272        self.logdebug("JobOriginatingHostName : %s" % self.ClientHost) 
    257273         
     274        # fakes some entries to allow for external mailto 
     275        # before real entries are extracted from the database. 
     276        self.User = FakeUser(self.UserName) 
     277        self.Printer = FakePrinter(self.PrinterName) 
     278         
    258279        self.enableSigInt() 
    259280        self.logdebug("Backend initialized.") 
     
    849870                        msg["Subject"] = str(Header(_("Print Quota"), charset=self.charset)) 
    850871                        msg["From"] = adminmail 
    851                         msg["To"] = usermail 
    852                         msg["Cc"] = adminmail 
     872                        if mailto in ("BOTH", "USER") : 
     873                            msg["To"] = usermail 
     874                            if mailto == "BOTH" : 
     875                                msg["Cc"] = adminmail 
     876                        else :     
     877                            msg["To"] = adminmail 
    853878                        server.sendmail(adminmail, destination, msg.as_string()) 
    854879                    except smtplib.SMTPException, answer :     
     
    864889            # higher in the chain failed because of a misconfiguration. 
    865890            # we deny the job in this case (nothing to print anyway) 
    866             self.printInfo(_("Job contains no data. Printing is denied."), "error") 
     891            self.Reason = _("Job contains no data. Printing is denied.") 
     892            self.printInfo(self.Reason, "error") 
     893            self.tellUser() 
    867894            return self.removeJob() 
    868895             
     
    870897        if self.Policy == "EXTERNALERROR" : 
    871898            # Policy was 'EXTERNAL' and the external command returned an error code 
     899            self.Reason = _("Error in external policy script. Printing is denied.") 
     900            self.printInfo(self.Reason, "error") 
     901            self.tellUser() 
    872902            return self.removeJob() 
    873903        elif self.Policy == "EXTERNAL" : 
    874904            # Policy was 'EXTERNAL' and the external command wasn't able 
    875905            # to add either the printer, user or user print quota 
     906            self.Reason = _("Still no print quota entry for user %s on printer %s after external policy. Printing is denied.") % (self.UserName, self.PrinterName) 
     907            self.printInfo(self.Reason, "warn") 
     908            self.tellUser() 
    876909            return self.removeJob() 
    877910        elif self.Policy == "DENY" :     
    878911            # Either printer, user or user print quota doesn't exist, 
    879912            # and the job should be rejected. 
     913            self.Reason = _("Printing is denied by printer policy.") 
     914            self.printInfo(self.Reason, "warn") 
     915            self.tellUser() 
    880916            return self.removeJob() 
    881917        elif self.Policy == "ALLOW" : 
    882918            # ALLOW means : Either printer, user or user print quota doesn't exist, 
    883919            #               but the job should be allowed anyway. 
    884             self.printInfo(_("Job allowed by printer policy. No accounting will be done."), "warn") 
     920            self.Reason = _("Job allowed by printer policy. No accounting will be done.") 
     921            self.printInfo(self.Reason, "warn") 
     922            self.tellUser() 
    885923            return self.printJobDatas() 
    886924        elif self.Policy == "OK" : 
     
    889927            return self.doWork() 
    890928        else :     
    891             self.printInfo(_("Invalid policy %s for printer %s") % (self.Policy, self.PrinterName), "error") 
     929            self.Reason = _("Invalid policy %s for printer %s") % (self.Policy, self.PrinterName) 
     930            self.printInfo(self.Reason, "error") 
     931            self.tellUser() 
    892932            return self.removeJob() 
    893933