Changeset 1332 for pykota

Show
Ignore:
Timestamp:
02/04/04 14:24:41 (21 years ago)
Author:
jalet
Message:

pkprinters can now remove printers from printers groups.

Location:
pykota/trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pkprinters

    r1331 r1332  
    2424# 
    2525# $Log$ 
     26# Revision 1.3  2004/02/04 13:24:41  jalet 
     27# pkprinters can now remove printers from printers groups. 
     28# 
    2629# Revision 1.2  2004/02/04 12:52:37  jalet 
    2730# pkprinters' help 
     
    6265                       Floating point and negative values are allowed. 
    6366   
    64   -g | --groups pg1[,pg2...] Adds the printer(s) to the printer groups 
    65                        pg1, pg2, etc... which must already exist. 
     67  -g | --groups pg1[,pg2...] Adds or Remove the printer(s) to the printer  
     68                       groups pg1, pg2, etc... which must already exist. 
    6669                       A printer group is just like a normal printer, 
    6770                       only that it is usually unknown from the printing 
     
    7376                       is done on a printer and on all the printer groups 
    7477                       it belongs to. 
     78                       If the --remove option below is not used, the  
     79                       default action is to add printers to the specified 
     80                       printer groups. 
     81                        
     82  -r | --remove        In combination with the --groups option above,                        
     83                       remove printers from the specified printers groups. 
    7584   
    7685  printer1 through printerN can contain wildcards if the --add option  
     
    96105  This will put all printers which name matches "hp*" into printers groups  
    97106  Laser and HP, which MUST already exist. 
     107   
     108  $ pkprinters --groups LexMark --remove hp2200 
     109   
     110  This will remove the hp2200 printer from the LexMark printer group. 
    98111   
    99112This program is free software; you can redistribute it and/or modify 
     
    159172                if options["groups"] :     
    160173                    for pgroup in printersgroups : 
    161                         pgroup.addPrinterToGroup(printer)     
     174                        if options["remove"] : 
     175                            pgroup.delPrinterFromGroup(printer) 
     176                        else : 
     177                            pgroup.addPrinterToGroup(printer)     
    162178                      
    163179if __name__ == "__main__" :  
    164180    retcode = 0 
    165181    try : 
    166         short_options = "hvac:dg:" 
    167         long_options = ["help", "version", "add", "charge=", "delete", "groups="] 
     182        short_options = "hvac:dg:r" 
     183        long_options = ["help", "version", "add", "charge=", "delete", "groups=", "remove"] 
    168184         
    169185        # Initializes the command line tool 
     
    180196        options["delete"] = options["d"] or options["delete"]  
    181197        options["groups"] = options["g"] or options["groups"] 
     198        options["remove"] = options["r"] or options["remove"] 
    182199         
    183200        if options["help"] : 
     
    185202        elif options["version"] : 
    186203            manager.display_version_and_quit() 
    187         elif options["delete"] and (options["add"] or options["groups"] or options["charge"]) :     
     204        elif options["delete"] and (options["add"] or options["groups"] or options["charge"] or options["remove"]) :     
    188205            raise PyKotaToolError, _("incompatible options, see help.") 
     206        elif options["remove"] and not options["groups"] :     
     207            raise PyKotaToolError, _("You have to pass printer groups names on the command line") 
    189208        elif not args :     
    190209            raise PyKotaToolError, _("You have to pass printer names on the command line") 
  • pykota/trunk/man/pkprinters.1

    r1331 r1332  
    3232Floating point and negative values are allowed. 
    3333.TP 
    34 \fB\-g\fR | \fB\-\-groups\fR pg1[,pg2...] Adds the printer(s) to the printer groups 
    35 pg1, pg2, etc... which must already exist. 
     34\fB\-g\fR | \fB\-\-groups\fR pg1[,pg2...] Adds or Remove the printer(s) to the printer 
     35groups pg1, pg2, etc... which must already exist. 
    3636A printer group is just like a normal printer, 
    3737only that it is usually unknown from the printing 
     
    4343is done on a printer and on all the printer groups 
    4444it belongs to. 
     45If the \fB\-\-remove\fR option below is not used, the 
     46default action is to add printers to the specified 
     47printer groups. 
     48.TP 
     49\fB\-r\fR | \fB\-\-remove\fR 
     50In combination with the \fB\-\-groups\fR option above, 
     51remove printers from the specified printers groups. 
    4552.IP 
    4653printer1 through printerN can contain wildcards if the \fB\-\-add\fR option 
     
    6673This will put all printers which name matches "hp*" into printers groups 
    6774Laser and HP, which MUST already exist. 
     75.IP 
     76\f(CW$ pkprinters --groups LexMark --remove hp2200\fR 
     77.IP 
     78This will remove the hp2200 printer from the LexMark printer group. 
    6879.PP 
    6980This program is free software; you can redistribute it and/or modify 
  • pykota/trunk/pykota/storage.py

    r1330 r1332  
    2222# 
    2323# $Log$ 
     24# Revision 1.40  2004/02/04 13:24:41  jalet 
     25# pkprinters can now remove printers from printers groups. 
     26# 
    2427# Revision 1.39  2004/02/04 11:16:59  jalet 
    2528# pkprinters command line tool added. 
     
    262265        if (printer not in self.parent.getParentPrinters(self)) and (printer.ident != self.ident) : 
    263266            self.parent.writePrinterToGroup(self, printer) 
     267            # TODO : reset cached value for printer parents, or add new parent to cached value 
     268             
     269    def delPrinterFromGroup(self, printer) :     
     270        """Deletes a printer from a printer group.""" 
     271        if (printer in self.parent.getParentPrinters(self)) and (printer.ident != self.ident) : 
     272            self.parent.removePrinterFromGroup(self, printer) 
    264273            # TODO : reset cached value for printer parents, or add new parent to cached value 
    265274         
  • pykota/trunk/pykota/storages/ldapstorage.py

    r1330 r1332  
    2222# 
    2323# $Log$ 
     24# Revision 1.51  2004/02/04 13:24:41  jalet 
     25# pkprinters can now remove printers from printers groups. 
     26# 
    2427# Revision 1.50  2004/02/04 11:17:00  jalet 
    2528# pkprinters command line tool added. 
     
    871874            self.doModify(pgroup.ident, fields)          
    872875             
     876    def removePrinterFromGroup(self, pgroup, printer) : 
     877        """Removes a printer from a printer group.""" 
     878        try : 
     879            pgroup.uniqueMember.remove(printer.ident) 
     880        except ValueError :     
     881            pass 
     882        else :     
     883            fields = { 
     884                       "uniqueMember" : pgroup.uniqueMember, 
     885                     }   
     886            self.doModify(pgroup.ident, fields)          
     887             
    873888    def retrieveHistory(self, user=None, printer=None, datelimit=None, limit=100) :     
    874889        """Retrieves all print jobs for user on printer (or all) before date, limited to first 100 results.""" 
     
    9931008            self.doDelete(ident) 
    9941009        for parent in self.getParentPrinters(printer) :   
    995             parent.uniqueMember.remove(printer.ident) 
    996             fields = { 
    997                        "uniqueMember" : parent.uniqueMember, 
    998                      }   
    999             self.doModify(parent.ident, fields)          
     1010            try : 
     1011                parent.uniqueMember.remove(printer.ident) 
     1012            except ValueError :     
     1013                pass 
     1014            else :     
     1015                fields = { 
     1016                           "uniqueMember" : parent.uniqueMember, 
     1017                         }   
     1018                self.doModify(parent.ident, fields)          
    10001019        self.doDelete(printer.ident)     
  • pykota/trunk/pykota/storages/sql.py

    r1330 r1332  
    2222# 
    2323# $Log$ 
     24# Revision 1.36  2004/02/04 13:24:41  jalet 
     25# pkprinters can now remove printers from printers groups. 
     26# 
    2427# Revision 1.35  2004/02/04 11:17:00  jalet 
    2528# pkprinters command line tool added. 
     
    353356            self.doModify("INSERT INTO printergroupsmembers (groupid, printerid) VALUES (%s, %s)" % (self.doQuote(pgroup.ident), self.doQuote(printer.ident))) 
    354357         
     358    def removePrinterFromGroup(self, pgroup, printer) : 
     359        """Removes a printer from a printer group.""" 
     360        self.doModify("DELETE FROM printergroupsmembers WHERE groupid=%s AND printerid=%s" % (self.doQuote(pgroup.ident), self.doQuote(printer.ident))) 
     361         
    355362    def retrieveHistory(self, user=None, printer=None, datelimit=None, limit=100) :     
    356363        """Retrieves all print jobs for user on printer (or all) before date, limited to first 100 results."""