Show
Ignore:
Timestamp:
09/27/05 20:34:31 (19 years ago)
Author:
jerome
Message:

Ensure that human made errors (like incorrect command line options)
don't produce a traceback anymore. No need to frighten users with
such complete tracebacks and email reporting each time they mistype
some command.
Makes pykosd check more carefully the values of its command line options.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pkprinters

    r2465 r2512  
    2929import pwd 
    3030 
    31 from pykota.tool import PyKotaTool, PyKotaToolError, crashed, N_ 
     31from pykota.tool import PyKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 
    3232 
    3333__doc__ = N_("""pkprinters v%(__version__)s (c) %(__years__)s %(__author__)s 
     
    127127        """Manage printers.""" 
    128128        if (not self.config.isAdmin) and (not options["list"]) : 
    129             raise PyKotaToolError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command.")) 
     129            raise PyKotaCommandLineError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command.")) 
    130130             
    131131        if options["list"] and not names : 
     
    135135            printersgroups = self.storage.getMatchingPrinters(options["groups"]) 
    136136            if not printersgroups : 
    137                 raise PyKotaToolError, _("There's no printer matching %s") % " ".join(options["groups"].split(',')) 
     137                raise PyKotaCommandLineError, _("There's no printer matching %s") % " ".join(options["groups"].split(',')) 
    138138             
    139139        if options["charge"] : 
     
    141141                charges = [float(part) for part in options["charge"].split(',', 1)] 
    142142            except ValueError :     
    143                 raise PyKotaToolError, _("Invalid charge amount value %s") % options["charge"] 
     143                raise PyKotaCommandLineError, _("Invalid charge amount value %s") % options["charge"] 
    144144            else :     
    145145                if len(charges) > 2 : 
     
    155155                    raise ValueError 
    156156            except ValueError :     
    157                 raise PyKotaToolError, _("Invalid maximum job size value %s") % options["maxjobsize"] 
     157                raise PyKotaCommandLineError, _("Invalid maximum job size value %s") % options["maxjobsize"] 
    158158        else :         
    159159            maxjobsize = None 
     
    178178                            printers.append(printer) 
    179179                    else :     
    180                         raise PyKotaToolError, _("Invalid printer name %s") % pname 
     180                        raise PyKotaCommandLineError, _("Invalid printer name %s") % pname 
    181181        else :         
    182182            printers = self.storage.getMatchingPrinters(",".join(names)) 
    183183            if not printers : 
    184                 raise PyKotaToolError, _("There's no printer matching %s") % " ".join(names) 
     184                raise PyKotaCommandLineError, _("There's no printer matching %s") % " ".join(names) 
    185185                     
    186186        for printer in printers :         
     
    255255           or (options["list"] and (options["add"] or options["delete"] or options["groups"] or options["charge"] or options["remove"] or options["description"])) \ 
    256256           or (options["passthrough"] and options["nopassthrough"]) : 
    257             raise PyKotaToolError, _("incompatible options, see help.") 
     257            raise PyKotaCommandLineError, _("incompatible options, see help.") 
    258258        elif options["remove"] and not options["groups"] :     
    259             raise PyKotaToolError, _("You have to pass printer groups names on the command line") 
     259            raise PyKotaCommandLineError, _("You have to pass printer groups names on the command line") 
    260260        elif (not args) and (not options["list"]) :     
    261             raise PyKotaToolError, _("You have to pass printer names on the command line") 
     261            raise PyKotaCommandLineError, _("You have to pass printer names on the command line") 
    262262        else : 
    263263            retcode = manager.main(args, options) 
    264264    except KeyboardInterrupt :         
    265265        sys.stderr.write("\nInterrupted with Ctrl+C !\n") 
     266    except PyKotaCommandLineError, msg :     
     267        sys.stderr.write("%s : %s\n" % (sys.argv[0], msg)) 
    266268    except SystemExit :         
    267269        pass