Changeset 2638

Show
Ignore:
Timestamp:
02/02/06 19:30:32 (18 years ago)
Author:
matt
Message:

Initial MySQL support

Location:
pykota/trunk
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/checkdeps.py

    r2629 r2638  
    7070    modulestocheck = [ ("Python-PygreSQL", "pg", "PygreSQL is mandatory if you want to use PostgreSQL as the quota database backend.\nSee http://www.pygresql.org"), 
    7171                       ("Python-SQLite", "pysqlite2", "Python-SQLite is mandatory if you want to use SQLite as the quota database backend.\nSee http://www.pysqlite.org"), 
     72                       ("MySQL-Python", "MySQLdb", "MySQL-Python is mandatory if you want to use MySQL as the quota database backend.\nSee http://sourceforge.net/projects/mysql-python"), 
    7273                       ("Python-egenix-mxDateTime", "mx.DateTime", "eGenix' mxDateTime is mandatory for PyKota to work.\nSee http://www.egenix.com"), 
    7374                       ("Python-LDAP", "ldap", "Python-LDAP is mandatory if you plan to use an LDAP\ndirectory as the quota database backend.\nSee http://python-ldap.sf.net"), 
  • pykota/trunk/conf/pykota.conf.sample

    r2635 r2638  
    4949# Storage backend for quotas 
    5050# only PGStorage (PostgreSQL), LDAPStorage (OpenLDAP or else), 
    51 # and SQLiteStorage (SQLite 3) are supported. 
    52 # 
    53 # MySQL and BerkeleyDB are planned. 
     51# MySQLStorage (MySQL) and SQLiteStorage (SQLite 3) are supported. 
     52# 
     53# BerkeleyDB is planned. 
    5454 
    5555#################################################################### 
     
    6060#storagename: /etc/pykota/pykota.db 
    6161 
    62 #################################################################### 
    63 # PostgreSQL : comment this section out if you use another backend # 
    64 #################################################################### 
     62############################################################################ 
     63# PostgreSQL or MySQL: comment this section out if you use another backend # 
     64############################################################################ 
    6565storagebackend: pgstorage 
     66# storagebackend: mysqlstorage 
    6667 
    6768# Quota Storage Server hostname (and optional port) 
  • pykota/trunk/conf/pykotadmin.conf.sample

    r2622 r2638  
    6060# For SQLite3, you can comment out all the lines in this file. 
    6161 
    62 # PostgreSQL's Quota Storage administrator's name and password 
     62# PostgreSQL's or MySQL's Quota Storage administrator's name and password 
    6363# Please comment these lines out and see further below if you use LDAP. 
    6464storageadmin: pykotaadmin 
  • pykota/trunk/initscripts/mysql/pykota-mysql.sql

    r2622 r2638  
    3131-- Create the print quota database 
    3232-- 
     33CREATE DATABASE pykota; 
    3334 
    3435-- 
    3536-- Create the print quota database users 
    3637--  
    37 -- TODO : CREATE USER pykotaadmin; 
    38 -- TODO : CREATE USER pykotauser; 
     38GRANT USAGE ON *.* TO 'pykotauser'@'localhost' IDENTIFIED BY 'readonly'; 
     39GRANT USAGE ON *.* TO 'pykotaadmin'@'localhost' IDENTIFIED BY 'readwrite'; 
    3940 
    4041--  
    4142-- Now connect to the new database 
    4243--  
    43 \u pykota 
     44use pykota; 
    4445 
    4546-- 
    4647-- Create the users table 
    4748-- 
    48 CREATE TABLE users(id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, 
     49CREATE TABLE users (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, 
    4950                   username VARCHAR(255) UNIQUE NOT NULL, 
    5051                   email TEXT,  
    5152                   balance FLOAT DEFAULT 0.0, 
    5253                   lifetimepaid FLOAT DEFAULT 0.0, 
    53                    limitby VARCHAR(30) DEFAULT 'quota'); 
     54                   limitby VARCHAR(30) DEFAULT 'quota', 
     55                   description TEXT, 
     56                   overcharge FLOAT NOT NULL DEFAULT 1.0) TYPE=INNODB; 
    5457                    
    5558-- 
    5659-- Create the groups table 
    5760-- 
    58 CREATE TABLE groups(id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, 
     61CREATE TABLE groups (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, 
    5962                    groupname VARCHAR(255) UNIQUE NOT NULL, 
    60                     limitby VARCHAR(30) DEFAULT 'quota'); 
     63                    description TEXT, 
     64                    limitby VARCHAR(30) DEFAULT 'quota') TYPE=INNODB; 
    6165                     
    6266-- 
    6367-- Create the printers table 
    6468-- 
    65 CREATE TABLE printers(id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, 
     69CREATE TABLE printers (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, 
    6670                      printername VARCHAR(255) UNIQUE NOT NULL, 
    6771                      description TEXT, 
    6872                      priceperpage FLOAT DEFAULT 0.0, 
    69                       priceperjob FLOAT DEFAULT 0.0); 
     73                      priceperjob FLOAT DEFAULT 0.0, 
     74                      passthrough ENUM('t','f') DEFAULT 'f', 
     75                      maxjobsize INT4) TYPE=INNODB; 
    7076                     
    7177-- 
    7278-- Create the print quota table for users 
    7379-- 
    74 CREATE TABLE userpquota(id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, 
    75                         userid INT4 REFERENCES users(id), 
    76                         printerid INT4 REFERENCES printers(id), 
     80CREATE TABLE userpquota (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, 
     81                        userid INT4,  
     82                        printerid INT4,  
    7783                        lifepagecounter INT4 DEFAULT 0, 
    7884                        pagecounter INT4 DEFAULT 0, 
    7985                        softlimit INT4, 
    8086                        hardlimit INT4, 
    81                         datelimit TIMESTAMP); 
     87                        datelimit TIMESTAMP, 
     88                        maxjobsize INT4, 
     89                        warncount INT4 DEFAULT 0,  
     90                        FOREIGN KEY (userid) REFERENCES users(id), 
     91                        FOREIGN KEY (printerid) REFERENCES printers(id))  
     92                        TYPE=INNODB; 
     93CREATE INDEX userpquota_u_id_ix ON userpquota (userid); 
     94CREATE INDEX userpquota_p_id_ix ON userpquota (printerid); 
    8295CREATE UNIQUE INDEX userpquota_up_id_ix ON userpquota (userid, printerid); 
    8396                         
     
    99112                        options TEXT, 
    100113                        hostname VARCHAR(255), 
    101                         jobdate TIMESTAMP, 
    102                         CONSTRAINT checkUserPQuota FOREIGN KEY (userid, printerid)  
    103                                                            REFERENCES userpquota(userid, printerid)); 
     114                        md5sum TEXT, 
     115                        pages TEXT, 
     116                        billingcode TEXT, 
     117                        precomputedjobsize INT4, 
     118                        precomputedjobprice FLOAT, 
     119                        jobdate TIMESTAMP DEFAULT, 
     120                        CONSTRAINT checkUserPQuota FOREIGN KEY (userid, printerid) REFERENCES userpquota(userid, printerid)) TYPE=INNODB; 
     121CREATE INDEX jobhistory_u_id_ix ON jobhistory (userid); 
    104122CREATE INDEX jobhistory_p_id_ix ON jobhistory (printerid); 
    105123CREATE INDEX jobhistory_pd_id_ix ON jobhistory (printerid, jobdate); 
     
    110128-- 
    111129CREATE TABLE grouppquota(id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, 
    112                          groupid INT4 REFERENCES groups(id), 
    113                          printerid INT4 REFERENCES printers(id), 
     130                         groupid INT4,  
     131                         printerid INT4, 
    114132                         softlimit INT4, 
    115133                         hardlimit INT4, 
    116                          datelimit TIMESTAMP); 
     134                         maxjobsize INT4, 
     135                         datelimit TIMESTAMP, 
     136                         FOREIGN KEY (groupid) REFERENCES groups(id), 
     137                         FOREIGN KEY (printerid) REFERENCES printers(id)) 
     138                         TYPE=INNODB; 
     139CREATE INDEX grouppquota_g_id_ix ON grouppquota (groupid); 
     140CREATE INDEX grouppquota_p_id_ix ON grouppquota (printerid); 
    117141CREATE UNIQUE INDEX grouppquota_up_id_ix ON grouppquota (groupid, printerid); 
    118142                         
     
    120144-- Create the groups/members relationship 
    121145-- 
    122 CREATE TABLE groupsmembers(groupid INT4 REFERENCES groups(id), 
    123                            userid INT4 REFERENCES users(id), 
    124                            PRIMARY KEY (groupid, userid)); 
     146CREATE TABLE groupsmembers(groupid INT4, 
     147                           userid INT4, 
     148                           FOREIGN KEY (groupid) REFERENCES groups(id), 
     149                           FOREIGN KEY (userid) REFERENCES users(id), 
     150                           PRIMARY KEY (groupid, userid)) TYPE=INNODB; 
    125151                            
    126152--                          
    127153-- Create the printer groups relationship 
    128154-- 
    129 CREATE TABLE printergroupsmembers(groupid INT4 REFERENCES printers(id), 
    130                            printerid INT4 REFERENCES printers(id), 
    131                            PRIMARY KEY (groupid, printerid)); 
     155CREATE TABLE printergroupsmembers(groupid INT4, 
     156                           printerid INT4, 
     157                           FOREIGN KEY (groupid) REFERENCES groups(id), 
     158                           FOREIGN KEY (printerid) REFERENCES printers(id), 
     159                           PRIMARY KEY (groupid, printerid)) TYPE=INNODB; 
    132160-- 
    133161-- Create the table for payments 
    134162--  
    135163CREATE TABLE payments (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, 
    136                        userid INT4 REFERENCES users(id), 
     164                       userid INT4, 
    137165                       amount FLOAT, 
    138                        date TIMESTAMP DEFAULT now()); 
     166                       description TEXT, 
     167                       date TIMESTAMP DEFAULT now(), 
     168                       FOREIGN KEY (userid) REFERENCES users(id)) TYPE=INNODB; 
    139169CREATE INDEX payments_date_ix ON payments (date); 
    140170 
     171-- 
     172-- Create the table for coefficients wrt paper sizes and the like 
     173-- 
     174CREATE TABLE coefficients (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, 
     175                           printerid INT4 NOT NULL, 
     176                           label VARCHAR(255) NOT NULL, 
     177                           coefficient FLOAT DEFAULT 1.0, 
     178                           FOREIGN KEY (printerid) REFERENCES printers(id), 
     179                           CONSTRAINT coeffconstraint UNIQUE (printerid, label)); 
     180 
     181--  
     182-- Create the table for the billing codes 
     183-- 
     184CREATE TABLE billingcodes (id INT4 PRIMARY KEY NOT NULL, 
     185                           billingcode VARCHAR(255) UNIQUE NOT NULL, 
     186                           description TEXT, 
     187                           balance FLOAT DEFAULT 0.0, 
     188                           pagecounter INT4 DEFAULT 0) TYPE=INNODB; 
    141189--                         
    142190-- Set some ACLs                         
    143191-- 
    144 -- TODO : REVOKE ALL ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments FROM public;                         
    145 -- TODO : REVOKE 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; 
     192GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON `pykota`.* TO 'pykotaadmin'@'localhost'; 
     193GRANT SELECT ON `pykota`.* TO 'pykotauser'@'localhost'; 
    146194 
    147 -- TODO : GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments TO pykotaadmin; 
    148 -- TODO : GRANT 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; 
    149 -- TODO : GRANT SELECT ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments TO pykotauser; 
    150  
  • pykota/trunk/pykota/storages/sql.py

    r2622 r2638  
    226226        userpquota = StorageUserPQuota(self, user, printer) 
    227227        if printer.Exists and user.Exists : 
    228             result = self.doSearch("SELECT * FROM userpquota WHERE userid=%s AND printerid=%s" % (self.doQuote(user.ident), self.doQuote(printer.ident))) 
     228            result = self.doSearch("SELECT * FROM userpquota WHERE userid=%s AND printerid=%s;" % (self.doQuote(user.ident), self.doQuote(printer.ident))) 
    229229            if result : 
    230230                fields = result[0] 
  • pykota/trunk/README

    r2622 r2638  
    6262          An SQL script to create the database is included. 
    6363           
     64        - Supports MySQL as the database backend. 
     65          An SQL script to create the database is included. 
     66 
    6467        - The print jobs history can be stored in any database   
    6568          of your choice (or in plain text files) if needed.  
     
    383386      as the database backend (http://www.sqlite.org). You also need the  
    384387      PySQLite module v2.0.5 or higher (http://www.pysqlite.org) 
     388 or 
     389    - MySQL 4.0 or higher and the MySQL-python bindings.  
     390      IMPORTANT: If you are using MySQL 4.1, then MySQL-python must be  
     391      version 1.2 or greater. Version 1.0 does not work correctly with 4.1. 
    385392       
    386393     
  • pykota/trunk/setup.py

    r2622 r2638  
    6868data_files.append((os.path.join(docdir, "postgresql"), ["initscripts/postgresql/README.postgresql"])) 
    6969data_files.append((os.path.join(docdir, "ldap"), ["initscripts/ldap/README.ldap"])) 
     70data_files.append((os.path.join(docdir, "mysql"), ["initscripts/mysql/README.mysql"])) 
    7071 
    7172directory = os.sep.join(["share", "man", "man1"]) 
     
    105106data_files.append((ldapdirectory, ["initscripts/ldap/README.ldap", "initscripts/ldap/pykota.schema", "initscripts/ldap/pykota-sample.ldif"])) 
    106107 
     108mysqldirectory = os.sep.join([directory, "mysql"]) 
     109data_files.append((mysqldirectory, ["initscripts/mysql/README.mysql", "initscripts/mysql/pykota-mysql.sql"])) 
     110 
    107111os.umask(022) 
    108112setup(name = "pykota", version = __version__,