Changeset 2466 for pykota/trunk/bin

Show
Ignore:
Timestamp:
09/19/05 19:26:41 (19 years ago)
Author:
jerome
Message:

Much more powerful pkturnkey

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pkturnkey

    r2435 r2466  
    4141command line usage : 
    4242 
    43   pkturnkey [options] 
     43  pkturnkey [options] [printqueues names] 
    4444 
    4545options : 
     
    9292  To REALLY initialize the database instead of simulating it, please 
    9393  use the -f | --force command line switch. 
     94   
     95  You can limit the initialization to only a subset of the existing 
     96  printers, by passing their names at the end of the command line. 
    9497""") 
    9598         
    9699class PKTurnKey(Tool) : 
    97100    """A class for an initialization tool.""" 
    98     def listPrinters(self) : 
     101    def listPrinters(self, namestomatch) : 
    99102        """Returns a list of tuples (queuename, deviceuri) for all existing print queues.""" 
    100103        self.printInfo("Extracting all print queues.") 
     
    107110            deviceuri = end.strip() 
    108111            queuename = begin.split()[-1] 
    109             printers.append((queuename, deviceuri)) 
     112            if self.matchString(queuename, namestomatch) : 
     113                printers.append((queuename, deviceuri)) 
     114            else :     
     115                self.printInfo("Print queue %s skipped." % queuename) 
    110116        return printers     
    111117         
     
    160166                self.printInfo(_("Printer %s is not managed by PyKota yet. Please modify printers.conf and restart CUPS.") % p, "warn") 
    161167         
    162     def createUsers(self, users, dryrun=0) : 
     168    def createUsers(self, users, printers, dryrun=0) : 
    163169        """Creates all users in PyKota's database.""" 
    164170        if users : 
    165             command = "edpykota --add --noquota %s" % " ".join(['"%s"' % u for u in users]) 
     171            printersnames = [p[0] for p in printers] 
     172            command = "edpykota --add --noquota --printer %s %s" % (",".join(['"%s"' % p for p in printersnames]), \ 
     173                                                                    " ".join(['"%s"' % u for u in users])) 
    166174            self.runCommand(command, dryrun) 
    167175             
    168     def createGroups(self, groups, dryrun=0) : 
     176    def createGroups(self, groups, printers, dryrun=0) : 
    169177        """Creates all groups in PyKota's database.""" 
    170178        if groups : 
    171             commands = ["edpykota --groups --add --noquota %s" % " ".join(['"%s"' % g for g in groups.keys()])] 
     179            printersnames = [p[0] for p in printers] 
     180            commands = ["edpykota --add --groups --noquota --printer %s %s" % (",".join(['"%s"' % p for p in printersnames]), \ 
     181                                                                               " ".join(['"%s"' % g for g in groups.keys()]))] 
    172182            revmembership = {} 
    173183            for (groupname, usernames) in groups.items() : 
     
    184194            raise PyKotaToolError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command.")) 
    185195             
    186         # TODO : names not used for now     
    187196        if not names : 
    188197            names = ["*"] 
     
    259268            groups = [] 
    260269             
    261         printers = self.listPrinters()                     
     270        printers = self.listPrinters(names) 
    262271        if printers : 
    263272            self.createPrinters(printers, dryrun) 
    264             self.createUsers([entry[0] for entry in users], dryrun) 
    265             self.createGroups(groups, dryrun) 
     273            self.createUsers([entry[0] for entry in users], printers, dryrun) 
     274            self.createGroups(groups, printers, dryrun) 
    266275         
    267276        if dryrun :