Changeset 1017

Show
Ignore:
Timestamp:
06/06/03 16:21:08 (21 years ago)
Author:
jalet
Message:

New LDAP schema.
Small bug fixes.

Location:
pykota/trunk
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/repykota

    r1005 r1017  
    2323# 
    2424# $Log$ 
     25# Revision 1.36  2003/06/06 14:21:08  jalet 
     26# New LDAP schema. 
     27# Small bug fixes. 
     28# 
    2529# Revision 1.35  2003/05/28 13:56:24  jalet 
    2630# Unneeded code. 
     
    256260                (balance, lifetimepaid) = balance 
    257261            else :     
    258                 (balance, lifetimepaid) = 0.0 
     262                (balance, lifetimepaid) = (0.0, 0.0) 
    259263            if datelimit is not None : 
    260264                now = DateTime.now() 
     
    274278            print "%-9.9s %s %7i %7s %7s %10s %-10.10s %8i %10s" % (name, reached, pagecounter, str(softlimit), str(hardlimit), strbalance, str(datelimit)[:10], lifepagecounter, strlifetimepaid) 
    275279            return (lifepagecounter, lifetimepaid) 
     280        else :     
     281            return (0, 0) 
    276282         
    277283                     
  • pykota/trunk/CREDITS

    r1015 r1017  
    4444    - John Flynn - University of Belize : LDAP support 
    4545    - Wayne Godoy - University of Belize : LDAP support 
     46    - Leif Johansson - LDAP support 
    4647 
    4748============================================================ 
  • pykota/trunk/initscripts/ldap/pykota-sample.ldif

    r1015 r1017  
    44# $Id$ 
    55# 
    6 #  
     6  
    77dn: ou=People,dc=librelogiciel,dc=com 
    88ou: People 
     
    1313objectClass: organizationalUnit 
    1414 
    15 dn: ou=Printers,dc=librelogiciel,dc=com 
     15dn: ou=PyKota,dc=librelogiciel,dc=com 
     16ou: PyKota 
     17objectClass: organizationalUnit 
     18 
     19dn: ou=Printers,ou=PyKota,dc=librelogiciel,dc=com 
    1620ou: Printers 
     21objectClass: organizationalUnit 
     22 
     23dn: ou=UQuotas,ou=PyKota,dc=librelogiciel,dc=com 
     24ou: UQuotas 
     25objectClass: organizationalUnit 
     26 
     27dn: ou=GQuotas,ou=PyKota,dc=librelogiciel,dc=com 
     28ou: GQuotas 
     29objectClass: organizationalUnit 
     30 
     31dn: ou=Jobs,ou=PyKota,dc=librelogiciel,dc=com 
     32ou: Jobs 
     33objectClass: organizationalUnit 
     34 
     35dn: ou=LastJobs,ou=PyKota,dc=librelogiciel,dc=com 
     36ou: LastJobs 
    1737objectClass: organizationalUnit 
    1838 
     
    2444objectClass: top 
    2545objectClass: shadowAccount 
    26 objectClass: pykotaUser 
     46objectClass: pykotaAccount 
     47objectClass: pykotaAccountBalance 
    2748userPassword: {crypt}PvuIT4Mz8.lCM 
    2849shadowLastChange: 12093 
     
    3455homeDirectory: /home/jerome 
    3556gecos: Jerome Alet,,, 
     57pykotaUserName: jerome 
    3658pykotaLimitBy: quota 
    37 pykotaBalance: 0 
    38 pykotaLifeTimePaid: 0 
     59pykotaBalance: 9.25 
     60pykotaLifeTimePaid: 10 
    3961 
    4062dn: cn=devel,ou=Groups,dc=librelogiciel,dc=com 
     
    4668gidNumber: 500 
    4769memberUid: jerome 
     70pykotaGroupName: devel 
    4871pykotaLimitBy: quota 
    4972 
    50 dn: pykotaPrinterName=apple,ou=Printers,dc=librelogiciel,dc=com 
     73dn: cn=apple,ou=Printers,ou=PyKota,dc=librelogiciel,dc=com 
     74objectClass: pykotaNamed 
    5175objectClass: pykotaPrinter 
     76cn: apple 
    5277pykotaPrinterName: apple 
    5378pykotaPricePerPage: 0.1 
    5479pykotaPricePerJob: 0.25 
    5580 
    56 dn: ou=userPQuotas,pykotaPrinterName=apple,ou=Printers,dc=librelogiciel,dc=com 
    57 ou: userPQuotas 
    58 objectClass: organizationalUnit 
    59  
    60 dn: ou=groupPQuotas,pykotaPrinterName=apple,ou=Printers,dc=librelogiciel,dc=com 
    61 ou: groupPQuotas 
    62 objectClass: organizationalUnit 
    63  
    64 dn: ou=Jobs,pykotaPrinterName=apple,ou=Printers,dc=librelogiciel,dc=com 
    65 ou: Jobs 
    66 objectClass: organizationalUnit 
    67  
    68 dn: uid=jerome,ou=userPQuotas,pykotaPrinterName=apple,ou=Printers,dc=librelogiciel,dc=com 
     81dn: cn=uniqueidentifier01,ou=UQuotas,ou=PyKota,dc=librelogiciel,dc=com 
     82objectClass: pykotaNamed 
    6983objectClass: pykotaUserPQuota 
    70 uid: jerome 
    71 pykotaPageCounter: 0 
    72 pykotaLifePageCounter: 0 
     84cn: uniqueidentifier01 
     85pykotaUserName: jerome 
     86pykotaPrinterName: apple 
     87pykotaPageCounter: 5 
     88pykotaLifePageCounter: 5 
    7389pykotaSoftLimit: 100 
    7490pykotaHardLimit: 110 
    7591pykotaDateLimit: None 
    7692 
    77 dn: cn=devel,ou=groupPQuotas,pykotaPrinterName=apple,ou=Printers,dc=librelogiciel,dc=com 
     93dn: cn=uniqueidentifier02,ou=GQuotas,ou=PyKota,dc=librelogiciel,dc=com 
     94objectClass: pykotaNamed 
    7895objectClass: pykotaGroupPQuota 
    79 cn: devel 
     96cn: uniqueidentifier02 
     97pykotaGroupName: devel 
     98pykotaPrinterName: apple 
    8099pykotaSoftLimit: 400 
    81100pykotaHardLimit: 450 
    82101pykotaDateLimit: None 
    83102 
    84 dn: pykotaJobHistoryId=1,ou=Jobs,pykotaPrinterName=apple,ou=Printers,dc=librelogiciel,dc=com 
    85 objectClass: pykotaPrinterJob 
    86 pykotaJobHistoryId: 1 
     103dn: cn=uniqueidentifier03,ou=Jobs,ou=PyKota,dc=librelogiciel,dc=com 
     104objectClass: pykotaNamed 
     105objectClass: pykotaJob 
     106cn: uniqueidentifier03 
     107pykotaUserName: jerome 
     108pykotaPrinterName: apple 
    87109pykotaJobId: 15 
    88 uid: jerome 
    89110pykotaPrinterPageCounter: 1533 
    90111pykotaJobSize: 5 
    91112pykotaAction: ALLOW 
    92 pykotaJobDate: 2003-06-04 16:12 
     113 
     114dn: cn=uniqueidentifier04,ou=LastJobs,ou=PyKota,dc=librelogiciel,dc=com 
     115objectClass: pykotaNamed 
     116objectClass: pykotaLastJob 
     117cn: uniqueidentifier04 
     118pykotaPrinterName: apple 
     119pykotaLastJobUUID: uniqueidentifier03 
  • pykota/trunk/initscripts/ldap/pykota.schema

    r1015 r1017  
    1616# 
    1717# 
     18# Contributors : Leif Johansson 
     19# 
    1820# THIS IS WORK UNDER HEAVY DEVELOPPMENT ! 
    1921# 
     
    2426# 
    2527 
    26 ## Pykota related LDAP attributes 
     28#         
     29# PyKota Attributes Types 
     30# 
    2731 
     32# pykotaLimitBy 
    2833attributetype ( 1.3.6.1.4.1.16868.1.1.1 NAME 'pykotaLimitBy' 
    2934        DESC 'How to limit the user/group : quota or balance' 
     
    3136        SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE ) 
    3237 
     38# pykotaBalance 
    3339attributetype ( 1.3.6.1.4.1.16868.1.1.2 NAME 'pykotaBalance' 
    3440        DESC 'Current account balance for the user, float' 
     
    3642        SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE ) 
    3743 
     44# pykotaLifeTimePaid 
    3845attributetype ( 1.3.6.1.4.1.16868.1.1.3 NAME 'pykotaLifeTimePaid' 
    3946        DESC 'Total money paid by the user to fill his account balance, float' 
     
    4148        SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE ) 
    4249 
     50# pykotaPricePerPage 
    4351attributetype ( 1.3.6.1.4.1.16868.1.1.4 NAME 'pykotaPricePerPage' 
    4452        DESC 'Price per page for a printer, float' 
     
    4654        SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE ) 
    4755 
     56# pykotaPricePerJob 
    4857attributetype ( 1.3.6.1.4.1.16868.1.1.5 NAME 'pykotaPricePerJob' 
    4958        DESC 'Price per job for a printer, float' 
     
    5160        SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE ) 
    5261 
    53 attributetype ( 1.3.6.1.4.1.16868.1.1.6 NAME 'pykotaPrinterName' 
    54         DESC 'Printer name as defined in the printing environment, e.g. lp' 
    55         EQUALITY caseIgnoreIA5Match 
    56         SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE ) 
    57  
    58 attributetype ( 1.3.6.1.4.1.16868.1.1.7 NAME 'pykotaSoftLimit' 
     62# pykotaSoftLimit 
     63attributetype ( 1.3.6.1.4.1.16868.1.1.6 NAME 'pykotaSoftLimit' 
    5964        DESC 'Soft limit in maximal number of pages' 
    6065        EQUALITY integerMatch 
    6166        SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE ) 
    6267         
    63 attributetype ( 1.3.6.1.4.1.16868.1.1.8 NAME 'pykotaHardLimit' 
     68# pykotaHardLimit         
     69attributetype ( 1.3.6.1.4.1.16868.1.1.7 NAME 'pykotaHardLimit' 
    6470        DESC 'Hard limit in maximal number of pages' 
    6571        EQUALITY integerMatch 
    6672        SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE ) 
    6773 
    68 attributetype ( 1.3.6.1.4.1.16868.1.1.9 NAME 'pykotaDateLimit' 
     74# pykotaDateLimit 
     75attributetype ( 1.3.6.1.4.1.16868.1.1.8 NAME 'pykotaDateLimit' 
    6976        DESC 'Date at which the soft limit becomes a hard one' 
    7077        EQUALITY caseIgnoreIA5Match 
    7178        SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE ) 
    7279 
    73 attributetype ( 1.3.6.1.4.1.16868.1.1.10 NAME 'pykotaPageCounter' 
     80# pykotaPageCounter 
     81attributetype ( 1.3.6.1.4.1.16868.1.1.9 NAME 'pykotaPageCounter' 
    7482        DESC 'Current page counter for the user on a particular printer' 
    7583        EQUALITY integerMatch 
    7684        SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE ) 
    7785 
    78 attributetype ( 1.3.6.1.4.1.16868.1.1.11 NAME 'pykotaLifePageCounter' 
     86# pykotaLifePageCounter 
     87attributetype ( 1.3.6.1.4.1.16868.1.1.10 NAME 'pykotaLifePageCounter' 
    7988        DESC 'Total page counter for the user on a particular printer' 
    8089        EQUALITY integerMatch 
    8190        SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE ) 
    8291 
    83 attributetype ( 1.3.6.1.4.1.16868.1.1.12 NAME 'pykotaJobHistoryId' 
    84         DESC 'Id of an entry in a printer history of jobs' 
    85         EQUALITY integerMatch 
    86         SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE ) 
     92# pykotaJobId 
     93attributetype ( 1.3.6.1.4.1.16868.1.1.11 NAME 'pykotaJobId' 
     94        DESC 'Id of a job in a printer history of jobs' 
     95        EQUALITY caseExactIA5Match 
     96        SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE ) 
    8797 
    88 attributetype ( 1.3.6.1.4.1.16868.1.1.13 NAME 'pykotaJobId' 
    89         DESC 'Id of a job in a printer history of jobs' 
    90         EQUALITY integerMatch 
    91         SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE ) 
    92  
    93 attributetype ( 1.3.6.1.4.1.16868.1.1.14 NAME 'pykotaPrinterPageCounter' 
     98# pykotaPrinterPageCounter 
     99attributetype ( 1.3.6.1.4.1.16868.1.1.12 NAME 'pykotaPrinterPageCounter' 
    94100        DESC 'Life time page counter of a printer when the job began' 
    95101        EQUALITY integerMatch 
    96102        SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE ) 
    97103 
    98 attributetype ( 1.3.6.1.4.1.16868.1.1.15 NAME 'pykotaJobSize' 
     104# pykotaJobSize 
     105attributetype ( 1.3.6.1.4.1.16868.1.1.13 NAME 'pykotaJobSize' 
    99106        DESC 'Current job size in number of pages in the history' 
    100107        EQUALITY integerMatch 
    101108        SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE ) 
    102109 
    103 attributetype ( 1.3.6.1.4.1.16868.1.1.16 NAME 'pykotaAction' 
     110# pykotaAction 
     111attributetype ( 1.3.6.1.4.1.16868.1.1.14 NAME 'pykotaAction' 
    104112        DESC 'Was the job allowed, or denied' 
    105113        EQUALITY caseIgnoreIA5Match 
    106114        SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE ) 
    107115         
    108 attributetype ( 1.3.6.1.4.1.16868.1.1.17 NAME 'pykotaJobDate' 
    109         DESC 'Date of when the job began' 
     116# pykotaPrinterName         
     117attributetype ( 1.3.6.1.4.1.16868.1.1.15 NAME 'pykotaPrinterName' 
     118        DESC 'PyKota printer name as received from the printing subsystem' 
    110119        EQUALITY caseIgnoreIA5Match 
    111120        SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE ) 
     121         
     122# pykotaUserName         
     123attributetype ( 1.3.6.1.4.1.16868.1.1.16 NAME 'pykotaUserName' 
     124        DESC 'PyKota user name' 
     125        EQUALITY caseExactIA5Match 
     126        SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE ) 
     127         
     128# pykotaGroupName         
     129attributetype ( 1.3.6.1.4.1.16868.1.1.17 NAME 'pykotaGroupName' 
     130        DESC 'PyKota group name' 
     131        EQUALITY caseExactIA5Match 
     132        SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE ) 
     133         
     134# pykotaLastJobUUID         
     135attributetype ( 1.3.6.1.4.1.16868.1.1.18 NAME 'pykotaLastJobUUID' 
     136        DESC 'Last job uuid in the history' 
     137        EQUALITY caseExactIA5Match 
     138        SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE ) 
     139         
     140#         
     141# PyKota Object Classes 
     142# 
    112143 
    113  
    114 ## New Pykota User object type 
    115 objectclass ( 1.3.6.1.4.1.16868.1.2.1 NAME 'pykotaUser' SUP top AUXILIARY 
     144# pykotaUser 
     145objectclass ( 1.3.6.1.4.1.16868.1.2.1 NAME 'pykotaAccount' SUP top AUXILIARY 
    116146        DESC 'PyKota Auxiliary User Account' 
    117         MUST ( uid ) 
    118         MAY  ( pykotaLimitBy $ pykotaBalance $ pykotaLifeTimePaid ) ) 
     147        MUST ( uid $ pykotaUserName ) 
     148        MAY  ( pykotaLimitBy ) ) 
    119149         
    120 ## New Pykota Group object type 
     150# pykotaGroup         
    121151objectclass ( 1.3.6.1.4.1.16868.1.2.2 NAME 'pykotaGroup' SUP top AUXILIARY 
    122152        DESC 'PyKota Auxiliary Group' 
    123         MUST ( cn ) 
    124         MAY  ( pykotaLimitBy ) ) 
     153        MUST ( cn $ pykotaGroupName ) 
     154        MAY  ( pykotaLimitBy $ memberUid ) ) 
    125155         
    126 ## New Pykota Printer object type 
    127 objectclass ( 1.3.6.1.4.1.16868.1.2.3 NAME 'pykotaPrinter' SUP top STRUCTURAL 
     156# pykotaPrinter         
     157objectclass ( 1.3.6.1.4.1.16868.1.2.3 NAME 'pykotaPrinter' SUP top AUXILIARY 
    128158        DESC 'PyKota Printer' 
    129         MUST ( pykotaPrinterName ) 
     159        MUST ( cn $ pykotaPrinterName ) 
    130160        MAY  ( pykotaPricePerPage $ pykotaPricePerJob ) ) 
    131161         
    132 ## New PyKota User Print Quota on a Printer         
    133 objectclass ( 1.3.6.1.4.1.16868.1.2.4 NAME 'pykotaUserPQuota' SUP top STRUCTURAL 
     162# pykotaUserPQuota         
     163objectclass ( 1.3.6.1.4.1.16868.1.2.4 NAME 'pykotaUserPQuota' SUP top AUXILIARY 
    134164        DESC 'PyKota User Quota on a Printer' 
    135         MUST ( uid ) 
     165        MUST ( cn $ pykotaUserName $ pykotaPrinterName ) 
    136166        MAY  ( pykotaPageCounter $ pykotaLifePageCounter $ pykotaSoftLimit $ pykotaHardLimit $ pykotaDateLimit ) ) 
    137167         
    138 ## New PyKota Group Print Quota on a Printer         
    139 objectclass ( 1.3.6.1.4.1.16868.1.2.5 NAME 'pykotaGroupPQuota' SUP top STRUCTURAL 
     168# pykotaGroupPQuota         
     169objectclass ( 1.3.6.1.4.1.16868.1.2.5 NAME 'pykotaGroupPQuota' SUP top AUXILIARY 
    140170        DESC 'PyKota Group Quota on a Printer' 
    141         MUST ( cn ) 
     171        MUST ( cn $ pykotaGroupName $ pykotaPrinterName ) 
    142172        MAY  ( pykotaSoftLimit $ pykotaHardLimit $ pykotaDateLimit ) ) 
    143173         
    144 ## New PyKota Job entry in a Printer's history         
    145 objectclass ( 1.3.6.1.4.1.16868.1.2.6 NAME 'pykotaPrinterJob' SUP top STRUCTURAL 
     174# pykotaJob         
     175objectclass ( 1.3.6.1.4.1.16868.1.2.6 NAME 'pykotaJob' SUP top AUXILIARY 
    146176        DESC 'An entry in the job history for a printer' 
    147         MUST ( pykotaJobHistoryId $ uid $ pykotaJobId ) 
    148         MAY  ( pykotaPrinterPageCounter $ pykotaJobSize $ pykotaAction $ pykotaJobDate ) ) 
     177        MUST ( cn $ pykotaUserName $ pykotaPrinterName $ pykotaJobId ) 
     178        MAY  ( pykotaPrinterPageCounter $ pykotaJobSize $ pykotaAction ) ) 
    149179         
     180# pykotaAccountBalance 
     181objectclass ( 1.3.6.1.4.1.16868.1.2.7 NAME 'pykotaAccountBalance' SUP top AUXILIARY 
     182        DESC 'PyKota User account balance' 
     183        MUST ( pykotaUserName ) 
     184        MAY  ( pykotaBalance $ pykotaLifeTimePaid ) ) 
     185         
     186# pykotaLastJob         
     187objectclass ( 1.3.6.1.4.1.16868.1.2.8 NAME 'pykotaLastJob' SUP top AUXILIARY 
     188        DESC 'Last job information for a printer' 
     189        MUST ( pykotaPrinterName $ pykotaLastJobUUID ) ) 
     190         
     191# pykotaNamed - Use it if you have to  
     192objectclass ( 1.3.6.1.4.1.16868.1.2.9 NAME 'pykotaNamed' SUP top STRUCTURAL 
     193        DESC 'PyKota Named Object' 
     194        MUST ( cn ) ) 
     195         
     196         
  • pykota/trunk/NEWS

    r1016 r1017  
    2222PyKota NEWS : 
    2323 
     24    - 1.08alpha6 :  
     25     
     26        - Minor bug corrections 
     27        - More work on LDAP : new schema 
     28         
    2429    - 1.08alpha5 : 
    2530     
    26         More good work on LDAP storage. 
    27         repykota now works reasonably well with the sample LDAP directory. 
     31        - More good work on LDAP storage. 
     32          repykota now works reasonably well with the sample LDAP directory. 
    2833         
    2934    - 1.08alpha4 : 
  • pykota/trunk/pykota/storages/ldapstorage.py

    r1016 r1017  
    2121# 
    2222# $Log$ 
     23# Revision 1.2  2003/06/06 14:21:08  jalet 
     24# New LDAP schema. 
     25# Small bug fixes. 
     26# 
    2327# Revision 1.1  2003/06/05 11:19:13  jalet 
    2428# More good work on LDAP storage. 
     
    6468            self.closed = 1 
    6569         
    66     def doSearch(self, key, fields, base="") : 
     70    def doSearch(self, key, fields, base="", scope=ldap.SCOPE_SUBTREE) : 
    6771        """Does an LDAP search query.""" 
    6872        try : 
    6973            # prepends something more restrictive at the beginning of the base dn 
    70             result = self.database.search_s(base or self.basedn, ldap.SCOPE_SUBTREE, key, fields) 
     74            result = self.database.search_s(base or self.basedn, scope, key, fields) 
    7175        except ldap.NO_SUCH_OBJECT :     
    7276            return 
     
    7983        if result : 
    8084            return [(printerid, printer["pykotaPrinterName"][0]) for (printerid, printer) in result if fnmatch.fnmatchcase(printer["pykotaPrinterName"][0], printerpattern)] 
    81         else :     
    82             return 
    8385             
    8486    def getPrinterId(self, printername) :         
     
    8789        if result : 
    8890            return result[0][0] 
    89         else :     
    90             return 
    9191             
    9292    def getPrinterPrices(self, printerid) :         
     
    9595        if result : 
    9696            return (float(result[0][1]["pykotaPricePerPage"][0]), float(result[0][1]["pykotaPricePerJob"][0])) 
    97         else : 
    98             return  
    9997             
    10098    def setPrinterPrices(self, printerid, perpage, perjob) : 
     
    104102    def getUserId(self, username) : 
    105103        """Returns a userid given a username.""" 
    106         result = self.doSearch("(&(objectClass=pykotaUser)(uid=%s))" % username, ["uid"]) 
     104        result = self.doSearch("(&(objectClass=pykotaAccount)(pykotaUserName=%s))" % username, ["uid"]) 
    107105        if result : 
    108106            return result[0][0] 
    109         else :     
    110             return 
    111107             
    112108    def getGroupId(self, groupname) : 
    113109        """Returns a groupid given a grupname.""" 
    114         result = self.doSearch("(&(objectClass=pykotaGroup)(cn=%s))" % groupname, ["cn"]) 
     110        result = self.doSearch("(&(objectClass=pykotaGroup)(pykotaGroupName=%s))" % groupname, ["cn"]) 
    115111        if result is not None : 
    116112            (groupid, dummy) = result[0] 
     
    123119    def getPrinterUsers(self, printerid) :         
    124120        """Returns the list of userids and usernames which uses a given printer.""" 
    125         result = self.doSearch("(&(objectClass=pykotaUserPQuota)(uid=*))", ["uid"], base=printerid)  
    126         if result : 
    127             return [(pquotauserid, fields["uid"][0]) for (pquotauserid, fields) in result] 
    128         else : 
    129             return 
     121        # first get the printer's name from the id 
     122        result = self.doSearch("objectClass=pykotaPrinter", ["pykotaPrinterName"], base=printerid, scope=ldap.SCOPE_BASE) 
     123        if result : 
     124            printername = result[0][1]["pykotaPrinterName"][0] 
     125            result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s))" % printername, ["pykotaUserName"])  
     126            if result : 
     127                return [(pquotauserid, fields["pykotaUserName"][0]) for (pquotauserid, fields) in result] 
    130128         
    131129    def getPrinterGroups(self, printerid) :         
    132130        """Returns the list of groups which uses a given printer.""" 
    133         result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(cn=*))", ["cn"], base=printerid)  
    134         if result : 
    135             return [(pquotagroupid, fields["cn"][0]) for (pquotagroupid, fields) in result] 
    136         else : 
    137             return 
     131        # first get the printer's name from the id 
     132        result = self.doSearch("objectClass=pykotaPrinter", ["pykotaPrinterName"], base=printerid, scope=ldap.SCOPE_BASE) 
     133        if result : 
     134            printername = result[0][1]["pykotaPrinterName"][0] 
     135            result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaPrinterName=%s))" % printername, ["pykotaGroupName"])  
     136            if result : 
     137                return [(pquotagroupid, fields["pykotaGroupName"][0]) for (pquotagroupid, fields) in result] 
    138138         
    139139    def getGroupMembersNames(self, groupname) :         
    140140        """Returns the list of user's names which are member of this group.""" 
    141         result = self.doSearch("(&(objectClass=pykotaGroup)(cn=%s))" % groupname, ["memberUid"]) 
     141        result = self.doSearch("(&(objectClass=pykotaGroup)(pykotaGroupName=%s))" % groupname, ["memberUid"]) 
    142142        if result : 
    143143            return result[0][1]["memberUid"] 
    144         else : 
    145             return 
    146144         
    147145    def getUserGroupsNames(self, userid) :         
     
    173171        pass 
    174172         
    175     def getUserBalance(self, userid) :     
    176         """Returns the current account balance for a given user.""" 
    177         shortuid = userid.split(",")[0] 
    178         result = self.doSearch("(&(objectClass=pykotaUser)(%s))" % shortuid, ["pykotaBalance", "pykotaLifeTimePaid"]) 
    179         if result : 
    180             fields = result[0][1] 
    181             return (float(fields["pykotaBalance"][0]), float(fields["pykotaLifeTimePaid"][0])) 
    182         else :     
    183             return 
    184          
    185     def getGroupBalance(self, groupid) :     
     173    def getUserBalance(self, userquotaid) :     
     174        """Returns the current account balance for a given user quota identifier.""" 
     175        # first get the user's name from the user quota id 
     176        result = self.doSearch("objectClass=pykotaUserPQuota", ["pykotaUserName"], base=userquotaid, scope=ldap.SCOPE_BASE) 
     177        if result : 
     178            username = result[0][1]["pykotaUserName"][0] 
     179            result = self.doSearch("(&(objectClass=pykotaAccountBalance)(pykotaUserName=%s))" % username, ["pykotaBalance", "pykotaLifeTimePaid"]) 
     180            if result : 
     181                fields = result[0][1] 
     182                return (float(fields["pykotaBalance"][0]), float(fields["pykotaLifeTimePaid"][0])) 
     183         
     184    def getUserBalanceFromUserId(self, userid) :     
     185        """Returns the current account balance for a given user id.""" 
     186        # first get the user's name from the user id 
     187        result = self.doSearch("objectClass=pykotaAccount", ["pykotaUserName"], base=userid, scope=ldap.SCOPE_BASE) 
     188        if result : 
     189            username = result[0][1]["pykotaUserName"][0] 
     190            result = self.doSearch("(&(objectClass=pykotaAccountBalance)(pykotaUserName=%s))" % username, ["pykotaBalance", "pykotaLifeTimePaid"]) 
     191            if result : 
     192                fields = result[0][1] 
     193                return (float(fields["pykotaBalance"][0]), float(fields["pykotaLifeTimePaid"][0])) 
     194         
     195    def getGroupBalance(self, groupquotaid) :     
    186196        """Returns the current account balance for a given group, as the sum of each of its users' account balance.""" 
    187         groupname = groupid.split(",")[0].split("=")[1] 
    188         members = self.getGroupMembersNames(groupname) 
    189         balance = lifetimepaid = 0.0 
    190         for member in members : 
    191             userid = self.getUserId(member) 
    192             if userid : 
    193                 userbal = self.getUserBalance(userid) 
    194                 if userbal : 
    195                     (bal, paid) = userbal 
    196                     balance += bal 
    197                     lifetimepaid += paid 
    198         return (balance, lifetimepaid)             
     197        # first get the group's name from the group quota id 
     198        result = self.doSearch("objectClass=pykotaGroupPQuota", ["pykotaGroupName"], base=groupquotaid, scope=ldap.SCOPE_BASE) 
     199        if result : 
     200            groupname = result[0][1]["pykotaGroupName"][0] 
     201            members = self.getGroupMembersNames(groupname) 
     202            balance = lifetimepaid = 0.0 
     203            for member in members : 
     204                userid = self.getUserId(member) 
     205                if userid : 
     206                    userbal = self.getUserBalanceFromUserId(userid) 
     207                    if userbal : 
     208                        (bal, paid) = userbal 
     209                        balance += bal 
     210                        lifetimepaid += paid 
     211            return (balance, lifetimepaid)             
    199212         
    200213    def getUserLimitBy(self, userid) :     
    201214        """Returns the way in which user printing is limited.""" 
    202         shortuid = userid.split(",")[0] 
    203         result = self.doSearch("(&(objectClass=pykotaUser)(%s))" % shortuid, ["pykotaLimitBy"]) 
     215        result = self.doSearch("objectClass=pykotaAccount", ["pykotaLimitBy"], base=userid, scope=ldap.SCOPE_BASE) 
    204216        if result : 
    205217            return result[0][1]["pykotaLimitBy"][0] 
    206         else :     
    207             return 
    208          
    209     def getGroupLimitBy(self, groupid) :     
     218         
     219    def getGroupLimitBy(self, groupquotaid) :     
    210220        """Returns the way in which group printing is limited.""" 
    211         shortgid = groupid.split(",")[0] 
    212         result = self.doSearch("(&(objectClass=pykotaGroup)(%s))" % shortgid, ["pykotaLimitBy"]) 
    213         if result : 
    214             return result[0][1]["pykotaLimitBy"][0] 
    215         else :     
    216             return 
     221        # first get the group's name from the group quota id 
     222        result = self.doSearch("objectClass=pykotaGroupPQuota", ["pykotaGroupName"], base=groupquotaid, scope=ldap.SCOPE_BASE) 
     223        if result : 
     224            groupname = result[0][1]["pykotaGroupName"][0] 
     225            result = self.doSearch("(&(objectClass=pykotaGroup)(pykotaGroupName=%s))" % groupname, ["pykotaLimitBy"]) 
     226            if result : 
     227                return result[0][1]["pykotaLimitBy"][0] 
    217228         
    218229    def setUserBalance(self, userid, balance) :     
     
    248259        pass 
    249260         
    250     def getUserPQuota(self, userid, printerid) : 
    251         """Returns the Print Quota information for a given (userid, printerid).""" 
    252         result = self.doSearch("(&(objectClass=pykotaUserPQuota)(uid=*))", ["uid", "pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit"], base=userid) 
     261    def getUserPQuota(self, userquotaid, printerid) : 
     262        """Returns the Print Quota information for a given (userquotaid, printerid).""" 
     263        # first get the user's name from the id 
     264        result = self.doSearch("objectClass=pykotaUserPQuota", ["pykotaUserName", "pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit"], base=userquotaid, scope=ldap.SCOPE_BASE) 
    253265        if result : 
    254266            fields = result[0][1] 
     
    262274                     "datelimit" : datelimit 
    263275                   } 
    264         else : 
    265             return 
    266          
    267     def getGroupPQuota(self, groupid, printerid) : 
    268         """Returns the Print Quota information for a given (groupid, printerid).""" 
    269         result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(cn=*))", ["pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit"], base=groupid) 
     276         
     277    def getGroupPQuota(self, grouppquotaid, printerid) : 
     278        """Returns the Print Quota information for a given (grouppquotaid, printerid).""" 
     279        result = self.doSearch("objectClass=pykotaGroupPQuota", ["pykotaGroupName", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit"], base=grouppquotaid, scope=ldap.SCOPE_BASE) 
    270280        if result : 
    271281            fields = result[0][1] 
     282            groupname = fields["pykotaGroupName"][0] 
    272283            datelimit = fields["pykotaDateLimit"][0].strip() 
    273284            if (not datelimit) or (datelimit.upper() == "NONE") :  
     
    278289                      "datelimit" : datelimit 
    279290                    } 
    280             groupname = groupid.split(",")[0].split("=")[1] 
    281291            members = self.getGroupMembersNames(groupname) 
    282292            pagecounter = lifepagecounter = 0 
     
    291301            quota.update({"pagecounter": pagecounter, "lifepagecounter": lifepagecounter})                 
    292302            return quota 
    293         else : 
    294             return 
    295303         
    296304    def setUserDateLimit(self, userid, printerid, datelimit) : 
     
    316324        if result : 
    317325            pass # TODO 
    318         else : 
    319             return  
    320326         
    321327    def addUserToGroup(self, userid, groupid) :     
  • pykota/trunk/pykota/version.py

    r1016 r1017  
    2121# 
    2222 
    23 __version__ = "1.08alpha5_unofficial" 
     23__version__ = "1.08alpha6_unofficial" 
    2424 
    2525__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""