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