Changeset 2674

Show
Ignore:
Timestamp:
02/11/06 23:28:39 (18 years ago)
Author:
jerome
Message:

Now pkprinters' skeleton resembles more to pkbcodes :
factorizing the code will be much easier.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pkprinters

    r2658 r2674  
    130130             
    131131        if options["delete"] :     
    132             self.display("%s...\n" % _("Processing")) 
     132            self.display("%s...\n" % _("Deletion")) 
    133133            todelete = self.storage.getMatchingPrinters(",".join(names)) 
    134134            nbtotal = len(todelete) 
     
    137137                percent = 100.0 * float(i) / float(nbtotal) 
    138138                self.display("\r%.02f%%" % percent) 
    139             self.display("\r100.00%%\r        ") 
    140             self.display("\r%s\n" % _("Done.")) 
    141139        else : 
    142             if options["list"] and not names : 
    143                 names = ["*"] 
     140            if options["add"] :     
     141                self.display("%s...\n" % _("Creation")) 
     142                printers = [] 
     143                nbtotal = len(names) 
     144                for i in range(nbtotal) : 
     145                    pname = names[i] 
     146                    printer = self.storage.getPrinter(pname) 
     147                    if printer.Exists : 
     148                        if options["skipexisting"] : 
     149                            self.printInfo(_("Printer %s already exists, skipping.") % printer.Name) 
     150                        else :     
     151                            self.printInfo(_("Printer %s already exists, will be modified.") % printer.Name) 
     152                            printers.append(printer) 
     153                    else : 
     154                        if self.isValidName(pname) : 
     155                            printer = self.storage.addPrinter(pname) 
     156                            if not printer.Exists : 
     157                                raise PyKotaToolError, _("Impossible to add printer %s") % pname 
     158                            else :     
     159                                printers.append(printer) 
     160                        else :     
     161                            raise PyKotaCommandLineError, _("Invalid printer name %s") % pname 
     162                    percent = 100.0 * float(i) / float(nbtotal) 
     163                    self.display("\r%.02f%%" % percent) 
     164                self.display("\r100.00%%\r        \r%s\n" % _("Done.")) 
     165            else :         
     166                if not names : 
     167                    names = ["*"] 
     168                printers = self.storage.getMatchingPrinters(",".join(names)) 
     169                if not printers : 
     170                    raise PyKotaCommandLineError, _("There's no printer matching %s") % " ".join(names) 
     171                         
     172            if not options["list"] : 
     173                self.display("%s...\n" % _("Modification")) 
    144174                 
    145175            if options["groups"] :         
     
    147177                if not printersgroups : 
    148178                    raise PyKotaCommandLineError, _("There's no printer matching %s") % " ".join(options["groups"].split(',')) 
    149                  
     179                     
    150180            if options["charge"] : 
    151181                try : 
     
    170200                maxjobsize = None 
    171201                     
    172                      
    173             if options["add"] :     
    174                 printers = [] 
    175                 for pname in names : 
    176                     printer = self.storage.getPrinter(pname) 
    177                     if printer.Exists : 
    178                         if options["skipexisting"] : 
    179                             self.printInfo(_("Printer %s already exists, skipping.") % printer.Name) 
    180                         else :     
    181                             self.printInfo(_("Printer %s already exists, will be modified.") % printer.Name) 
    182                             printers.append(printer) 
    183                     else : 
    184                         if self.isValidName(pname) : 
    185                             printer = self.storage.addPrinter(pname) 
    186                             if not printer.Exists : 
    187                                 raise PyKotaToolError, _("Impossible to add printer %s") % pname 
    188                             else :     
    189                                 printers.append(printer) 
    190                         else :     
    191                             raise PyKotaCommandLineError, _("Invalid printer name %s") % pname 
    192             else :         
    193                 printers = self.storage.getMatchingPrinters(",".join(names)) 
    194                 if not printers : 
    195                     raise PyKotaCommandLineError, _("There's no printer matching %s") % " ".join(names) 
    196                          
    197             for printer in printers :         
     202            nbtotal = len(printers) 
     203            for i in range(nbtotal) :         
     204                printer = printers[i] 
    198205                if options["list"] :     
    199206                    parents = ", ".join([p.Name for p in self.storage.getParentPrinters(printer)]) 
     
    224231                            else : 
    225232                                pgroup.addPrinterToGroup(printer)     
     233                    percent = 100.0 * float(i) / float(nbtotal) 
     234                    self.display("\r%.02f%%" % percent) 
     235                                 
     236        if not options["list"] :                 
     237            self.display("\r100.00%%\r        \r%s\n" % _("Done.")) 
    226238                      
    227239if __name__ == "__main__" :