Changeset 2512

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.

Location:
pykota/trunk
Files:
14 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/autopykota

    r2447 r2512  
    2828import os 
    2929 
    30 from pykota.tool import PyKotaTool, PyKotaToolError, crashed, N_ 
     30from pykota.tool import PyKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 
    3131 
    3232__doc__ = N_("""autopykota v%(__version__)s (c) %(__years__)s %(__author__)s 
     
    115115            automat.display_version_and_quit() 
    116116        elif args :     
    117             raise PyKotaToolError, "autopykota doesn't accept non option arguments !" 
     117            raise PyKotaCommandLineError, "autopykota doesn't accept non option arguments !" 
    118118        else : 
    119119            retcode = automat.main(args, options) 
    120120    except KeyboardInterrupt :         
    121121        sys.stderr.write("\nInterrupted with Ctrl+C !\n") 
     122    except PyKotaCommandLineError, msg :     
     123        sys.stderr.write("%s : %s\n" % (sys.argv[0], msg)) 
    122124    except SystemExit :         
    123125        pass 
  • pykota/trunk/bin/dumpykota

    r2344 r2512  
    2929 
    3030from pykota import version 
    31 from pykota.tool import PyKotaToolError, crashed, N_ 
     31from pykota.tool import PyKotaToolError, PyKotaCommandLineError, crashed, N_ 
    3232from pykota.dumper import DumPyKota 
    3333 
     
    154154            dumper.display_version_and_quit() 
    155155        elif options["data"] is None :     
    156             raise PyKotaToolError, _("The -d | --data command line option is mandatory, see help.") 
     156            raise PyKotaCommandLineError, _("The -d | --data command line option is mandatory, see help.") 
    157157        else : 
    158158            retcode = dumper.main(args, options) 
    159159    except KeyboardInterrupt :         
    160160        sys.stderr.write("\nInterrupted with Ctrl+C !\n") 
     161    except PyKotaCommandLineError, msg :     
     162        sys.stderr.write("%s : %s\n" % (sys.argv[0], msg)) 
    161163    except SystemExit :         
    162164        pass 
  • pykota/trunk/bin/edpykota

    r2472 r2512  
    2929import pwd 
    3030import grp 
    31 from pykota.tool import PyKotaTool, PyKotaToolError, crashed, N_ 
     31from pykota.tool import PyKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 
    3232from pykota.config import PyKotaConfigError 
    3333from pykota.storage import PyKotaStorageError 
     
    246246        """Edit user or group quotas.""" 
    247247        if not self.config.isAdmin : 
    248             raise PyKotaToolError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command.")) 
     248            raise PyKotaCommandLineError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command.")) 
    249249         
    250250        suffix = (options["groups"] and "Group") or "User"         
     
    261261            if limitby not in ('quota', 'balance', 'noquota', \ 
    262262                                        'noprint', 'nochange') : 
    263                 raise PyKotaToolError, _("Invalid limitby value %s") % options["limitby"] 
     263                raise PyKotaCommandLineError, _("Invalid limitby value %s") % options["limitby"] 
    264264            if limitby in ('noquota', 'nochange') :     
    265265                options["noquota"] = 1 
    266266            if (limitby in ('nochange', 'noprint')) and options["groups"] :     
    267                 raise PyKotaToolError, _("Invalid limitby value %s") % options["limitby"] 
     267                raise PyKotaCommandLineError, _("Invalid limitby value %s") % options["limitby"] 
    268268 
    269269        used = options["used"] 
     
    273273                int(used) 
    274274            except ValueError : 
    275                 raise PyKotaToolError, _("Invalid used value %s.") % used 
     275                raise PyKotaCommandLineError, _("Invalid used value %s.") % used 
    276276                 
    277277        increase = options["increase"] 
     
    280280                increase = int(increase.strip()) 
    281281            except ValueError : 
    282                 raise PyKotaToolError, _("Invalid increase value %s.") % increase 
     282                raise PyKotaCommandLineError, _("Invalid increase value %s.") % increase 
    283283 
    284284        if not options["noquota"] : 
     
    289289                        raise ValueError 
    290290                except ValueError :     
    291                     raise PyKotaToolError, _("Invalid softlimit value %s.") % options["softlimit"] 
     291                    raise PyKotaCommandLineError, _("Invalid softlimit value %s.") % options["softlimit"] 
    292292            if options["hardlimit"] : 
    293293                try : 
     
    296296                        raise ValueError 
    297297                except ValueError :     
    298                     raise PyKotaToolError, _("Invalid hardlimit value %s.") % options["hardlimit"] 
     298                    raise PyKotaCommandLineError, _("Invalid hardlimit value %s.") % options["hardlimit"] 
    299299            if (softlimit is not None) and (hardlimit is not None) and (hardlimit < softlimit) :         
    300300                # error, exchange them 
     
    307307                overcharge = float(overcharge.strip()) 
    308308            except (ValueError, AttributeError) :     
    309                 raise PyKotaToolError, _("Invalid overcharge value %s") % options["overcharge"] 
     309                raise PyKotaCommandLineError, _("Invalid overcharge value %s") % options["overcharge"] 
    310310                 
    311311        balance = options["balance"] 
     
    315315                balancevalue = float(balance) 
    316316            except ValueError :     
    317                 raise PyKotaToolError, _("Invalid balance value %s") % options["balance"] 
     317                raise PyKotaCommandLineError, _("Invalid balance value %s") % options["balance"] 
    318318             
    319319        if options["charge"] : 
     
    321321                charges = [float(part) for part in options["charge"].split(',', 1)] 
    322322            except ValueError :     
    323                 raise PyKotaToolError, _("Invalid charge amount value %s") % options["charge"] 
     323                raise PyKotaCommandLineError, _("Invalid charge amount value %s") % options["charge"] 
    324324            else :     
    325325                if len(charges) > 2 : 
     
    346346                        raise PyKotaToolError, _("Impossible to add printer %s") % pname 
    347347                else :     
    348                     raise PyKotaToolError, _("Invalid printer name %s") % pname 
     348                    raise PyKotaCommandLineError, _("Invalid printer name %s") % pname 
    349349            else : 
    350                 raise PyKotaToolError, _("There's no printer matching %s") % pname 
     350                raise PyKotaCommandLineError, _("There's no printer matching %s") % pname 
    351351        if not names :     
    352352            if options["delete"] :     
    353                 raise PyKotaToolError, _("You have to pass user or group names on the command line") 
     353                raise PyKotaCommandLineError, _("You have to pass user or group names on the command line") 
    354354            else : 
    355355                names = getattr(self.storage, "getAll%ssNames" % suffix)() # all users or groups 
     
    362362            protoentry = getattr(self.storage, "get%s" % suffix)(options["prototype"]) 
    363363            if not protoentry.Exists : 
    364                 raise PyKotaToolError, _("Prototype object %s not found in Quota Storage.") % protoentry.Name 
     364                raise PyKotaCommandLineError, _("Prototype object %s not found in Quota Storage.") % protoentry.Name 
    365365            else :     
    366366                limitby = protoentry.LimitBy 
     
    598598            editor.display_version_and_quit() 
    599599        elif options["users"] and options["groups"] :     
    600             raise PyKotaToolError, _("incompatible options, see help.") 
     600            raise PyKotaCommandLineError, _("incompatible options, see help.") 
    601601        elif (options["add"] or options["prototype"]) and options["delete"] :     
    602             raise PyKotaToolError, _("incompatible options, see help.") 
     602            raise PyKotaCommandLineError, _("incompatible options, see help.") 
    603603        elif (options["reset"] or options["hardreset"] or options["limitby"] or options["used"] or options["balance"] or options["overcharge"] or options["softlimit"] or options["hardlimit"]) and options["prototype"] : 
    604             raise PyKotaToolError, _("incompatible options, see help.") 
     604            raise PyKotaCommandLineError, _("incompatible options, see help.") 
    605605        elif options["noquota"] and (options["prototype"] or options["hardlimit"] or options["softlimit"]) : 
    606             raise PyKotaToolError, _("incompatible options, see help.") 
     606            raise PyKotaCommandLineError, _("incompatible options, see help.") 
    607607        elif options["groups"] and (options["balance"] or options["ingroups"] or options["used"] or options["overcharge"]) : 
    608             raise PyKotaToolError, _("incompatible options, see help.") 
     608            raise PyKotaCommandLineError, _("incompatible options, see help.") 
    609609        elif options["comment"] and not options["balance"] :     
    610             raise PyKotaToolError, _("incompatible options, see help.") 
     610            raise PyKotaCommandLineError, _("incompatible options, see help.") 
    611611        else : 
    612612            retcode = editor.main(args, options) 
    613613    except KeyboardInterrupt :         
    614614        sys.stderr.write("\nInterrupted with Ctrl+C !\n") 
     615    except PyKotaCommandLineError, msg :      
     616        sys.stderr.write("%s : %s\n" % (sys.argv[0], msg)) 
    615617    except SystemExit :         
    616618        pass 
  • pykota/trunk/bin/pkbanner

    r2344 r2512  
    4747    hasPIL = 1 
    4848     
    49 from pykota.tool import Tool, PyKotaToolError, crashed, N_ 
     49from pykota.tool import Tool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 
    5050 
    5151__doc__ = N_("""pkbanner v%(__version__)s (c) %(__years__)s %(__author__)s 
     
    312312    except KeyboardInterrupt :         
    313313        sys.stderr.write("\nInterrupted with Ctrl+C !\n") 
     314    except PyKotaCommandLineError, msg :     
     315        sys.stderr.write("%s : %s\n" % (sys.argv[0], msg)) 
    314316    except SystemExit :         
    315317        pass 
  • 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 
  • pykota/trunk/bin/pkmail

    r2352 r2512  
    3131import email 
    3232 
    33 from pykota.tool import PyKotaTool, PyKotaToolError, crashed, N_ 
     33from pykota.tool import PyKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 
    3434     
    3535__doc__ = N_("""pkmail v%(__version__)s (c) %(__years__)s %(__author__)s 
     
    8787            (command, arguments) = (cmdargs[0].capitalize(), cmdargs[1:]) 
    8888        except IndexError :     
    89             raise PyKotaToolError, "No command found !" 
     89            raise PyKotaCommandLineError, "No command found !" 
    9090         
    9191        badchars = """/<>&"'#!%*$,;\\""" 
     
    159159    except KeyboardInterrupt :         
    160160        sys.stderr.write("\nInterrupted with Ctrl+C !\n") 
     161    except PyKotaCommandLineError, msg :     
     162        sys.stderr.write("%s : %s\n" % (sys.argv[0], msg)) 
    161163    except SystemExit :         
    162164        pass 
  • 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 
  • pykota/trunk/bin/pkturnkey

    r2509 r2512  
    3232import signal 
    3333 
    34 from pykota.tool import Tool, PyKotaToolError, crashed, N_ 
     34from pykota.tool import Tool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 
    3535 
    3636__doc__ = N_("""pkturnkey v%(__version__)s (c) %(__years__)s %(__author__)s 
     
    342342        """Intializes PyKota's database.""" 
    343343        if not self.config.isAdmin : 
    344             raise PyKotaToolError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0],\ 
     344            raise PyKotaCommandLineError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0],\ 
    345345                                   _("You're not allowed to use this command.")) 
    346346             
     
    366366                        uidmin = pwd.getpwnam(options["uidmin"])[2] 
    367367                    except KeyError, msg :     
    368                         raise PyKotaToolError, _("Unknown username %s : %s") \ 
     368                        raise PyKotaCommandLineError, _("Unknown username %s : %s") \ 
    369369                                                   % (options["uidmin"], msg) 
    370370                         
     
    378378                        uidmax = pwd.getpwnam(options["uidmax"])[2] 
    379379                    except KeyError, msg :     
    380                         raise PyKotaToolError, _("Unknown username %s : %s") \ 
     380                        raise PyKotaCommandLineError, _("Unknown username %s : %s") \ 
    381381                                                   % (options["uidmax"], msg) 
    382382             
     
    398398                        gidmin = grp.getgrnam(options["gidmin"])[2] 
    399399                    except KeyError, msg :     
    400                         raise PyKotaToolError, _("Unknown groupname %s : %s") \ 
     400                        raise PyKotaCommandLineError, _("Unknown groupname %s : %s") \ 
    401401                                                   % (options["gidmin"], msg) 
    402402                         
     
    410410                        gidmax = grp.getgrnam(options["gidmax"])[2] 
    411411                    except KeyError, msg :     
    412                         raise PyKotaToolError, _("Unknown groupname %s : %s") \ 
     412                        raise PyKotaCommandLineError, _("Unknown groupname %s : %s") \ 
    413413                                                   % (options["gidmax"], msg) 
    414414             
     
    492492    except KeyboardInterrupt :         
    493493        sys.stderr.write("\nInterrupted with Ctrl+C !\n") 
     494    except PyKotaCommandLineError, msg :     
     495        sys.stderr.write("%s : %s\n" % (sys.argv[0], msg)) 
    494496    except SystemExit :         
    495497        pass 
  • pykota/trunk/bin/pykosd

    r2344 r2512  
    3636    sys.exit(-1) 
    3737 
    38 from pykota.tool import PyKotaTool, PyKotaToolError, crashed, N_ 
     38from pykota.tool import PyKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 
    3939 
    4040__doc__ = N_("""pykosd v%(__version__)s (c) %(__years__)s %(__author__)s 
     
    8383        try :     
    8484            duration = int(options["duration"]) 
    85         except :     
    86             raise PyKotaToolError, _("Invalid duration option %s") % str(options["duration"]) 
     85            if duration <= 0 : 
     86                raise ValueError  
     87        except :     
     88            raise PyKotaCommandLineError, _("Invalid duration option %s") % str(options["duration"]) 
    8789             
    8890        try :     
    8991            loop = int(options["loop"]) 
    90         except :     
    91             raise PyKotaToolError, _("Invalid loop option %s") % str(options["loop"]) 
     92            if loop < 0 : 
     93                raise ValueError 
     94        except :     
     95            raise PyKotaCommandLineError, _("Invalid loop option %s") % str(options["loop"]) 
    9296             
    9397        try :     
    9498            sleep = float(options["sleep"]) 
    95         except :     
    96             raise PyKotaToolError, _("Invalid sleep option %s") % str(options["sleep"]) 
     99            if sleep <= 0 : 
     100                raise ValueError 
     101        except :     
     102            raise PyKotaCommandLineError, _("Invalid sleep option %s") % str(options["sleep"]) 
    97103             
    98104        color = options["color"]     
     
    100106            color = "#%s" % color 
    101107        if len(color) != 7 :     
    102             raise PyKotaToolError, _("Invalid color option %s") % str(color) 
     108            raise PyKotaCommandLineError, _("Invalid color option %s") % str(color) 
    103109        savecolor = color 
    104110         
     
    108114            user = cmd.storage.getUserFromBackend(uname)        # don't use cache 
    109115            if not user.Exists : 
    110                 raise PyKotaToolError, _("User %s doesn't exist in PyKota's database") % uname 
     116                raise PyKotaCommandLineError, _("User %s doesn't exist in PyKota's database") % uname 
    111117            if user.LimitBy == "quota" :     
    112118                printers = cmd.storage.getMatchingPrinters("*") 
     
    177183    except KeyboardInterrupt :         
    178184        sys.stderr.write("\nInterrupted with Ctrl+C !\n") 
     185    except PyKotaCommandLineError, msg :     
     186        sys.stderr.write("%s : %s\n" % (sys.argv[0], msg)) 
    179187    except SystemExit :         
    180188        pass 
  • pykota/trunk/bin/pykotme

    r2352 r2512  
    2929import pwd 
    3030 
    31 from pykota.tool import PyKotaTool, PyKotaToolError, crashed, N_ 
     31from pykota.tool import PyKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 
    3232 
    3333try : 
     
    9696        printers = self.storage.getMatchingPrinters(options["printer"]) 
    9797        if not printers : 
    98             raise PyKotaToolError, _("There's no printer matching %s") % options["printer"] 
     98            raise PyKotaCommandLineError, _("There's no printer matching %s") % options["printer"] 
    9999             
    100100        username = pwd.getpwuid(os.getuid())[0] 
     
    140140    except KeyboardInterrupt :         
    141141        sys.stderr.write("\nInterrupted with Ctrl+C !\n") 
     142    except PyKotaCommandLineError, msg :     
     143        sys.stderr.write("%s : %s\n" % (sys.argv[0], msg)) 
    142144    except SystemExit :         
    143145        pass 
  • pykota/trunk/bin/repykota

    r2452 r2512  
    3131from mx import DateTime 
    3232 
    33 from pykota.tool import PyKotaTool, PyKotaToolError, crashed, N_ 
    34 from pykota.config import PyKotaConfigError 
    35 from pykota.storage import PyKotaStorageError 
    36 from pykota.reporter import PyKotaReporterError 
     33from pykota.tool import PyKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 
    3734from pykota import reporter 
    3835 
     
    110107            # reports only the current user 
    111108            if options["ingroups"] : 
    112                 raise PyKotaToolError, _("Option --ingroups is reserved to PyKota Administrators.") 
     109                raise PyKotaCommandLineError, _("Option --ingroups is reserved to PyKota Administrators.") 
    113110                 
    114111            username = pwd.getpwuid(os.geteuid())[0] 
     
    124121        printers = self.storage.getMatchingPrinters(options["printer"]) 
    125122        if not printers : 
    126             raise PyKotaToolError, _("There's no printer matching %s") % options["printer"] 
     123            raise PyKotaCommandLineError, _("There's no printer matching %s") % options["printer"] 
    127124             
    128125        self.reportingtool = reporter.openReporter(self, "text", printers, ugnames, (options["groups"] and 1) or 0)     
     
    157154        elif options["version"] : 
    158155            reportTool.display_version_and_quit() 
    159         elif options["users"] and options["groups"] :     
    160             raise PyKotaToolError, _("incompatible options, see help.") 
     156        elif (options["users"] or options["ingroups"]) and options["groups"] : 
     157            raise PyKotaCommandLineError, _("incompatible options, see help.") 
    161158        else : 
    162159            retcode = reportTool.main(args, options) 
    163160    except KeyboardInterrupt :         
    164161        sys.stderr.write("\nInterrupted with Ctrl+C !\n") 
     162    except PyKotaCommandLineError, msg :     
     163        sys.stderr.write("%s : %s\n" % (sys.argv[0], msg)) 
    165164    except SystemExit :         
    166165        pass 
  • pykota/trunk/bin/warnpykota

    r2344 r2512  
    2929import pwd 
    3030 
    31 from pykota.tool import PyKotaTool, PyKotaToolError, crashed, N_ 
     31from pykota.tool import PyKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 
    3232from pykota.config import PyKotaConfigError 
    3333from pykota.storage import PyKotaStorageError 
     
    108108        printers = self.storage.getMatchingPrinters(options["printer"]) 
    109109        if not printers : 
    110             raise PyKotaToolError, _("There's no printer matching %s") % options["printer"] 
     110            raise PyKotaCommandLineError, _("There's no printer matching %s") % options["printer"] 
    111111        alreadydone = {} 
    112112        for printer in printers : 
     
    155155            sender.display_version_and_quit() 
    156156        elif options["users"] and options["groups"] :     
    157             raise PyKotaToolError, _("incompatible options, see help.") 
     157            raise PyKotaCommandLineError, _("incompatible options, see help.") 
    158158        else : 
    159159            retcode = sender.main(args, options) 
    160160    except KeyboardInterrupt :         
    161161        sys.stderr.write("\nInterrupted with Ctrl+C !\n") 
     162    except PyKotaCommandLineError, msg :     
     163        sys.stderr.write("%s : %s\n" % (sys.argv[0], msg)) 
    162164    except SystemExit :         
    163165        pass 
  • pykota/trunk/pykota/dumper.py

    r2342 r2512  
    3939 
    4040from pykota import version 
    41 from pykota.tool import PyKotaTool, PyKotaToolError, N_ 
     41from pykota.tool import PyKotaTool, PyKotaToolError, PyKotaCommandLineError, N_ 
    4242 
    4343class DumPyKota(PyKotaTool) :         
     
    7272        """Print Quota Data Dumper.""" 
    7373        if restricted and not self.config.isAdmin : 
    74             raise PyKotaToolError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command.")) 
     74            raise PyKotaCommandLineError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command.")) 
    7575             
    7676        extractonly = {} 
     
    8282                        raise ValueError                 
    8383                except ValueError :     
    84                     raise PyKotaToolError, _("Invalid filter value [%s], see help.") % filterexp 
     84                    raise PyKotaCommandLineError, _("Invalid filter value [%s], see help.") % filterexp 
    8585                else :     
    8686                    extractonly.update({ filterkey : filtervalue }) 
     
    8888        datatype = options["data"] 
    8989        if datatype not in self.validdatatypes.keys() : 
    90             raise PyKotaToolError, _("Invalid modifier [%s] for --data command line option, see help.") % datatype 
     90            raise PyKotaCommandLineError, _("Invalid modifier [%s] for --data command line option, see help.") % datatype 
    9191                     
    9292        format = options["format"] 
    9393        if (format not in self.validformats.keys()) \ 
    9494              or ((format == "cups") and ((datatype != "history") or options["sum"])) : 
    95             raise PyKotaToolError, _("Invalid modifier [%s] for --format command line option, see help.") % format 
     95            raise PyKotaCommandLineError, _("Invalid modifier [%s] for --format command line option, see help.") % format 
    9696             
    9797        if (format == "xml") and not hasJAXML : 
     
    9999             
    100100        if options["sum"] and datatype not in ("payments", "history") :  
    101             raise PyKotaToolError, _("Invalid data type [%s] for --sum command line option, see help.") % datatype 
     101            raise PyKotaCommandLineError, _("Invalid data type [%s] for --sum command line option, see help.") % datatype 
    102102             
    103103        entries = getattr(self.storage, "extract%s" % datatype.title())(extractonly) 
  • pykota/trunk/pykota/tool.py

    r2511 r2512  
    5353 
    5454class PyKotaToolError(Exception): 
    55     """An exception for PyKota config related stuff.""" 
     55    """An exception for PyKota related stuff.""" 
    5656    def __init__(self, message = ""): 
    5757        self.message = message 
     
    6060        return self.message 
    6161    __str__ = __repr__ 
     62     
     63class PyKotaCommandLineError(PyKotaToolError) :     
     64    """An exception for Pykota command line tools.""" 
     65    pass 
    6266     
    6367def crashed(message="Bug in PyKota") :