Changeset 2337

Show
Ignore:
Timestamp:
06/30/05 13:28:18 (19 years ago)
Author:
jerome
Message:

The pkbcodes command line tool should be ok now, but the database
handling code still lacks support for the BillingCode? class (which
doesn't even exist yet)
Severity : still a work in progress.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pkbcodes

    r2332 r2337  
    5858 
    5959  -s | --skipexisting  In combination with the --add option above, tells 
    60                        pkbcodes to not modify existing printers. 
     60                       pkbcodes to not modify existing billing codes. 
    6161 
    6262  code1 through codeN can contain wildcards if the --add option 
     
    9696         
    9797class PKBcodes(PyKotaTool) :         
    98     """A class for edpykota.""" 
     98    """A class for a billing codes manager.""" 
    9999    def main(self, names, options) : 
    100         """Manage printers.""" 
    101         raise "Not Implemented yet !!! Please be patient !!!" 
    102          
     100        """Manage billing codes.""" 
    103101        if (not self.config.isAdmin) and (not options["list"]) : 
    104102            raise PyKotaToolError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command.")) 
     
    107105            names = ["*"] 
    108106             
    109         if options["groups"] :         
    110             printersgroups = self.storage.getMatchingPrinters(options["groups"]) 
    111             if not printersgroups : 
    112                 raise PyKotaToolError, _("There's no printer matching %s") % " ".join(options["groups"].split(',')) 
    113              
    114         if options["charge"] : 
    115             try : 
    116                 charges = [float(part) for part in options["charge"].split(',', 1)] 
    117             except ValueError :     
    118                 raise PyKotaToolError, _("Invalid charge amount value %s") % options["charge"] 
     107        if options["add"] :     
     108            billingcodes = [] 
     109            for bname in names : 
     110                billingcode = self.storage.getBillingCode(bname) 
     111                if billingcode.Exists : 
     112                    if options["skipexisting"] : 
     113                        self.printInfo(_("Billing code [%s] already exists, skipping.") % billingcode.Name) 
     114                    else :     
     115                        self.printInfo(_("Billing code [%s] already exists, will be modified.") % billingcode.Name) 
     116                        billingcodes.append(billingcode) 
     117                else : 
     118                    billingcode = self.storage.addBillingCode(bname) 
     119                    if not billingcode.Exists : 
     120                        raise PyKotaToolError, _("Impossible to add billingcode %s") % bname 
     121                    else :      
     122                        billingcodes.append(billingcode) 
     123        else :         
     124            billingcodes = self.storage.getMatchingBillingCodes(",".join(names)) 
     125            if not billingcodes : 
     126                raise PyKotaToolError, _("There's no billingcode matching %s") % " ".join(names) 
     127                     
     128        for billingcode in billingcodes :         
     129            if options["delete"] : 
     130                billingcode.delete() 
     131            elif options["list"] :     
     132                print "%s [%s] %s %s %s %.2f %s" % \ 
     133                      (billingcode.Name, billingcode.Description, \ 
     134                       billingcode.PageCounter, \ 
     135                       _("pages"), \ 
     136                       _("and"), \ 
     137                       billingcode.Balance, \ 
     138                       _("credits")) 
    119139            else :     
    120                 if len(charges) > 2 : 
    121                     charges = charges[:2] 
    122                 if len(charges) != 2 : 
    123                     charges = [charges[0], None] 
    124                 (perpage, perjob) = charges 
    125                  
    126         if options["add"] :     
    127             printers = [] 
    128             for pname in names : 
    129                 printer = self.storage.getPrinter(pname) 
    130                 if printer.Exists : 
    131                     if options["skipexisting"] : 
    132                         self.printInfo(_("Printer %s already exists, skipping.") % printer.Name) 
    133                     else :     
    134                         self.printInfo(_("Printer %s already exists, will be modified.") % printer.Name) 
    135                         printers.append(printer) 
    136                 else : 
    137                     if self.isValidName(pname) : 
    138                         printer = self.storage.addPrinter(pname) 
    139                         if not printer.Exists : 
    140                             raise PyKotaToolError, _("Impossible to add printer %s") % pname 
    141                         else :     
    142                             printers.append(printer) 
    143                     else :     
    144                         raise PyKotaToolError, _("Invalid printer name %s") % pname 
    145         else :         
    146             printers = self.storage.getMatchingPrinters(",".join(names)) 
    147             if not printers : 
    148                 raise PyKotaToolError, _("There's no printer matching %s") % " ".join(names) 
    149                      
    150         for printer in printers :         
    151             if options["delete"] : 
    152                 printer.delete() 
    153             elif options["list"] :     
    154                 parents = ", ".join([p.Name for p in self.storage.getParentPrinters(printer)]) 
    155                 if parents :  
    156                     parents = "%s %s" % (_("in"), parents) 
    157                 print "%s [%s] (%s + #*%s) %s" % \ 
    158                       (printer.Name, printer.Description, printer.PricePerJob, \ 
    159                        printer.PricePerPage, parents) 
    160             else :     
    161                 if options["charge"] : 
    162                     printer.setPrices(perpage, perjob)     
     140                if options["reset"] : 
     141                    billingcode.reset()     
    163142                if options["description"] is not None : 
    164                     printer.setDescription(options["description"].strip()) 
    165                 if options["groups"] :     
    166                     for pgroup in printersgroups : 
    167                         if options["remove"] : 
    168                             pgroup.delPrinterFromGroup(printer) 
    169                         else : 
    170                             pgroup.addPrinterToGroup(printer)     
     143                    billingcode.setDescription(options["description"].strip()) 
    171144                      
    172145if __name__ == "__main__" :