Show
Ignore:
Timestamp:
02/21/06 23:24:47 (19 years ago)
Author:
jerome
Message:

Reactivated the autopykota command line tool.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/autopykota

    r2715 r2744  
    6464        else : 
    6565            printer = self.storage.getPrinter(printername) 
     66            if not printer.Exists : 
     67                self.logdebug("Creating printer %s which doesn't exist yet." % printername) 
     68                os.system('pkprinters --add --description "printer created from autopykota" "%s"' % printername) 
     69                printer = self.storage.getPrinterFromBackend(printername) 
     70                if printer.Exists : 
     71                    self.logdebug("Printer %s created successfully." % printername) 
     72                else :     
     73                    self.logdebug("Impossible to create printer %s." % printername) 
     74                printernames = [printername] 
     75            else :     
     76                printernames = [printer.Name] + [p.Name for p in self.storage.getParentPrinters(printer)] 
     77             
    6678            user = self.storage.getUser(username) 
    67             if user.Exists : 
    68                 self.logdebug("User %s already exits." % username)  
    69                 if printer.Exists : 
    70                     userpquota = self.storage.getUserPQuota(user, printer) 
     79            if not user.Exists : 
     80                self.logdebug("Creating user %s which doesn't exist yet." % username) 
     81                os.system('pkusers --add --limitby balance --balance "%s" --description "user created from autopykota" "%s"' % (options["initbalance"], username)) 
     82                user = self.storage.getUserFromBackend(username) 
     83                if user.Exists : 
     84                    self.logdebug("User %s created successfully." % username) 
     85                else :     
     86                    self.logdebug("Impossible to create user %s." % username) 
     87                 
     88            if user.Exists and printer.Exists :     
     89                userpquota = self.storage.getUserPQuota(user, printer) 
     90                if not userpquota.Exists : 
     91                    self.logdebug("Creating a print quota entry for user %s on printers %s" % (username, printernames)) 
     92                    os.system('edpykota --add --printer "%s" "%s"' % (','.join(printernames), username)) 
     93                    userpquota = self.storage.getUserPQuotaFromBackend(user, printer) 
    7194                    if userpquota.Exists : 
    72                         # we should never get there, unless autopykota was launched manually 
    73                         self.logdebug("User %s's quota entry on printer %s already exists. Nothing to do." % (username, printername)) 
     95                        self.logdebug("User %s's print quota entry on printer %s created successfully." % (username, printername)) 
    7496                        return 0 
    7597                    else :     
    76                         printersnames = [printer.Name] + [p.Name for p in self.storage.getParentPrinters(printer)] 
    77                         self.logdebug("Creating a quota entry for user %s on printers %s" % (username, printersnames)) 
    78                         return os.system('edpykota --add --printer "%s" "%s"' % (','.join(printersnames), username)) 
     98                        self.logdebug("Impossible to create user %s's print quota entry on printer %s." % (username, printername)) 
     99                        return -1 
    79100                else : 
    80                     self.logdebug("Printer %s doesn't exist. Creating printer %s and a quota entry for user %s on printer %s." % (printername, printername, username, printername)) 
    81                     return os.system('edpykota --add --printer "%s" "%s"' % (printername, username)) 
    82             else : 
    83                 if printer.Exists : 
    84                     printersnames = [printer.Name] + [p.Name for p in self.storage.getParentPrinters(printer)] 
    85                 else :     
    86                     printersnames = [printer.Name] 
    87                 self.logdebug("User %s doesn't exist yet." % username) 
    88                 self.logdebug("Creating user %s's account with balance %s and quota entries on printers %s" % (username, options["initbalance"], printersnames)) 
    89                 return os.system('edpykota --add --limitby balance --balance "%s" --printer "%s" "%s"' % (options["initbalance"], ','.join(printersnames), username)) 
    90      
     101                    self.logdebug("User %s's print quota entry on printer %s already exists. Nothing to do." % (username, printername)) 
     102                    return 0 
     103            else :         
     104                return -1 
     105                 
    91106if __name__ == "__main__" :     
    92107    retcode = 0 
    93108    try : 
    94         raise PyKotaCommandLineError, "This version is not stable, download an earlier one. Operation aborted." 
    95          
    96109        defaults = { \ 
    97110                     "initbalance" : 0.0