Changeset 1990

Show
Ignore:
Timestamp:
12/21/04 15:45:31 (20 years ago)
Author:
jalet
Message:

Prepared dumpykota to accept the new --filter command line option. Some
additionnal work needs to be done in the backends though.

Location:
pykota/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/dumpykota

    r1809 r1990  
    2424# 
    2525# $Log$ 
     26# Revision 1.16  2004/12/21 14:45:31  jalet 
     27# Prepared dumpykota to accept the new --filter command line option. Some 
     28# additionnal work needs to be done in the backends though. 
     29# 
    2630# Revision 1.15  2004/10/12 15:37:00  jalet 
    2731# Now outputs the name of the offending user if a mere mortal tries to use 
     
    134138                         - xml : dump data as XML 
    135139                          
     140  -F - | --filter exp  Uses the filter to extract only parts of the                           
     141                       datas. Allowed filters are of the form : 
     142                        
     143                         key=value 
     144                          
     145                       Allowed keys for now are :   
     146                        
     147                         username       User's name 
     148                         groupname      Users group's name 
     149                         printername    Printer's name 
     150                         pgroupname     Printers group's name 
     151                          
     152                       Contrary to other PyKota management tools, wildcard 
     153                       characters are not expanded, so you can't use them. 
     154                          
     155                       NB : not all keys are allowed for each data type, 
     156                       so the result may be empty if you use a key not 
     157                       available for a particular data type. 
     158                          
    136159  -o | --output fname  All datas will be dumped to the file instead of 
    137160                       to the standard output. The special '-' filename 
     
    149172   
    150173  Dumps all users datas to the users.xml file. 
     174   
     175  $ dumpykota --data history --filter printername=HP2100 
     176   
     177  Dumps the job history for printer HP2100 only. 
    151178   
    152179This program is free software; you can redistribute it and/or modify 
     
    172199        if not self.config.isAdmin : 
    173200            raise PyKotaToolError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command.")) 
     201             
     202        extractonly = {} 
     203        filterexp = options["filter"]     
     204        if filterexp : 
     205            try : 
     206                (filterkey, filtervalue) = [part.strip() for part in filterexp.split("=")] 
     207                if filterkey not in [ "username", 
     208                                      "groupname", 
     209                                      "printername", 
     210                                      "pgroupname", 
     211                                    ] : 
     212                    raise ValueError                 
     213            except ValueError :     
     214                raise PyKotaToolError, _("Invalid value [%s] for --filter command line option, see help.") % filterexp 
     215            else :     
     216                extractonly = { filterkey : filtervalue } 
    174217             
    175218        datatype = options["data"] 
     
    197240            raise PyKotaToolError, _("XML output is disabled because the jaxml module is not available.") 
    198241             
    199         entries = getattr(self.storage, "extract%s" % datatype.title())()     
     242        entries = getattr(self.storage, "extract%s" % datatype.title())(extractonly)     
    200243        if entries : 
    201244            mustclose = 0     
     
    263306                     "output" : "-", \ 
    264307                   } 
    265         short_options = "vhd:f:o:" 
    266         long_options = ["help", "version", "data=", "format=", "output="] 
     308        short_options = "vhd:f:o:F:" 
     309        long_options = ["help", "version", "data=", "format=", "output=", "filter="] 
    267310         
    268311        # Initializes the command line tool 
     
    278321        options["format"] = options["f"] or options["format"] or defaults["format"] 
    279322        options["output"] = options["o"] or options["output"] or defaults["output"] 
     323        options["filter"] = options["F"] or options["filter"] 
    280324         
    281325        if options["help"] : 
  • pykota/trunk/pykota/storages/ldapstorage.py

    r1969 r1990  
    2222# 
    2323# $Log$ 
     24# Revision 1.90  2004/12/21 14:45:31  jalet 
     25# Prepared dumpykota to accept the new --filter command line option. Some 
     26# additionnal work needs to be done in the backends though. 
     27# 
    2428# Revision 1.89  2004/12/02 22:27:11  jalet 
    2529# Integrated and extended Stefan Wold's patch to store print quota entries 
     
    13961400        self.doDelete(printer.ident)     
    13971401         
    1398     def extractPrinters(self) : 
     1402    def extractPrinters(self, extractonly={}) : 
    13991403        """Extracts all printer records.""" 
    14001404        entries = [p for p in [self.getPrinter(name) for name in self.getAllPrintersNames()] if p.Exists] 
     
    14051409            return result  
    14061410         
    1407     def extractUsers(self) : 
     1411    def extractUsers(self, extractonly={}) : 
    14081412        """Extracts all user records.""" 
    14091413        entries = [u for u in [self.getUser(name) for name in self.getAllUsersNames()] if u.Exists] 
     
    14141418            return result  
    14151419         
    1416     def extractGroups(self) : 
     1420    def extractGroups(self, extractonly={}) : 
    14171421        """Extracts all group records.""" 
    14181422        entries = [g for g in [self.getGroup(name) for name in self.getAllGroupsNames()] if g.Exists] 
     
    14231427            return result  
    14241428         
    1425     def extractPayments(self) : 
     1429    def extractPayments(self, extractonly={}) : 
    14261430        """Extracts all payment records.""" 
    14271431        entries = [u for u in [self.getUser(name) for name in self.getAllUsersNames()] if u.Exists] 
     
    14331437            return result         
    14341438         
    1435     def extractUpquotas(self) : 
     1439    def extractUpquotas(self, extractonly={}) : 
    14361440        """Extracts all userpquota records.""" 
    14371441        entries = [p for p in [self.getPrinter(name) for name in self.getAllPrintersNames()] if p.Exists] 
     
    14431447            return result 
    14441448         
    1445     def extractGpquotas(self) : 
     1449    def extractGpquotas(self, extractonly={}) : 
    14461450        """Extracts all grouppquota records.""" 
    14471451        entries = [p for p in [self.getPrinter(name) for name in self.getAllPrintersNames()] if p.Exists] 
     
    14531457            return result 
    14541458         
    1455     def extractUmembers(self) : 
     1459    def extractUmembers(self, extractonly={}) : 
    14561460        """Extracts all user groups members.""" 
    14571461        entries = [g for g in [self.getGroup(name) for name in self.getAllGroupsNames()] if g.Exists] 
     
    14631467            return result         
    14641468                 
    1465     def extractPmembers(self) : 
     1469    def extractPmembers(self, extractonly={}) : 
    14661470        """Extracts all printer groups members.""" 
    14671471        entries = [p for p in [self.getPrinter(name) for name in self.getAllPrintersNames()] if p.Exists] 
     
    14731477            return result         
    14741478         
    1475     def extractHistory(self) : 
     1479    def extractHistory(self, extractonly={}) : 
    14761480        """Extracts all jobhistory records.""" 
    14771481        entries = self.retrieveHistory(limit=None) 
  • pykota/trunk/pykota/storages/sql.py

    r1875 r1990  
    2222# 
    2323# $Log$ 
     24# Revision 1.60  2004/12/21 14:45:31  jalet 
     25# Prepared dumpykota to accept the new --filter command line option. Some 
     26# additionnal work needs to be done in the backends though. 
     27# 
    2428# Revision 1.59  2004/10/25 14:12:25  jalet 
    2529# For URGENT legal reasons (Italy), a new "privacy" directive was added to pykota.conf 
     
    132136            return entries 
    133137         
    134     def extractPrinters(self) : 
     138    def extractPrinters(self, extractonly={}) : 
    135139        """Extracts all printer records.""" 
    136140        result = self.doRawSearch("SELECT * FROM printers ORDER BY id ASC") 
    137141        return self.prepareRawResult(result) 
    138142         
    139     def extractUsers(self) : 
     143    def extractUsers(self, extractonly={}) : 
    140144        """Extracts all user records.""" 
    141145        result = self.doRawSearch("SELECT * FROM users ORDER BY id ASC") 
    142146        return self.prepareRawResult(result) 
    143147         
    144     def extractGroups(self) : 
     148    def extractGroups(self, extractonly={}) : 
    145149        """Extracts all group records.""" 
    146150        result = self.doRawSearch("SELECT groups.*,COALESCE(SUM(balance), 0) AS balance, COALESCE(SUM(lifetimepaid), 0) as lifetimepaid FROM groups LEFT OUTER JOIN users ON users.id IN (SELECT userid FROM groupsmembers WHERE groupid=groups.id) GROUP BY groups.id,groups.groupname,groups.limitby ORDER BY groups.id ASC") 
    147151        return self.prepareRawResult(result) 
    148152         
    149     def extractPayments(self) : 
     153    def extractPayments(self, extractonly={}) : 
    150154        """Extracts all payment records.""" 
    151155        result = self.doRawSearch("SELECT username,payments.* FROM users,payments WHERE users.id=payments.userid ORDER BY payments.id ASC") 
    152156        return self.prepareRawResult(result) 
    153157         
    154     def extractUpquotas(self) : 
     158    def extractUpquotas(self, extractonly={}) : 
    155159        """Extracts all userpquota records.""" 
    156160        result = self.doRawSearch("SELECT users.username,printers.printername,userpquota.* FROM users,printers,userpquota WHERE users.id=userpquota.userid AND printers.id=userpquota.printerid ORDER BY userpquota.id ASC") 
    157161        return self.prepareRawResult(result) 
    158162         
    159     def extractGpquotas(self) : 
     163    def extractGpquotas(self, extractonly={}) : 
    160164        """Extracts all grouppquota records.""" 
    161165        result = self.doRawSearch("SELECT groups.groupname,printers.printername,grouppquota.*,coalesce(sum(pagecounter), 0) AS pagecounter,coalesce(sum(lifepagecounter), 0) AS lifepagecounter FROM groups,printers,grouppquota,userpquota WHERE groups.id=grouppquota.groupid AND printers.id=grouppquota.printerid AND userpquota.printerid=grouppquota.printerid AND userpquota.userid IN (SELECT userid FROM groupsmembers WHERE groupsmembers.groupid=grouppquota.groupid) GROUP BY grouppquota.id,grouppquota.groupid,grouppquota.printerid,grouppquota.softlimit,grouppquota.hardlimit,grouppquota.datelimit,groups.groupname,printers.printername ORDER BY grouppquota.id") 
    162166        return self.prepareRawResult(result) 
    163167         
    164     def extractUmembers(self) : 
     168    def extractUmembers(self, extractonly={}) : 
    165169        """Extracts all user groups members.""" 
    166170        result = self.doRawSearch("SELECT groups.groupname, users.username, groupsmembers.* FROM groups,users,groupsmembers WHERE users.id=groupsmembers.userid AND groups.id=groupsmembers.groupid ORDER BY groupsmembers.groupid, groupsmembers.userid ASC") 
    167171        return self.prepareRawResult(result) 
    168172         
    169     def extractPmembers(self) : 
     173    def extractPmembers(self, extractonly={}) : 
    170174        """Extracts all printer groups members.""" 
    171175        result = self.doRawSearch("SELECT p1.printername as pgroupname, p2.printername as printername, printergroupsmembers.* FROM printers p1, printers p2, printergroupsmembers WHERE p1.id=printergroupsmembers.groupid AND p2.id=printergroupsmembers.printerid ORDER BY printergroupsmembers.groupid, printergroupsmembers.printerid ASC") 
    172176        return self.prepareRawResult(result) 
    173177         
    174     def extractHistory(self) : 
     178    def extractHistory(self, extractonly={}) : 
    175179        """Extracts all jobhistory records.""" 
    176180        result = self.doRawSearch("SELECT users.username,printers.printername,jobhistory.* FROM users,printers,jobhistory WHERE users.id=jobhistory.userid AND printers.id=jobhistory.printerid ORDER BY jobhistory.id ASC")