Show
Ignore:
Timestamp:
09/03/05 15:48:56 (19 years ago)
Author:
jerome
Message:

Added the --dryrun command line option to pkturnkey.
Improved pkturnkey's general usability.
Added pkturnkey's manual page.
Updated other manpages.
Severity : minor.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pkturnkey

    r2419 r2420  
    4747  -h | --help          Prints this message then exits. 
    4848   
     49  -d | --dryrun        Doesn't modify the database at all, but instead prints 
     50                       what it would do. 
     51                        
    4952  -u | --uidmin uid    Only adds users whose uid is greater than or equal to 
    5053                       uid. You can pass an username there as well, and its 
     
    8790        return [entry[0] for entry in pwd.getpwall() if uidmin <= entry[2] <= uidmax] 
    8891         
    89     def createPrinters(self, printers) :     
     92    def runCommand(self, command, dryrun) :     
     93        """Launches an external command.""" 
     94        if dryrun : 
     95            self.printInfo("%s" % command) 
     96        else :     
     97            self.logdebug("%s" % command) 
     98            os.system(command) 
     99             
     100    def createPrinters(self, printers, dryrun=0) :     
    90101        """Creates all printers in PyKota's database.""" 
    91         needswarning = [p[0] for p in printers if p[1].find("cupspykota") == -1] 
    92         command = "pkprinters --add %s" % " ".join(['"%s"' % p[0] for p in printers]) 
    93         self.logdebug("Launching : %s" % command) 
    94         os.system(command) 
    95          
    96     def createUsers(self, users) :     
     102        if printers : 
     103            needswarning = [p[0] for p in printers if p[1].find("cupspykota") == -1] 
     104            command = "pkprinters --add %s" % " ".join(['"%s"' % p[0] for p in printers]) 
     105            self.runCommand(command, dryrun) 
     106            for p in needswarning : 
     107                self.printInfo(_("Printer %s is not managed by PyKota yet. Please modify printers.conf and restart CUPS.") % p, "warn") 
     108         
     109    def createUsers(self, users, dryrun=0) : 
    97110        """Creates all users in PyKota's database.""" 
    98         command = "edpykota --add --noquota %s" % " ".join(['"%s"' % u for u in users]) 
    99         self.logdebug("Launching : %s" % command) 
    100         os.system(command) 
     111        if users : 
     112            command = "edpykota --add --noquota %s" % " ".join(['"%s"' % u for u in users]) 
     113            self.runCommand(command, dryrun) 
    101114         
    102115    def main(self, names, options) : 
     
    137150        printers = self.listPrinters()                     
    138151         
    139         print "Please be patient...", 
    140         sys.stdout.flush() 
    141         self.createPrinters(printers) 
    142         self.createUsers(users) 
    143         print 
     152        print "Please be patient..." 
     153         
     154        if printers : 
     155            self.createPrinters(printers, options["dryrun"]) 
     156            self.createUsers(users, options["dryrun"]) 
     157         
    144158        print "Database initialized." 
    145159                     
     
    148162    retcode = 0 
    149163    try : 
    150         short_options = "hvu:U:" 
    151         long_options = ["help", "version", "uidmin=", "uidmax="] 
     164        short_options = "hvdu:U:" 
     165        long_options = ["help", "version", "dryrun", "uidmin=", "uidmax="] 
    152166         
    153167        # Initializes the command line tool 
     
    164178        options["help"] = options["h"] or options["help"] 
    165179        options["version"] = options["v"] or options["version"] 
     180        options["dryrun"] = options["d"] or options["dryrun"] 
    166181        options["uidmin"] = options["u"] or options["uidmin"] 
    167182        options["uidmax"] = options["U"] or options["uidmax"]