Index: pykota/trunk/bin/pkturnkey
===================================================================
--- pykota/trunk/bin/pkturnkey (revision 2466)
+++ pykota/trunk/bin/pkturnkey (revision 2467)
@@ -29,4 +29,5 @@
 import pwd
 import grp
+import socket
 
 from pykota.tool import Tool, PyKotaToolError, crashed, N_
@@ -47,4 +48,6 @@
   -v | --version       Prints pkturnkey version number then exits.
   -h | --help          Prints this message then exits.
+  
+  -c | --doconf        Give hints about what to put into pykota.conf
   
   -d | --dousers       Manages users accounts as well.
@@ -170,6 +173,7 @@
         if users :
             printersnames = [p[0] for p in printers]
-            command = "edpykota --add --noquota --printer %s %s" % (",".join(['"%s"' % p for p in printersnames]), \
-                                                                    " ".join(['"%s"' % u for u in users]))
+            command = "edpykota --add --noquota --printer %s %s" \
+                          % (",".join(['"%s"' % p for p in printersnames]), \
+                             " ".join(['"%s"' % u for u in users]))
             self.runCommand(command, dryrun)
             
@@ -178,6 +182,7 @@
         if groups :
             printersnames = [p[0] for p in printers]
-            commands = ["edpykota --add --groups --noquota --printer %s %s" % (",".join(['"%s"' % p for p in printersnames]), \
-                                                                               " ".join(['"%s"' % g for g in groups.keys()]))]
+            commands = ["edpykota --add --groups --noquota --printer %s %s" \
+                            % (",".join(['"%s"' % p for p in printersnames]), \
+                               " ".join(['"%s"' % g for g in groups.keys()]))]
             revmembership = {}
             for (groupname, usernames) in groups.items() :
@@ -185,12 +190,97 @@
                     revmembership.setdefault(username, []).append(groupname)
             for (username, groupnames) in revmembership.items() :        
-                commands.append('edpykota --ingroups %s "%s"' % (",".join(['"%s"' % g for g in groupnames]), username))
+                commands.append('edpykota --ingroups %s "%s"' \
+                    % (",".join(['"%s"' % g for g in groupnames]), username))
             for command in commands :
                 self.runCommand(command, dryrun)
+        
+    def hintConfig(self, printers) :    
+        """Gives some hints about what to put into pykota.conf"""
+        if not printers :
+            return
+        sys.stderr.flush() # ensure outputs don't mix    
+        print     
+        print "--- CUT ---"
+        print "# Here are some lines that we suggest you add at the end"
+        print "# of the pykota.conf file. These lines gives possible"
+        print "# values for the way print jobs' size will be computed."
+        print "# NB : it is possible that a manual configuration gives"
+        print "# better results for you. As always, your mileage may vary."
+        print "#"
+        for (name, uri) in printers :
+            print "[%s]" % name
+            accounter = "software()"
+            try :
+                uri = uri.split("cupspykota:", 2)[-1]
+            except (ValueError, IndexError) :    
+                pass
+            else :    
+                while uri and uri.startswith("/") :
+                    uri = uri[1:]
+                try :
+                    (backend, destination) = uri.split(":", 1) 
+                    if backend not in ("ipp", "http", "https", "lpd", "socket") :
+                        raise ValueError
+                except ValueError :    
+                    pass
+                else :        
+                    while destination.startswith("/") :
+                        destination = destination[1:]
+                    checkauth = destination.split("@", 1)    
+                    if len(checkauth) == 2 :
+                        destination = checkauth[1]
+                    parts = destination.split("/")[0].split(":")
+                    if len(parts) == 2 :
+                        (hostname, port) = parts
+                        try :
+                            port = int(port)
+                        except ValueError :
+                            port = 9100
+                    else :    
+                        (hostname, port) = parts[0], 9100
+                        
+                    # check udp/161 (SNMP)
+                    # TODO : this doesn't work as expected if the host
+                    # TODO : is down, I must find another solution.
+                    trysnmp = 0
+                    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+                    try :
+                        s.connect((hostname, socket.getservbyname("snmp", "udp")))
+                        for i in range(2) :
+                            s.send("")
+                    except :
+                        pass
+                    else :    
+                        trysnmp = 1    
+                    s.close()
+                    
+                    # check tcp/9100
+                    trypjl = 0
+                    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+                    try :
+                        s.connect((hostname, port))
+                    except :    
+                        pass
+                    else :    
+                        trypjl = 1
+                    s.close()
+                        
+                    if trysnmp :
+                        accounter = "hardware(snmp)"
+                    elif trypjl :    
+                        if port != 9100 :
+                            accounter = "hardware(pjl:%s)" % port
+                        else :    
+                            accounter = "hardware(pjl)" % port
+                    
+            print "accounter : %s" % accounter
+            print
+        print "--- CUT ---"
         
     def main(self, names, options) :
         """Intializes PyKota's database."""
         if not self.config.isAdmin :
-            raise PyKotaToolError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command."))
+            raise PyKotaToolError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0],\
+                                   _("You're not allowed to use this command."))
             
         if not names :
@@ -215,5 +305,6 @@
                         uidmin = pwd.getpwnam(options["uidmin"])[2]
                     except KeyError, msg :    
-                        raise PyKotaToolError, _("Unknown username %s : %s") % (options["uidmin"], msg)
+                        raise PyKotaToolError, _("Unknown username %s : %s") \
+                                                   % (options["uidmin"], msg)
                         
             if not options["uidmax"] :    
@@ -226,5 +317,6 @@
                         uidmax = pwd.getpwnam(options["uidmax"])[2]
                     except KeyError, msg :    
-                        raise PyKotaToolError, _("Unknown username %s : %s") % (options["uidmax"], msg)
+                        raise PyKotaToolError, _("Unknown username %s : %s") \
+                                                   % (options["uidmax"], msg)
             
             if uidmin > uidmax :            
@@ -245,5 +337,6 @@
                         gidmin = grp.getgrnam(options["gidmin"])[2]
                     except KeyError, msg :    
-                        raise PyKotaToolError, _("Unknown groupname %s : %s") % (options["gidmin"], msg)
+                        raise PyKotaToolError, _("Unknown groupname %s : %s") \
+                                                   % (options["gidmin"], msg)
                         
             if not options["gidmax"] :    
@@ -256,5 +349,6 @@
                         gidmax = grp.getgrnam(options["gidmax"])[2]
                     except KeyError, msg :    
-                        raise PyKotaToolError, _("Unknown groupname %s : %s") % (options["gidmax"], msg)
+                        raise PyKotaToolError, _("Unknown groupname %s : %s") \
+                                                   % (options["gidmax"], msg)
             
             if gidmin > gidmax :            
@@ -278,4 +372,7 @@
         else :    
             self.printInfo(_("Database initialized !"))
+       
+        if options["doconf"] :    
+            self.hintConfig(printers)
                     
                      
@@ -283,8 +380,8 @@
     retcode = 0
     try :
-        short_options = "hvdDefu:U:g:G:"
+        short_options = "hvdDefu:U:g:G:c"
         long_options = ["help", "version", "dousers", "dogroups", \
                         "emptygroups", "force", "uidmin=", "uidmax=", \
-                        "gidmin=", "gidmax="]
+                        "gidmin=", "gidmax=", "doconf"]
         
         # Initializes the command line tool
@@ -309,4 +406,5 @@
         options["gidmin"] = options["g"] or options["gidmin"]
         options["gidmax"] = options["G"] or options["gidmax"]
+        options["doconf"] = options["c"] or options["doconf"]
         
         if options["uidmin"] or options["uidmax"] :
Index: pykota/trunk/man/sv_SE/pkturnkey.1
===================================================================
--- pykota/trunk/man/sv_SE/pkturnkey.1 (revision 2466)
+++ pykota/trunk/man/sv_SE/pkturnkey.1 (revision 2467)
@@ -22,4 +22,7 @@
 \fB\-h\fR | \fB\-\-help\fR
 Prints this message then exits.
+.TP
+\fB\-c\fR | \fB\-\-doconf\fR
+Give hints about what to put into pykota.conf
 .TP
 \fB\-d\fR | \fB\-\-dousers\fR
Index: pykota/trunk/man/pt/pkturnkey.1
===================================================================
--- pykota/trunk/man/pt/pkturnkey.1 (revision 2466)
+++ pykota/trunk/man/pt/pkturnkey.1 (revision 2467)
@@ -22,4 +22,7 @@
 \fB\-h\fR | \fB\-\-help\fR
 Prints this message then exits.
+.TP
+\fB\-c\fR | \fB\-\-doconf\fR
+Give hints about what to put into pykota.conf
 .TP
 \fB\-d\fR | \fB\-\-dousers\fR
Index: pykota/trunk/man/tr/pkturnkey.1
===================================================================
--- pykota/trunk/man/tr/pkturnkey.1 (revision 2466)
+++ pykota/trunk/man/tr/pkturnkey.1 (revision 2467)
@@ -22,4 +22,7 @@
 \fB\-h\fR | \fB\-\-help\fR
 Prints this message then exits.
+.TP
+\fB\-c\fR | \fB\-\-doconf\fR
+Give hints about what to put into pykota.conf
 .TP
 \fB\-d\fR | \fB\-\-dousers\fR
Index: pykota/trunk/man/el_GR/pkturnkey.1
===================================================================
--- pykota/trunk/man/el_GR/pkturnkey.1 (revision 2466)
+++ pykota/trunk/man/el_GR/pkturnkey.1 (revision 2467)
@@ -22,4 +22,7 @@
 \fB\-h\fR | \fB\-\-help\fR
 Prints this message then exits.
+.TP
+\fB\-c\fR | \fB\-\-doconf\fR
+Give hints about what to put into pykota.conf
 .TP
 \fB\-d\fR | \fB\-\-dousers\fR
Index: pykota/trunk/man/de/pkturnkey.1
===================================================================
--- pykota/trunk/man/de/pkturnkey.1 (revision 2466)
+++ pykota/trunk/man/de/pkturnkey.1 (revision 2467)
@@ -22,4 +22,7 @@
 \fB\-h\fR | \fB\-\-help\fR
 Prints this message then exits.
+.TP
+\fB\-c\fR | \fB\-\-doconf\fR
+Give hints about what to put into pykota.conf
 .TP
 \fB\-d\fR | \fB\-\-dousers\fR
Index: pykota/trunk/man/nb_NO/pkturnkey.1
===================================================================
--- pykota/trunk/man/nb_NO/pkturnkey.1 (revision 2466)
+++ pykota/trunk/man/nb_NO/pkturnkey.1 (revision 2467)
@@ -22,4 +22,7 @@
 \fB\-h\fR | \fB\-\-help\fR
 Prints this message then exits.
+.TP
+\fB\-c\fR | \fB\-\-doconf\fR
+Give hints about what to put into pykota.conf
 .TP
 \fB\-d\fR | \fB\-\-dousers\fR
Index: pykota/trunk/man/pkturnkey.1
===================================================================
--- pykota/trunk/man/pkturnkey.1 (revision 2466)
+++ pykota/trunk/man/pkturnkey.1 (revision 2467)
@@ -22,4 +22,7 @@
 \fB\-h\fR | \fB\-\-help\fR
 Prints this message then exits.
+.TP
+\fB\-c\fR | \fB\-\-doconf\fR
+Give hints about what to put into pykota.conf
 .TP
 \fB\-d\fR | \fB\-\-dousers\fR
Index: pykota/trunk/man/zh_TW/pkturnkey.1
===================================================================
--- pykota/trunk/man/zh_TW/pkturnkey.1 (revision 2466)
+++ pykota/trunk/man/zh_TW/pkturnkey.1 (revision 2467)
@@ -22,4 +22,7 @@
 \fB\-h\fR | \fB\-\-help\fR
 Prints this message then exits.
+.TP
+\fB\-c\fR | \fB\-\-doconf\fR
+Give hints about what to put into pykota.conf
 .TP
 \fB\-d\fR | \fB\-\-dousers\fR
Index: pykota/trunk/man/pt_BR/pkturnkey.1
===================================================================
--- pykota/trunk/man/pt_BR/pkturnkey.1 (revision 2466)
+++ pykota/trunk/man/pt_BR/pkturnkey.1 (revision 2467)
@@ -22,4 +22,7 @@
 \fB\-h\fR | \fB\-\-help\fR
 Prints this message then exits.
+.TP
+\fB\-c\fR | \fB\-\-doconf\fR
+Give hints about what to put into pykota.conf
 .TP
 \fB\-d\fR | \fB\-\-dousers\fR
Index: pykota/trunk/man/fr/pkturnkey.1
===================================================================
--- pykota/trunk/man/fr/pkturnkey.1 (revision 2466)
+++ pykota/trunk/man/fr/pkturnkey.1 (revision 2467)
@@ -22,4 +22,7 @@
 \fB\-h\fR | \fB\-\-help\fR
 Prints this message then exits.
+.TP
+\fB\-c\fR | \fB\-\-doconf\fR
+Give hints about what to put into pykota.conf
 .TP
 \fB\-d\fR | \fB\-\-dousers\fR
Index: pykota/trunk/man/es/pkturnkey.1
===================================================================
--- pykota/trunk/man/es/pkturnkey.1 (revision 2466)
+++ pykota/trunk/man/es/pkturnkey.1 (revision 2467)
@@ -22,4 +22,7 @@
 \fB\-h\fR | \fB\-\-help\fR
 Prints this message then exits.
+.TP
+\fB\-c\fR | \fB\-\-doconf\fR
+Give hints about what to put into pykota.conf
 .TP
 \fB\-d\fR | \fB\-\-dousers\fR
Index: pykota/trunk/man/th/pkturnkey.1
===================================================================
--- pykota/trunk/man/th/pkturnkey.1 (revision 2466)
+++ pykota/trunk/man/th/pkturnkey.1 (revision 2467)
@@ -22,4 +22,7 @@
 \fB\-h\fR | \fB\-\-help\fR
 Prints this message then exits.
+.TP
+\fB\-c\fR | \fB\-\-doconf\fR
+Give hints about what to put into pykota.conf
 .TP
 \fB\-d\fR | \fB\-\-dousers\fR
Index: pykota/trunk/man/it/pkturnkey.1
===================================================================
--- pykota/trunk/man/it/pkturnkey.1 (revision 2466)
+++ pykota/trunk/man/it/pkturnkey.1 (revision 2467)
@@ -22,4 +22,7 @@
 \fB\-h\fR | \fB\-\-help\fR
 Prints this message then exits.
+.TP
+\fB\-c\fR | \fB\-\-doconf\fR
+Give hints about what to put into pykota.conf
 .TP
 \fB\-d\fR | \fB\-\-dousers\fR
Index: pykota/trunk/NEWS
===================================================================
--- pykota/trunk/NEWS (revision 2466)
+++ pykota/trunk/NEWS (revision 2467)
@@ -31,4 +31,7 @@
           arguments on pkturnkey's command line.
           
+        - pkturnkey now supersedes pkhint with the help of the -c | --doconf
+          command line option.   
+          
     - 1.23alpha30 :
     
