Changeset 1502 for pykota/trunk/pykota

Show
Ignore:
Timestamp:
05/26/04 16:50:12 (20 years ago)
Author:
jalet
Message:

First try at saving the job-originating-hostname in the database

Location:
pykota/trunk/pykota
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/storage.py

    r1418 r1502  
    2222# 
    2323# $Log$ 
     24# Revision 1.52  2004/05/26 14:49:57  jalet 
     25# First try at saving the job-originating-hostname in the database 
     26# 
    2427# Revision 1.51  2004/03/24 15:15:24  jalet 
    2528# Began integration of Henrik Janhagen's work on quota-then-balance 
     
    300303            raise AttributeError, name 
    301304             
    302     def addJobToHistory(self, jobid, user, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None) : 
     305    def addJobToHistory(self, jobid, user, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None) : 
    303306        """Adds a job to the printer's history.""" 
    304         self.parent.writeJobNew(self, user, jobid, pagecounter, action, jobsize, jobprice, filename, title, copies, options) 
     307        self.parent.writeJobNew(self, user, jobid, pagecounter, action, jobsize, jobprice, filename, title, copies, options, clienthost) 
    305308        # TODO : update LastJob object ? Probably not needed. 
    306309         
     
    454457        self.JobCopies = None 
    455458        self.JobOptions = None 
     459        self.JobHostName = None 
    456460         
    457461    def __getattr__(self, name) :     
  • pykota/trunk/pykota/storages/ldapstorage.py

    r1451 r1502  
    2222# 
    2323# $Log$ 
     24# Revision 1.64  2004/05/26 14:50:01  jalet 
     25# First try at saving the job-originating-hostname in the database 
     26# 
    2427# Revision 1.63  2004/05/06 12:37:46  jalet 
    2528# pkpgcounter : comments 
     
    591594            lastjob.lastjobident = result[0][0] 
    592595            lastjobident = result[0][1]["pykotaLastJobIdent"][0] 
    593             result = self.doSearch("objectClass=pykotaJob", ["pykotaUserName", "pykotaJobId", "pykotaPrinterPageCounter", "pykotaJobSize", "pykotaAction", "pykotaJobPrice", "pykotaFileName", "pykotaTitle", "pykotaCopies", "pykotaOptions", "createTimestamp"], base="cn=%s,%s" % (lastjobident, self.info["jobbase"]), scope=ldap.SCOPE_BASE) 
     596            result = self.doSearch("objectClass=pykotaJob", ["pykotaHostName", "pykotaUserName", "pykotaJobId", "pykotaPrinterPageCounter", "pykotaJobSize", "pykotaAction", "pykotaJobPrice", "pykotaFileName", "pykotaTitle", "pykotaCopies", "pykotaOptions", "createTimestamp"], base="cn=%s,%s" % (lastjobident, self.info["jobbase"]), scope=ldap.SCOPE_BASE) 
    594597            if result : 
    595598                fields = result[0][1] 
     
    605608                lastjob.JobCopies = int(fields.get("pykotaCopies", [0])[0]) 
    606609                lastjob.JobOptions = fields.get("pykotaOptions", [""])[0] 
     610                lastjob.JobHostName = fields.get("pykotaHostName", [""])[0] 
    607611                date = fields.get("createTimestamp", ["19700101000000"])[0] 
    608612                year = int(date[:4]) 
     
    912916        self.doModify(lastjob.ident, fields)          
    913917         
    914     def writeJobNew(self, printer, user, jobid, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None) : 
     918    def writeJobNew(self, printer, user, jobid, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None) : 
    915919        """Adds a job in a printer's history.""" 
    916920        if (not self.disablehistory) or (not printer.LastJob.Exists) : 
     
    932936                   "pykotaCopies" : str(copies),  
    933937                   "pykotaOptions" : str(options),  
     938                   "pykotaHostName" : str(clienthost),  
    934939                 } 
    935940        if (not self.disablehistory) or (not printer.LastJob.Exists) : 
     
    9971002            self.doModify(pgroup.ident, fields)          
    9981003             
    999     def retrieveHistory(self, user=None, printer=None, datelimit=None, limit=100) :     
     1004    def retrieveHistory(self, user=None, printer=None, datelimit=None, hostname=None, limit=100) :     
    10001005        """Retrieves all print jobs for user on printer (or all) before date, limited to first 100 results.""" 
    10011006        precond = "(objectClass=pykotaJob)" 
     
    10051010        if (printer is not None) and printer.Exists : 
    10061011            where.append("(pykotaPrinterName=%s)" % printer.Name) 
     1012        if hostname is not None : 
     1013            where.append("(pykotaHostName=%s)" % hostname) 
    10071014        if where :     
    10081015            where = "(&%s)" % "".join([precond] + where) 
     
    10101017            where = precond 
    10111018        jobs = []     
    1012         result = self.doSearch(where, fields=["pykotaUserName", "pykotaPrinterName", "pykotaJobId", "pykotaPrinterPageCounter", "pykotaAction", "pykotaJobSize", "pykotaJobPrice", "pykotaFileName", "pykotaTitle", "pykotaCopies", "pykotaOptions", "createTimestamp"], base=self.info["jobbase"]) 
     1019        result = self.doSearch(where, fields=["pykotaHostName", "pykotaUserName", "pykotaPrinterName", "pykotaJobId", "pykotaPrinterPageCounter", "pykotaAction", "pykotaJobSize", "pykotaJobPrice", "pykotaFileName", "pykotaTitle", "pykotaCopies", "pykotaOptions", "createTimestamp"], base=self.info["jobbase"]) 
    10131020        if result : 
    10141021            for (ident, fields) in result : 
     
    10241031                job.JobCopies = int(fields.get("pykotaCopies", [0])[0]) 
    10251032                job.JobOptions = fields.get("pykotaOptions", [""])[0] 
     1033                job.JobHostName = fields.get("pykotaHostName", [""])[0] 
    10261034                date = fields.get("createTimestamp", ["19700101000000"])[0] 
    10271035                year = int(date[:4]) 
  • pykota/trunk/pykota/storages/sql.py

    r1451 r1502  
    2222# 
    2323# $Log$ 
     24# Revision 1.39  2004/05/26 14:50:12  jalet 
     25# First try at saving the job-originating-hostname in the database 
     26# 
    2427# Revision 1.38  2004/05/06 12:37:47  jalet 
    2528# pkpgcounter : comments 
     
    143146        """Extracts a printer's last job information.""" 
    144147        lastjob = StorageLastJob(self, printer) 
    145         result = self.doSearch("SELECT jobhistory.id, jobid, userid, username, pagecounter, jobsize, jobprice, filename, title, copies, options, jobdate FROM jobhistory, users WHERE printerid=%s AND userid=users.id ORDER BY jobdate DESC LIMIT 1" % self.doQuote(printer.ident)) 
     148        result = self.doSearch("SELECT jobhistory.id, jobid, userid, username, pagecounter, jobsize, jobprice, filename, title, copies, options, hostname, jobdate FROM jobhistory, users WHERE printerid=%s AND userid=users.id ORDER BY jobdate DESC LIMIT 1" % self.doQuote(printer.ident)) 
    146149        if result : 
    147150            fields = result[0] 
     
    158161            lastjob.JobOptions = fields.get("options") 
    159162            lastjob.JobDate = fields.get("jobdate") 
     163            lastjob.JobHostName = fields.get("hostname") 
    160164            lastjob.Exists = 1 
    161165        return lastjob 
     
    335339        self.doModify("UPDATE jobhistory SET jobsize=%s, jobprice=%s WHERE id=%s" % (self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(lastjob.ident))) 
    336340         
    337     def writeJobNew(self, printer, user, jobid, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None) :     
     341    def writeJobNew(self, printer, user, jobid, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None) :     
    338342        """Adds a job in a printer's history.""" 
    339343        if (not self.disablehistory) or (not printer.LastJob.Exists) : 
    340344            if jobsize is not None : 
    341                 self.doModify("INSERT INTO jobhistory (userid, printerid, jobid, pagecounter, action, jobsize, jobprice, filename, title, copies, options) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(printer.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options))) 
     345                self.doModify("INSERT INTO jobhistory (userid, printerid, jobid, pagecounter, action, jobsize, jobprice, filename, title, copies, options, hostname) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(printer.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options), self.doQuote(clienthost))) 
    342346            else :     
    343                 self.doModify("INSERT INTO jobhistory (userid, printerid, jobid, pagecounter, action, filename, title, copies, options) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(printer.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options))) 
     347                self.doModify("INSERT INTO jobhistory (userid, printerid, jobid, pagecounter, action, filename, title, copies, options, hostname) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(printer.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options), self.doQuote(clienthost))) 
    344348        else :         
    345349            # here we explicitly want to reset jobsize to NULL if needed 
    346             self.doModify("UPDATE jobhistory SET userid=%s, jobid=%s, pagecounter=%s, action=%s, jobsize=%s, jobprice=%s, filename=%s, title=%s, copies=%s, options=%s, jobdate=now() WHERE id=%s" % (self.doQuote(user.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options), self.doQuote(printer.LastJob.ident))) 
     350            self.doModify("UPDATE jobhistory SET userid=%s, jobid=%s, pagecounter=%s, action=%s, jobsize=%s, jobprice=%s, filename=%s, title=%s, copies=%s, options=%s, hostname=%s, jobdate=now() WHERE id=%s" % (self.doQuote(user.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options), self.doQuote(clienthost), self.doQuote(printer.LastJob.ident))) 
    347351             
    348352    def writeUserPQuotaLimits(self, userpquota, softlimit, hardlimit) : 
     
    368372        self.doModify("DELETE FROM printergroupsmembers WHERE groupid=%s AND printerid=%s" % (self.doQuote(pgroup.ident), self.doQuote(printer.ident))) 
    369373         
    370     def retrieveHistory(self, user=None, printer=None, datelimit=None, limit=100) :     
     374    def retrieveHistory(self, user=None, printer=None, datelimit=None, hostname=None, limit=100) :     
    371375        """Retrieves all print jobs for user on printer (or all) before date, limited to first 100 results.""" 
    372376        query = "SELECT jobhistory.*,username,printername FROM jobhistory,users,printers WHERE users.id=userid AND printers.id=printerid" 
     
    376380        if (printer is not None) and printer.Exists : 
    377381            where.append("printerid=%s" % self.doQuote(printer.ident)) 
     382        if hostname is not None :     
     383            where.append("hostname=%s" % self.doQuote(hostname)) 
    378384        if datelimit is not None :     
    379385            where.append("jobdate<=%s" % self.doQuote(datelimit)) 
     
    399405                job.JobOptions = fields.get("options") 
    400406                job.JobDate = fields.get("jobdate") 
     407                job.JobHostName = fields.get("hostname") 
    401408                job.UserName = fields.get("username") 
    402409                job.PrinterName = fields.get("printername") 
  • pykota/trunk/pykota/version.py

    r1500 r1502  
    2222# 
    2323 
    24 __version__ = "1.19alpha15_unofficial" 
     24__version__ = "1.19alpha16_unofficial" 
    2525 
    2626__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""