Changeset 2661

Show
Ignore:
Timestamp:
02/10/06 21:52:01 (18 years ago)
Author:
jerome
Message:

Added important command line options to pkinvoice.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pkinvoice

    r2660 r2661  
    4848  -g | --groups        Generate invoices for users groups instead of users. 
    4949   
     50  -l | --logo img      Use the image as the banner's logo. The logo will 
     51                       be drawn at the center top of the page. The default 
     52                       logo is /usr/share/pykota/logos/pykota.jpeg 
     53                        
     54  -p | --pagesize sz   Sets sz as the page size. Most well known 
     55                       page sizes are recognized, like 'A4' or 'Letter' 
     56                       to name a few. The default size is A4. 
     57                        
     58  -n | --number N      Sets the number of the first invoice. This number 
     59                       will automatically be incremented for each invoice. 
     60                        
    5061  -r | --reference v   Uses v as the initial reference value : an invoice 
    5162                       will be generated for any account balance's value 
     
    8798            raise PyKotaCommandLineError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command.")) 
    8899         
    89         self.display("%s...\n" % _("Processing")) 
     100        try :     
     101            vat = float(options["vat"]) 
     102            if not (0.0 <= vat < 100.0) : 
     103                raise ValueError 
     104        except :     
     105            raise PyKotaCommandLineError, _("Incorrect value '%s' for the --vat command line option") % options["vat"] 
     106             
     107        try :     
     108            reference = float(options["reference"]) 
     109        except :     
     110            raise PyKotaCommandLineError, _("Incorrect value '%s' for the --reference command line option") % options["reference"] 
     111             
     112        try :     
     113            number = float(options["number"]) 
     114            if number <= 0 : 
     115                raise ValueError 
     116        except :     
     117            raise PyKotaCommandLineError, _("Incorrect value '%s' for the --number command line option") % options["number"] 
     118             
    90119        if not names : 
    91120            names = [ "*" ] 
     121             
     122        outfname = options["output"]     
     123        if outfname != "-" : 
     124            self.display("%s...\n" % _("Processing")) 
    92125             
    93126        suffix = (options["groups"] and "Group") or "User"         
     
    98131            # TODO  
    99132            percent = 100.0 * float(i) / float(nbtotal) 
    100             self.display("\r%.02f%%" % percent) 
    101         self.display("\r100.00%%\r        ") 
    102         self.display("\r%s\n" % _("Done.")) 
     133            if outfname != "-" : 
     134                self.display("\r%.02f%%" % percent) 
     135        if outfname != "-" :         
     136            self.display("\r100.00%%\r        ") 
     137            self.display("\r%s\n" % _("Done.")) 
    103138                      
    104139if __name__ == "__main__" :  
     
    109144                     "unit" : _("Credits"), 
    110145                     "output" : "-", 
     146                     "pagesize" : "a4", \ 
     147                     "logo" : "/usr/share/pykota/logos/pykota.jpeg", 
     148                     "number" : "1", 
    111149                   } 
    112         short_options = "vho:gr:u:V:" 
     150        short_options = "vho:gr:u:V:p:l:" 
    113151        long_options = ["help", "version", \ 
    114152                        "groups", "reference=", "unit=", "output=", \ 
    115                         "vat=", ] 
     153                        "pagesize=", "logo=", "vat=", "number="] 
    116154         
    117155        # Initializes the command line tool 
     
    131169        options["unit"] = options["u"] or options["unit"] or defaults["unit"] 
    132170        options["output"] = options["o"] or options["output"] or defaults["output"] 
     171        options["pagesize"] = options["p"] or options["pagesize"] or defaults["pagesize"] 
     172        options["number"] = options["n"] or options["number"] or defaults["number"] 
     173        options["logo"] = options["l"] or options["logo"] 
     174        if options["logo"] is None : # Allows --logo="" to disable the logo entirely 
     175            options["logo"] = defaults["logo"]   
    133176         
    134177        if options["help"] :