Changeset 2593

Show
Ignore:
Timestamp:
11/29/05 12:43:34 (19 years ago)
Author:
jerome
Message:

Added support for SQLite3 database backend.
NEEDS TESTERS !

Location:
pykota/trunk
Files:
1 added
8 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/conf/pykota.conf.sample

    r2583 r2593  
    4848[global] 
    4949# Storage backend for quotas 
    50 # only PGStorage (PostgreSQL) and LDAPStorage (OpenLDAP) are supported. 
     50# only PGStorage (PostgreSQL), LDAPStorage (OpenLDAP or else), 
     51# and SQLiteStorage (SQLite 3) are supported. 
     52# 
    5153# MySQL and BerkeleyDB are planned. 
    5254 
    53 # the 'postgresql' value is deprecated, use 'pgstorage' instead. 
     55#################################################################### 
     56# SQLite3 : comment this section out if you use another backend    # 
     57#################################################################### 
     58 
     59#storagebackend : sqlitestorage 
     60#storagename: /etc/pykota/pykota.db 
     61 
     62#################################################################### 
     63# PostgreSQL : comment this section out if you use another backend # 
     64#################################################################### 
    5465storagebackend: pgstorage 
    5566 
     
    7485# storageuserpw: Comment out if unused, or set to Quota Storage user password 
    7586 
    76 # Should the database caching mechanism be enabled or not ? 
    77 # If unset, caching is disabled. Possible values Y/N/YES/NO 
    78 # caching mechanism works with both PostgreSQL and OpenLDAP backends 
    79 # but may be really interesting only with OpenLDAP. 
    80 # 
    81 # ACTIVATING CACHE MAY CAUSE PRECISION PROBLEMS IN PRINT ACCOUNTING 
    82 # IF AN USER PRINTS ON SEVERAL PRINTERS AT THE SAME TIME. 
    83 # YOU MAY FIND IT INTERESTING ANYWAY, ESPECIALLY FOR LDAP. 
    84 # 
    85 # FYI, I ALWAYS SET IT TO YES ! 
    86 # 
    87 storagecaching: No 
    88  
    89 # Should full job history be disabled ? 
    90 # If unset or set to No, full job history is kept in the database. 
    91 # This will be useful in the future when the report generator 
    92 # will be written. 
    93 # Disabling the job history can be useful with heavily loaded 
    94 # LDAP servers, to not make the LDAP tree grow out of control. 
    95 # Disabling the job history with the PostgreSQL backend works too 
    96 # but it's probably less useful than with LDAP. 
    97 disablehistory: No 
    98  
     87#################################################################### 
     88# LDAP : comment this section out if you use another backend       # 
     89#################################################################### 
    9990# LDAP example, uncomment and adapt it to your own configuration : 
    10091#storagebackend: ldapstorage 
     
    183174# BETTER TO LET IT SET TO 'NO' 
    184175# ldapcache: no 
     176 
     177############################################################# 
     178# ALL directives below are common to ALL storage backends   # 
     179############################################################# 
     180 
     181# Should the database caching mechanism be enabled or not ? 
     182# If unset, caching is disabled. Possible values Y/N/YES/NO 
     183# caching mechanism works with both PostgreSQL and OpenLDAP backends 
     184# but may be really interesting only with OpenLDAP. 
     185# 
     186# ACTIVATING CACHE MAY CAUSE PRECISION PROBLEMS IN PRINT ACCOUNTING 
     187# IF AN USER PRINTS ON SEVERAL PRINTERS AT THE SAME TIME. 
     188# YOU MAY FIND IT INTERESTING ANYWAY, ESPECIALLY FOR LDAP. 
     189# 
     190# FYI, I ALWAYS SET IT TO YES ! 
     191# 
     192storagecaching: No 
     193 
     194# Should full job history be disabled ? 
     195# If unset or set to No, full job history is kept in the database. 
     196# This will be useful in the future when the report generator 
     197# will be written. 
     198# Disabling the job history can be useful with heavily loaded 
     199# LDAP servers, to not make the LDAP tree grow out of control. 
     200# Disabling the job history with the PostgreSQL backend works too 
     201# but it's probably less useful than with LDAP. 
     202disablehistory: No 
     203 
    185204 
    186205# Where to log ? 
  • pykota/trunk/conf/pykotadmin.conf.sample

    r2576 r2593  
    5858[global] 
    5959 
     60# For SQLite3, you can comment out all the lines in this file. 
     61 
    6062# PostgreSQL's Quota Storage administrator's name and password 
    6163# Please comment these lines out and see further below if you use LDAP. 
  • pykota/trunk/NEWS

    r2588 r2593  
    2222PyKota NEWS : 
    2323        
     24    - 1.24alpha4 : 
     25     
     26        - Added support for the SQLite3 backend. 
     27          See pykota/initscripts/sqlite/README.sqlite 
     28         
    2429    - 1.24alpha3 : 
    2530     
  • pykota/trunk/pykota/config.py

    r2583 r2593  
    9595        """Returns the storage backend information as a Python mapping."""         
    9696        backendinfo = {} 
    97         for option in [ "storagebackend", "storageserver", \ 
    98                         "storagename", "storageuser", \ 
    99                       ] : 
    100             backendinfo[option] = self.getGlobalOption(option) 
    101         backendinfo["storageuserpw"] = self.getGlobalOption("storageuserpw", ignore=1)  # password is optional 
     97        backend = self.getGlobalOption("storagebackend").lower() 
     98        backendinfo["storagebackend"] = backend 
     99        if backend == "sqlitestorage" : 
     100            issqlite = 1 
     101            backendinfo["storagename"] = self.getGlobalOption("storagename") 
     102            for option in ["storageserver", "storageuser", "storageuserpw"] : 
     103                backendinfo[option] = None           
     104        else : 
     105            issqlite = 0 
     106            for option in ["storageserver", "storagename", "storageuser"] : 
     107                backendinfo[option] = self.getGlobalOption(option) 
     108            backendinfo["storageuserpw"] = self.getGlobalOption("storageuserpw", ignore=1)  # password is optional 
     109             
    102110        backendinfo["storageadmin"] = None 
    103111        backendinfo["storageadminpw"] = None 
     
    109117                    backendinfo["storageadmin"] = adminconf.get("global", "storageadmin", raw=1) 
    110118                except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) :     
    111                     raise PyKotaConfigError, _("Option %s not found in section global of %s") % ("storageadmin", self.adminfilename) 
     119                    if not issqlite : 
     120                        raise PyKotaConfigError, _("Option %s not found in section global of %s") % ("storageadmin", self.adminfilename) 
    112121                try : 
    113122                    backendinfo["storageadminpw"] = adminconf.get("global", "storageadminpw", raw=1) 
  • pykota/trunk/pykota/storages/pgstorage.py

    r2418 r2593  
    118118            typ = "text" 
    119119        return pg._quote(field, typ) 
     120         
     121    def prepareRawResult(self, result) : 
     122        """Prepares a raw result by including the headers.""" 
     123        if result.ntuples() > 0 : 
     124            entries = [result.listfields()] 
     125            entries.extend(result.getresult()) 
     126            nbfields = len(entries[0]) 
     127            for i in range(1, len(entries)) : 
     128                fields = list(entries[i]) 
     129                for j in range(nbfields) : 
     130                    field = fields[j] 
     131                    if type(field) == StringType : 
     132                        fields[j] = self.databaseToUserCharset(field)  
     133                entries[i] = tuple(fields)     
     134            return entries 
     135         
  • pykota/trunk/pykota/storages/sqlitestorage.py

    r2591 r2593  
    123123        else :      
    124124            return "NULL" 
     125             
     126    def prepareRawResult(self, result) : 
     127        """Prepares a raw result by including the headers.""" 
     128        if result : 
     129            entries = [tuple([f[0] for f in self.cursor.description])] 
     130            for entry in result :     
     131                row = [] 
     132                for value in entry : 
     133                    try : 
     134                        value = value.encode("UTF-8") 
     135                    except : 
     136                        pass 
     137                    row.append(value) 
     138                entries.append(tuple(row))     
     139            return entries    
     140         
  • pykota/trunk/pykota/storages/sql.py

    r2464 r2593  
    3030 
    3131class SQLStorage : 
    32     def prepareRawResult(self, result) : 
    33         """Prepares a raw result by including the headers.""" 
    34         if result.ntuples() > 0 : 
    35             entries = [result.listfields()] 
    36             entries.extend(result.getresult()) 
    37             nbfields = len(entries[0]) 
    38             for i in range(1, len(entries)) : 
    39                 fields = list(entries[i]) 
    40                 for j in range(nbfields) : 
    41                     field = fields[j] 
    42                     if type(field) == StringType : 
    43                         fields[j] = self.databaseToUserCharset(field)  
    44                 entries[i] = tuple(fields)     
    45             return entries 
    46          
    4732    def createFilter(self, only) :     
    4833        """Returns the appropriate SQL filter.""" 
  • pykota/trunk/pykota/version.py

    r2588 r2593  
    2222# 
    2323 
    24 __version__ = "1.24alpha3_unofficial" 
     24__version__ = "1.24alpha4_unofficial" 
    2525 
    2626__doc__ = "PyKota : a complete Printing Quota Solution for CUPS."