Changeset 3367

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

Moved new method around.

Location:
pykota/trunk
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pkbcodes

    r3362 r3367  
    4646    def main(self, names, options) : 
    4747        """Manage billing codes.""" 
    48         if (not self.config.isAdmin) and (options.action != "list") : 
    49             raise PyKotaCommandLineError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command.")) 
     48        if options.action != "list" : 
     49            self.adminOnly() 
    5050            
    5151        islist = (options.action == "list") 
  • pykota/trunk/bin/pkinvoice

    r3365 r3367  
    189189            raise PyKotaToolError, "The Python Imaging Library is missing. Download it from http://www.pythonware.com/downloads" 
    190190             
    191         if not self.config.isAdmin : 
    192             raise PyKotaCommandLineError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command.")) 
     191        self.adminOnly() 
    193192         
    194193        self.pagesize = getPageSize(options.pagesize) 
  • pykota/trunk/bin/pkprinters

    r3295 r3367  
    190190    def main(self, names, options) : 
    191191        """Manage printers.""" 
    192         if (not self.config.isAdmin) and (not options["list"]) : 
    193             raise PyKotaCommandLineError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command.")) 
     192        if not options["list"] : 
     193            self.adminOnly() 
    194194             
    195195        docups = options["cups"] 
  • pykota/trunk/bin/pkrefund

    r3360 r3367  
    183183            raise PyKotaToolError, "The Python Imaging Library is missing. Download it from http://www.pythonware.com/downloads" 
    184184             
    185         if not self.config.isAdmin : 
    186             raise PyKotaCommandLineError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command.")) 
     185        self.adminOnly()     
    187186             
    188187        self.pagesize = getPageSize(options.pagesize) 
  • pykota/trunk/bin/pkturnkey

    r3295 r3367  
    381381    def main(self, names, options) : 
    382382        """Intializes PyKota's database.""" 
    383         if not self.config.isAdmin : 
    384             raise PyKotaCommandLineError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], \ 
    385                                    _("You're not allowed to use this command.")) 
    386              
     383        self.adminOnly() 
     384         
    387385        if not names : 
    388386            names = ["*"] 
  • pykota/trunk/pykota/tool.py

    r3327 r3367  
    171171        sys.stderr.flush() 
    172172         
     173    def adminOnly(self, restricted=True) : 
     174        """Raises an exception if the user is not a PyKota administrator.""" 
     175        if restricted and not self.config.isAdmin : 
     176            raise PyKotaCommandLineError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command.")) 
     177             
    173178    def matchString(self, s, patterns) : 
    174179        """Returns True if the string s matches one of the patterns, else False.""" 
  • pykota/trunk/pykota/utils.py

    r3366 r3367  
    3131from pykota.errors import PyKotaCommandLineError 
    3232 
    33 def 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          
    3833def initlocale(lang="", cset=None) : 
    3934    """Initializes the locale stuff."""