Changeset 1520

Show
Ignore:
Timestamp:
06/04/04 01:14:11 (20 years ago)
Author:
jalet
Message:

Now stores the job's size in bytes in the database.
Preliminary work on payments storage : database schemas are OK now,
but no code to store payments yet.
Removed schema picture, not relevant anymore.

Location:
pykota/trunk
Files:
1 removed
8 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/cupspykota

    r1519 r1520  
    2424# 
    2525# $Log$ 
     26# Revision 1.60  2004/06/03 23:14:08  jalet 
     27# Now stores the job's size in bytes in the database. 
     28# Preliminary work on payments storage : database schemas are OK now, 
     29# but no code to store payments yet. 
     30# Removed schema picture, not relevant anymore. 
     31# 
    2632# Revision 1.59  2004/06/03 22:12:53  jalet 
    2733# Now denies empty jobs 
     
    403409             
    404410            # adds the current job to history     
    405             printer.addJobToHistory(self.jobid, user, self.accounter.getLastPageCounter(), action, jobsize, jobprice, self.preserveinputfile, self.title, self.copies, self.options, clienthost) 
     411            printer.addJobToHistory(self.jobid, user, self.accounter.getLastPageCounter(), action, jobsize, jobprice, self.preserveinputfile, self.title, self.copies, self.options, clienthost, self.jobSizeBytes) 
    406412            self.logdebug("Job added to history.") 
    407413             
  • pykota/trunk/initscripts/ldap/pykota.schema

    r1480 r1520  
    175175        SUBSTR caseIgnoreSubstringsMatch 
    176176        SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{256} ) 
     177         
     178# pykotaJobSizeBytes 
     179attributetype ( 1.3.6.1.4.1.16868.1.1.25 NAME 'pykotaJobSizeBytes' 
     180        DESC 'Current job size in number of bytes in the history' 
     181        EQUALITY integerMatch 
     182        SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE ) 
     183 
     184# pykotaPayments 
     185attributetype ( 1.3.6.1.4.1.16868.1.1.26 NAME 'pykotaPayments' 
     186        DESC 'Stores all payments made by an user, encoded to store both date and amount' 
     187        EQUALITY caseExactIA5Match 
     188        SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 ) 
    177189 
    178190#         
     
    214226        DESC 'An entry in the job history for a printer' 
    215227        MUST ( cn $ pykotaUserName $ pykotaPrinterName $ pykotaJobId ) 
    216         MAY  ( pykotaPrinterPageCounter $ pykotaJobSize $ pykotaAction $ pykotaJobPrice $ pykotaFileName $ pykotaTitle $ pykotaCopies $ pykotaOptions $ pykotaHostName ) ) 
     228        MAY  ( pykotaPrinterPageCounter $ pykotaJobSize $ pykotaAction $ pykotaJobPrice $ pykotaFileName $ pykotaTitle $ pykotaCopies $ pykotaOptions $ pykotaHostName $ pykotaJobSizeBytes ) ) 
    217229         
    218230# pykotaAccountBalance 
    219231objectclass ( 1.3.6.1.4.1.16868.1.2.7 NAME 'pykotaAccountBalance' SUP top AUXILIARY 
    220232        DESC 'PyKota User account balance' 
    221         MAY  ( pykotaUserName $ pykotaBalance $ pykotaLifeTimePaid ) ) 
     233        MAY  ( pykotaUserName $ pykotaBalance $ pykotaLifeTimePaid $ pykotaPayments ) ) 
    222234         
    223235# pykotaLastJob         
  • pykota/trunk/initscripts/postgresql/pykota-postgresql.sql

    r1473 r1520  
    2020-- 
    2121-- $Log$ 
     22-- Revision 1.10  2004/06/03 23:14:09  jalet 
     23-- Now stores the job's size in bytes in the database. 
     24-- Preliminary work on payments storage : database schemas are OK now, 
     25-- but no code to store payments yet. 
     26-- Removed schema picture, not relevant anymore. 
     27-- 
    2228-- Revision 1.9  2004/05/13 11:15:29  jalet 
    2329-- Added hostname field in job history 
     
    121127                        userid INT4, 
    122128                        printerid INT4, 
    123                         hostname TEXT, 
    124129                        pagecounter INT4 DEFAULT 0, 
     130                        jobsizebytes INT8, 
    125131                        jobsize INT4, 
    126132                        jobprice FLOAT, 
     
    130136                        copies INT4, 
    131137                        options TEXT, 
     138                        hostname TEXT, 
    132139                        jobdate TIMESTAMP DEFAULT now(), 
    133140                        CONSTRAINT checkUserPQuota FOREIGN KEY (userid, printerid) REFERENCES userpquota(userid, printerid)); 
    134141CREATE INDEX jobhistory_p_id_ix ON jobhistory (printerid); 
    135142CREATE INDEX jobhistory_pd_id_ix ON jobhistory (printerid, jobdate); 
     143CREATE INDEX jobhistory_hostname_ix ON jobhistory (hostname); 
    136144                         
    137145-- 
     
    159167                           printerid INT4 REFERENCES printers(id), 
    160168                           PRIMARY KEY (groupid, printerid)); 
     169-- 
     170-- Create the table for payments 
     171--  
     172CREATE TABLE payments (id SERIAL PRIMARY KEY NOT NULL, 
     173                       userid INT4 REFERENCES users(id), 
     174                       amount FLOAT, 
     175                       date TIMESTAMP DEFAULT now()); 
     176CREATE INDEX payments_date_ix ON payments (date); 
    161177 
    162178--                         
    163179-- Set some ACLs                         
    164180-- 
    165 REVOKE ALL ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory FROM public;                         
    166 REVOKE ALL ON users_id_seq, groups_id_seq, printers_id_seq, userpquota_id_seq, grouppquota_id_seq, jobhistory_id_seq FROM public; 
     181REVOKE ALL ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments FROM public;                         
     182REVOKE ALL ON users_id_seq, groups_id_seq, printers_id_seq, userpquota_id_seq, grouppquota_id_seq, jobhistory_id_seq, payments_id_seq FROM public; 
    167183 
    168 GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory TO pykotaadmin; 
    169 GRANT SELECT, UPDATE ON users_id_seq, groups_id_seq, printers_id_seq, userpquota_id_seq, grouppquota_id_seq, jobhistory_id_seq TO pykotaadmin; 
    170 GRANT SELECT ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory TO pykotauser; 
     184GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments TO pykotaadmin; 
     185GRANT SELECT, UPDATE ON users_id_seq, groups_id_seq, printers_id_seq, userpquota_id_seq, grouppquota_id_seq, jobhistory_id_seq, payments_id_seq TO pykotaadmin; 
     186GRANT SELECT ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments TO pykotauser; 
    171187 
  • pykota/trunk/initscripts/postgresql/upgrade-to-1.19.sql

    r1473 r1520  
    2020-- 
    2121-- $Log$ 
     22-- Revision 1.2  2004/06/03 23:14:10  jalet 
     23-- Now stores the job's size in bytes in the database. 
     24-- Preliminary work on payments storage : database schemas are OK now, 
     25-- but no code to store payments yet. 
     26-- Removed schema picture, not relevant anymore. 
     27-- 
    2228-- Revision 1.1  2004/05/13 11:15:29  jalet 
    2329-- Added hostname field in job history 
     
    3945-- Modify the old database schema 
    4046-- 
     47ALTER TABLE jobhistory ADD COLUMN jobsizebytes INT8; 
    4148ALTER TABLE jobhistory ADD COLUMN hostname TEXT; 
     49CREATE INDEX jobhistory_hostname_ix ON jobhistory (hostname); 
    4250 
     51CREATE TABLE payments (id SERIAL PRIMARY KEY NOT NULL, 
     52                       userid INT4 REFERENCES users(id), 
     53                       amount FLOAT, 
     54                       date TIMESTAMP DEFAULT now()); 
     55CREATE INDEX payments_date_ix ON payments (date); 
     56 
     57REVOKE ALL ON payments FROM public;                         
     58REVOKE ALL ON payments_id_seq FROM public; 
     59GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON payments TO pykotaadmin; 
     60GRANT SELECT, UPDATE ON payments_id_seq TO pykotaadmin; 
     61GRANT SELECT ON payments TO pykotauser; 
  • pykota/trunk/pykota/storage.py

    r1502 r1520  
    2222# 
    2323# $Log$ 
     24# Revision 1.53  2004/06/03 23:14:10  jalet 
     25# Now stores the job's size in bytes in the database. 
     26# Preliminary work on payments storage : database schemas are OK now, 
     27# but no code to store payments yet. 
     28# Removed schema picture, not relevant anymore. 
     29# 
    2430# Revision 1.52  2004/05/26 14:49:57  jalet 
    2531# First try at saving the job-originating-hostname in the database 
     
    303309            raise AttributeError, name 
    304310             
    305     def addJobToHistory(self, jobid, user, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None) : 
     311    def addJobToHistory(self, jobid, user, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None, jobsizebytes=None) : 
    306312        """Adds a job to the printer's history.""" 
    307         self.parent.writeJobNew(self, user, jobid, pagecounter, action, jobsize, jobprice, filename, title, copies, options, clienthost) 
     313        self.parent.writeJobNew(self, user, jobid, pagecounter, action, jobsize, jobprice, filename, title, copies, options, clienthost, jobsizebytes) 
    308314        # TODO : update LastJob object ? Probably not needed. 
    309315         
     
    449455        self.JobId = None 
    450456        self.PrinterPageCounter = None 
     457        self.JobSizeBytes = None 
    451458        self.JobSize = None 
    452459        self.JobAction = None 
  • pykota/trunk/pykota/storages/ldapstorage.py

    r1510 r1520  
    2222# 
    2323# $Log$ 
     24# Revision 1.67  2004/06/03 23:14:10  jalet 
     25# Now stores the job's size in bytes in the database. 
     26# Preliminary work on payments storage : database schemas are OK now, 
     27# but no code to store payments yet. 
     28# Removed schema picture, not relevant anymore. 
     29# 
    2430# Revision 1.66  2004/05/28 20:56:45  jalet 
    2531# Extended syntax for LDAP specific newuser and newgroup directives. Untested. 
     
    603609            lastjob.lastjobident = result[0][0] 
    604610            lastjobident = result[0][1]["pykotaLastJobIdent"][0] 
    605             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) 
     611            result = self.doSearch("objectClass=pykotaJob", ["pykotaJobSizeBytes", "pykotaHostName", "pykotaUserName", "pykotaJobId", "pykotaPrinterPageCounter", "pykotaJobSize", "pykotaAction", "pykotaJobPrice", "pykotaFileName", "pykotaTitle", "pykotaCopies", "pykotaOptions", "createTimestamp"], base="cn=%s,%s" % (lastjobident, self.info["jobbase"]), scope=ldap.SCOPE_BASE) 
    606612            if result : 
    607613                fields = result[0][1] 
     
    618624                lastjob.JobOptions = fields.get("pykotaOptions", [""])[0] 
    619625                lastjob.JobHostName = fields.get("pykotaHostName", [""])[0] 
     626                lastjob.JobSizeBytes = fields.get("pykotaJobSizeBytes", [0L])[0] 
    620627                date = fields.get("createTimestamp", ["19700101000000"])[0] 
    621628                year = int(date[:4]) 
     
    945952        self.doModify(lastjob.ident, fields)          
    946953         
    947     def writeJobNew(self, printer, user, jobid, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None) : 
     954    def writeJobNew(self, printer, user, jobid, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None, jobsizebytes=None) : 
    948955        """Adds a job in a printer's history.""" 
    949956        if (not self.disablehistory) or (not printer.LastJob.Exists) : 
     
    966973                   "pykotaOptions" : str(options),  
    967974                   "pykotaHostName" : str(clienthost),  
     975                   "pykotaJobSizeBytes" : str(jobsizebytes), 
    968976                 } 
    969977        if (not self.disablehistory) or (not printer.LastJob.Exists) : 
     
    10461054            where = precond 
    10471055        jobs = []     
    1048         result = self.doSearch(where, fields=["pykotaHostName", "pykotaUserName", "pykotaPrinterName", "pykotaJobId", "pykotaPrinterPageCounter", "pykotaAction", "pykotaJobSize", "pykotaJobPrice", "pykotaFileName", "pykotaTitle", "pykotaCopies", "pykotaOptions", "createTimestamp"], base=self.info["jobbase"]) 
     1056        result = self.doSearch(where, fields=["pykotaJobSizeBytes", "pykotaHostName", "pykotaUserName", "pykotaPrinterName", "pykotaJobId", "pykotaPrinterPageCounter", "pykotaAction", "pykotaJobSize", "pykotaJobPrice", "pykotaFileName", "pykotaTitle", "pykotaCopies", "pykotaOptions", "createTimestamp"], base=self.info["jobbase"]) 
    10491057        if result : 
    10501058            for (ident, fields) in result : 
     
    10611069                job.JobOptions = fields.get("pykotaOptions", [""])[0] 
    10621070                job.JobHostName = fields.get("pykotaHostName", [""])[0] 
     1071                job.JobSizeBytes = fields.get("pykotaJobSizeBytes", [0L])[0] 
    10631072                date = fields.get("createTimestamp", ["19700101000000"])[0] 
    10641073                year = int(date[:4]) 
  • pykota/trunk/pykota/storages/pgstorage.py

    r1327 r1520  
    2222# 
    2323# $Log$ 
     24# Revision 1.36  2004/06/03 23:14:11  jalet 
     25# Now stores the job's size in bytes in the database. 
     26# Preliminary work on payments storage : database schemas are OK now, 
     27# but no code to store payments yet. 
     28# Removed schema picture, not relevant anymore. 
     29# 
    2430# Revision 1.35  2004/02/02 22:44:16  jalet 
    2531# Preliminary work on Relationnal Database Independance via DB-API 2.0 
     
    223229        elif type(field) == type(0) :     
    224230            typ = "int" 
     231        elif type(field) == type(0L) :     
     232            typ = "int" 
    225233        else :     
    226234            typ = "text" 
  • pykota/trunk/pykota/storages/sql.py

    r1502 r1520  
    2222# 
    2323# $Log$ 
     24# Revision 1.40  2004/06/03 23:14:11  jalet 
     25# Now stores the job's size in bytes in the database. 
     26# Preliminary work on payments storage : database schemas are OK now, 
     27# but no code to store payments yet. 
     28# Removed schema picture, not relevant anymore. 
     29# 
    2430# Revision 1.39  2004/05/26 14:50:12  jalet 
    2531# First try at saving the job-originating-hostname in the database 
     
    162168            lastjob.JobDate = fields.get("jobdate") 
    163169            lastjob.JobHostName = fields.get("hostname") 
     170            lastjob.JobSizeBytes = fields.get("jobsizebytes") 
    164171            lastjob.Exists = 1 
    165172        return lastjob 
     
    339346        self.doModify("UPDATE jobhistory SET jobsize=%s, jobprice=%s WHERE id=%s" % (self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(lastjob.ident))) 
    340347         
    341     def writeJobNew(self, printer, user, jobid, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None) :     
     348    def writeJobNew(self, printer, user, jobid, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None, jobsizebytes=None) :     
    342349        """Adds a job in a printer's history.""" 
    343350        if (not self.disablehistory) or (not printer.LastJob.Exists) : 
    344351            if jobsize is not None : 
    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))) 
     352                self.doModify("INSERT INTO jobhistory (userid, printerid, jobid, pagecounter, action, jobsize, jobprice, filename, title, copies, options, hostname, jobsizebytes) VALUES (%s, %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), self.doQuote(jobsizebytes))) 
    346353            else :     
    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))) 
     354                self.doModify("INSERT INTO jobhistory (userid, printerid, jobid, pagecounter, action, filename, title, copies, options, hostname, jobsizebytes) 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(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options), self.doQuote(clienthost), self.doQuote(jobsizebytes))) 
    348355        else :         
    349356            # here we explicitly want to reset jobsize to NULL if needed 
    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))) 
     357            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, jobsizebytes=%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(jobsizebytes), self.doQuote(printer.LastJob.ident))) 
    351358             
    352359    def writeUserPQuotaLimits(self, userpquota, softlimit, hardlimit) : 
     
    406413                job.JobDate = fields.get("jobdate") 
    407414                job.JobHostName = fields.get("hostname") 
     415                job.JobSizeBytes = fields.get("jobsizebytes") 
    408416                job.UserName = fields.get("username") 
    409417                job.PrinterName = fields.get("printername")