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/pkbcodes

    r2344 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_("""pkbcodes v%(__version__)s (c) %(__years__)s %(__author__)s 
     
    8787        """Manage billing codes.""" 
    8888        if (not self.config.isAdmin) and (not options["list"]) : 
    89             raise PyKotaToolError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command.")) 
     89            raise PyKotaCommandLineError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command.")) 
    9090             
    9191        if (options["list"] or options["reset"]) and not names : 
     
    111111            billingcodes = self.storage.getMatchingBillingCodes(",".join(names)) 
    112112            if not billingcodes : 
    113                 raise PyKotaToolError, _("There's no billingcode matching %s") % " ".join(names) 
     113                raise PyKotaCommandLineError, _("There's no billingcode matching %s") % " ".join(names) 
    114114                     
    115115        for billingcode in billingcodes :         
     
    160160           or (options["skipexisting"] and not options["add"]) \ 
    161161           or (options["list"] and (options["add"] or options["delete"] or options["reset"] or options["description"])) : 
    162             raise PyKotaToolError, _("incompatible options, see help.") 
     162            raise PyKotaCommandLineError, _("incompatible options, see help.") 
    163163        elif (not args) and (options["add"] or options["delete"]) :     
    164             raise PyKotaToolError, _("You have to pass billing codes on the command line") 
     164            raise PyKotaCommandLineError, _("You have to pass billing codes on the command line") 
    165165        else : 
    166166            retcode = manager.main(args, options) 
    167167    except KeyboardInterrupt :         
    168168        sys.stderr.write("\nInterrupted with Ctrl+C !\n") 
     169    except PyKotaCommandLineError, msg :     
     170        sys.stderr.write("%s : %s\n" % (sys.argv[0], msg)) 
    169171    except SystemExit :         
    170172        pass