Changeset 1993 for pykota/trunk

Show
Ignore:
Timestamp:
12/21/04 17:46:25 (20 years ago)
Author:
jalet
Message:

dumpykota's filtering capabilities are now supported within the LDAP
backend as well as within the PostgreSQL backend. Untested though since
my only PyKota+LDAP setup is on my laptop at work :-)

Location:
pykota/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/NEWS

    r1991 r1993  
    2222PyKota NEWS : 
    2323 
     24    - 1.21alpha15 : 
     25       
     26        - dumpykota filtering capabilities are now supported within 
     27          the LDAP backend too. 
     28           
    2429    - 1.21alpha14 : 
    2530     
  • pykota/trunk/pykota/storages/ldapstorage.py

    r1990 r1993  
    2222# 
    2323# $Log$ 
     24# Revision 1.91  2004/12/21 16:46:25  jalet 
     25# dumpykota's filtering capabilities are now supported within the LDAP 
     26# backend as well as within the PostgreSQL backend. Untested though since 
     27# my only PyKota+LDAP setup is on my laptop at work :-) 
     28# 
    2429# Revision 1.90  2004/12/21 14:45:31  jalet 
    2530# Prepared dumpykota to accept the new --filter command line option. Some 
     
    574579        raise PyKotaStorageError, message 
    575580             
    576     def getAllPrintersNames(self) :     
    577         """Extracts all printer names.""" 
     581    def getAllPrintersNames(self, printername=None) :     
     582        """Extracts all printer names or only the printers' names matching the optional parameter.""" 
    578583        printernames = [] 
    579         result = self.doSearch("objectClass=pykotaPrinter", ["pykotaPrinterName"], base=self.info["printerbase"]) 
     584        ldapfilter = "objectClass=pykotaPrinter" 
     585        if printername : 
     586            ldapfilter = "&(%s)(pykotaPrinterName=%s)" % (ldapfilter, printername) 
     587        result = self.doSearch(ldapfilter, ["pykotaPrinterName"], base=self.info["printerbase"]) 
    580588        if result : 
    581589            printernames = [record[1]["pykotaPrinterName"][0] for record in result] 
    582590        return printernames 
    583591         
    584     def getAllUsersNames(self) :     
    585         """Extracts all user names.""" 
     592    def getAllUsersNames(self, username=None) :     
     593        """Extracts all user names or only the users' names matching the optional parameter.""" 
    586594        usernames = [] 
    587         result = self.doSearch("objectClass=pykotaAccount", ["pykotaUserName"], base=self.info["userbase"]) 
     595        ldapfilter = "objectClass=pykotaAccount" 
     596        if username : 
     597            ldapfilter = "&(%s)(pykotaUserName=%s)" % (ldapfilter, username) 
     598        result = self.doSearch(ldapfilter, ["pykotaUserName"], base=self.info["userbase"]) 
    588599        if result : 
    589600            usernames = [record[1]["pykotaUserName"][0] for record in result] 
    590601        return usernames 
    591602         
    592     def getAllGroupsNames(self) :     
    593         """Extracts all group names.""" 
     603    def getAllGroupsNames(self, groupname=None) :     
     604        """Extracts all group names or only the groups' names matching the optional parameter.""" 
    594605        groupnames = [] 
    595         result = self.doSearch("objectClass=pykotaGroup", ["pykotaGroupName"], base=self.info["groupbase"]) 
     606        ldapfilter = "objectClass=pykotaGroup" 
     607        if groupname : 
     608            ldapfilter = "&(%s)(pykotaGroupName=%s)" % (ldapfilter, groupname) 
     609        result = self.doSearch(ldapfilter, ["pykotaGroupName"], base=self.info["groupbase"]) 
    596610        if result : 
    597611            groupnames = [record[1]["pykotaGroupName"][0] for record in result] 
     
    14021416    def extractPrinters(self, extractonly={}) : 
    14031417        """Extracts all printer records.""" 
    1404         entries = [p for p in [self.getPrinter(name) for name in self.getAllPrintersNames()] if p.Exists] 
     1418        pname = extractonly.get("printername") 
     1419        entries = [p for p in [self.getPrinter(name) for name in self.getAllPrintersNames(pname)] if p.Exists] 
    14051420        if entries : 
    14061421            result = [ ("dn", "pykotaPrinterName", "pykotaPricePerPage", "pykotaPricePerPage", "description") ] 
     
    14111426    def extractUsers(self, extractonly={}) : 
    14121427        """Extracts all user records.""" 
    1413         entries = [u for u in [self.getUser(name) for name in self.getAllUsersNames()] if u.Exists] 
     1428        uname = extractonly.get("username") 
     1429        entries = [u for u in [self.getUser(name) for name in self.getAllUsersNames(uname)] if u.Exists] 
    14141430        if entries : 
    14151431            result = [ ("dn", "pykotaUserName", self.info["usermail"], "pykotaBalance", "pykotaLifeTimePaid", "pykotaLimitBy") ] 
     
    14201436    def extractGroups(self, extractonly={}) : 
    14211437        """Extracts all group records.""" 
    1422         entries = [g for g in [self.getGroup(name) for name in self.getAllGroupsNames()] if g.Exists] 
     1438        gname = extractonly.get("groupname") 
     1439        entries = [g for g in [self.getGroup(name) for name in self.getAllGroupsNames(gname)] if g.Exists] 
    14231440        if entries : 
    14241441            result = [ ("dn", "pykotaGroupName", "pykotaBalance", "pykotaLifeTimePaid", "pykotaLimitBy") ] 
     
    14291446    def extractPayments(self, extractonly={}) : 
    14301447        """Extracts all payment records.""" 
    1431         entries = [u for u in [self.getUser(name) for name in self.getAllUsersNames()] if u.Exists] 
     1448        uname = extractonly.get("username") 
     1449        entries = [u for u in [self.getUser(name) for name in self.getAllUsersNames(uname)] if u.Exists] 
    14321450        if entries : 
    14331451            result = [ ("pykotaUserName", "date", "amount") ] 
     
    14391457    def extractUpquotas(self, extractonly={}) : 
    14401458        """Extracts all userpquota records.""" 
    1441         entries = [p for p in [self.getPrinter(name) for name in self.getAllPrintersNames()] if p.Exists] 
     1459        pname = extractonly.get("printername") 
     1460        entries = [p for p in [self.getPrinter(name) for name in self.getAllPrintersNames(pname)] if p.Exists] 
    14421461        if entries : 
    14431462            result = [ ("pykotaUserName", "pykotaPrinterName", "dn", "userdn", "printerdn", "pykotaLifePageCounter", "pykotaPageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit") ] 
     1463            uname = extraconly.get("username") 
    14441464            for entry in entries : 
    14451465                for (user, userpquota) in self.getPrinterUsersAndQuotas(entry) : 
    1446                     result.append((user.Name, entry.Name, userpquota.ident, user.ident, entry.ident, userpquota.LifePageCounter, userpquota.PageCounter, userpquota.SoftLimit, userpquota.HardLimit, userpquota.DateLimit)) 
     1466                    if (uname is None) or (user.Name == uname) : 
     1467                        result.append((user.Name, entry.Name, userpquota.ident, user.ident, entry.ident, userpquota.LifePageCounter, userpquota.PageCounter, userpquota.SoftLimit, userpquota.HardLimit, userpquota.DateLimit)) 
    14471468            return result 
    14481469         
    14491470    def extractGpquotas(self, extractonly={}) : 
    14501471        """Extracts all grouppquota records.""" 
    1451         entries = [p for p in [self.getPrinter(name) for name in self.getAllPrintersNames()] if p.Exists] 
     1472        pname = extractonly.get("printername") 
     1473        entries = [p for p in [self.getPrinter(name) for name in self.getAllPrintersNames(pname)] if p.Exists] 
    14521474        if entries : 
    14531475            result = [ ("pykotaGroupName", "pykotaPrinterName", "dn", "groupdn", "printerdn", "pykotaLifePageCounter", "pykotaPageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit") ] 
     1476            gname = extractonly.get("groupname") 
    14541477            for entry in entries : 
    14551478                for (group, grouppquota) in self.getPrinterGroupsAndQuotas(entry) : 
    1456                     result.append((group.Name, entry.Name, grouppquota.ident, group.ident, entry.ident, grouppquota.LifePageCounter, grouppquota.PageCounter, grouppquota.SoftLimit, grouppquota.HardLimit, grouppquota.DateLimit)) 
     1479                    if (gname is None) or (group.Name == gname) : 
     1480                        result.append((group.Name, entry.Name, grouppquota.ident, group.ident, entry.ident, grouppquota.LifePageCounter, grouppquota.PageCounter, grouppquota.SoftLimit, grouppquota.HardLimit, grouppquota.DateLimit)) 
    14571481            return result 
    14581482         
    14591483    def extractUmembers(self, extractonly={}) : 
    14601484        """Extracts all user groups members.""" 
    1461         entries = [g for g in [self.getGroup(name) for name in self.getAllGroupsNames()] if g.Exists] 
     1485        gname = extractonly.get("groupname") 
     1486        entries = [g for g in [self.getGroup(name) for name in self.getAllGroupsNames(gname)] if g.Exists] 
    14621487        if entries : 
    14631488            result = [ ("pykotaGroupName", "pykotaUserName", "groupdn", "userdn") ] 
     1489            uname = extractonly.get("username") 
    14641490            for entry in entries : 
    14651491                for member in entry.Members : 
    1466                     result.append((entry.Name, member.Name, entry.ident, member.ident)) 
     1492                    if (uname is None) or (member.Name == uname) : 
     1493                        result.append((entry.Name, member.Name, entry.ident, member.ident)) 
    14671494            return result         
    14681495                 
    14691496    def extractPmembers(self, extractonly={}) : 
    14701497        """Extracts all printer groups members.""" 
    1471         entries = [p for p in [self.getPrinter(name) for name in self.getAllPrintersNames()] if p.Exists] 
     1498        pname = extractonly.get("printername") 
     1499        entries = [p for p in [self.getPrinter(name) for name in self.getAllPrintersNames(pname)] if p.Exists] 
    14721500        if entries : 
    14731501            result = [ ("pykotaPGroupName", "pykotaPrinterName", "pgroupdn", "printerdn") ] 
     1502            pgname = extractonly.get("pgroupname") 
    14741503            for entry in entries : 
    14751504                for parent in self.getParentPrinters(entry) : 
    1476                     result.append((parent.Name, entry.Name, parent.ident, entry.ident)) 
     1505                    if (pgname is None) or (parent.Name == pgname) : 
     1506                        result.append((parent.Name, entry.Name, parent.ident, entry.ident)) 
    14771507            return result         
    14781508         
    14791509    def extractHistory(self, extractonly={}) : 
    14801510        """Extracts all jobhistory records.""" 
    1481         entries = self.retrieveHistory(limit=None) 
     1511        uname = extractonly.get("username") 
     1512        if uname : 
     1513            user = self.getUser(uname) 
     1514        else :     
     1515            user = None 
     1516        pname = extractonly.get("printername") 
     1517        if pname : 
     1518            printer = self.getPrinter(pname) 
     1519        else :     
     1520            printer = None 
     1521        entries = self.retrieveHistory(user, printer, limit=None) 
    14821522        if entries : 
    14831523            result = [ ("pykotaUserName", "pykotaPrinterName", "dn", "pykotaJobId", "pykotaPrinterPageCounter", "pykotaJobSize", "pykotaAction", "createTimeStamp", "pykotaFileName", "pykotaTitle", "pykotaCopies", "pykotaOptions", "pykotaJobPrice", "pykotaHostName", "pykotaJobSizeBytes") ]  
  • pykota/trunk/pykota/version.py

    r1991 r1993  
    2222# 
    2323 
    24 __version__ = "1.21alpha14_unofficial" 
     24__version__ = "1.21alpha15_unofficial" 
    2525 
    2626__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""