Changeset 3366 for pykota

Show
Ignore:
Timestamp:
05/03/08 18:45:38 (17 years ago)
Author:
jerome
Message:

Added a method to check if user is admin and fail if needed.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/utils.py

    r3354 r3366  
    2424import sys 
    2525import os 
     26import pwd 
    2627import locale 
    2728import gettext 
     
    3031from pykota.errors import PyKotaCommandLineError 
    3132 
     33def onlyAdmin(app, restricted=True) : 
     34    """Raises an exception if the user is not a PyKota administrator.""" 
     35    if restricted and not app.config.isAdmin : 
     36        raise PyKotaCommandLineError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command.")) 
     37         
    3238def initlocale(lang="", cset=None) : 
    3339    """Initializes the locale stuff."""