Index: pykoticon/trunk/bin/pykoticon
===================================================================
--- pykoticon/trunk/bin/pykoticon (revision 122)
+++ pykoticon/trunk/bin/pykoticon (revision 123)
@@ -41,5 +41,9 @@
 import xmlrpclib
 import SimpleXMLRPCServer
-
+try :
+    import optparse
+except ImportError :    
+    sys.stderr.write("You need Python v2.3 or higher for PyKotIcon to work.\nAborted.\n")
+    sys.exit(-1)
 
 if sys.platform == "win32" :
@@ -88,12 +92,12 @@
     """My own server class."""
     allow_reuse_address = True
-    def __init__(self, frame, printserver, localport, debug=False) :
+    def __init__(self, frame, options, arguments) :
         SimpleXMLRPCServer.SimpleXMLRPCServer.__init__(self, \
-                                                       ('0.0.0.0', localport), \
+                                                       ('0.0.0.0', options.port), \
                                                        SimpleXMLRPCServer.SimpleXMLRPCRequestHandler, \
-                                                       debug)
-        self.printServer = printserver
+                                                       options.debug)
         self.frame = frame
-        self.debug = debug
+        self.debug = options.debug
+        self.printServers = [ socket.gethostbyname(arg) for arg in arguments ]
         loop = threading.Thread(target=self.mainloop)
         loop.start()
@@ -145,5 +149,5 @@
         """Ensures that requests which don't come from the print server are rejected."""
         (client, port) = client_address
-        if socket.gethostbyname(self.printServer) == client :
+        if client in self.printServers :
             self.logDebug("%s accepted." % client)
             return True
@@ -329,10 +333,10 @@
             pass
         
-    def postInit(self, charset, printserver, localport) :    
+    def postInit(self, charset, options, arguments) :    
         """Starts the XML-RPC server."""
         self.quitEvent = threading.Event()
         self.charset = charset
-        self.port = localport
-        self.server = MyXMLRPCServer(self, printserver, localport)
+        self.port = options.port
+        self.server = MyXMLRPCServer(self, options, arguments)
         
     def UTF8ToUserCharset(self, text) :
@@ -379,10 +383,10 @@
         return True
         
-    def postInit(self, charset, printserver, localport) :    
+    def postInit(self, charset, options, arguments) :    
         """Continues processing."""
-        self.frame.postInit(charset, printserver, localport)
-        
-        
-def main(printserver, localport):
+        self.frame.postInit(charset, options, arguments)
+        
+        
+def main() :
     """Program's entry point."""
     try :
@@ -412,11 +416,29 @@
     charset = os.environ.get("CHARSET") or localecharset or "ISO-8859-15"
     
-    app = PyKotIconApp()
-    try :
-        localport = int(localport)    
-    except (TypeError, ValueError) :    
-        raise ValueError, "Invalid TCP port parameter %s\n" % localport
-    app.postInit(charset, printserver, localport)
-    app.MainLoop()
+    parser = optparse.OptionParser(usage="usage : pykoticon [options] server1 [server2 ...]")
+    parser.add_option("-v", "--version", 
+                            action="store_true", 
+                            dest="version",
+                            help=_("show PyKotIcon's version number and exit"))
+    parser.add_option("-d", "--debug", 
+                            action="store_true", 
+                            dest="debug",
+                            help=_("activate debug mode"))
+    parser.add_option("-p", "--port", 
+                            type="int", 
+                            default=7654, 
+                            dest="port",
+                            help=_("the TCP port PyKotIcon will listen to, default is %default"))
+    parser.add_option("-q", "--allowquit", 
+                            action="store_true", 
+                            dest="allowquit",
+                            help=_("allow the end user to close the application"))
+    (options, arguments) = parser.parse_args()
+    if options.version :
+        print "PyKotIcon v%(__version__)s" % globals()
+    else :
+        app = PyKotIconApp()
+        app.postInit(charset, options, arguments)
+        app.MainLoop()
     
     
@@ -433,12 +455,4 @@
     
 if __name__ == '__main__':
-    if len(sys.argv) >= 2 :
-        arg = sys.argv[1]
-        if arg in ("-v", "--version") :    
-            print __version__
-        elif arg in ("-h", "--help") :    
-            sys.stderr.write("usage : pykoticon  pykota_server_hostname_or_ip_address  localTCPPort\n")
-        else :
-            main(*sys.argv[1:3])
-    else :    
-        sys.stderr.write("usage : pykoticon  pykota_server_hostname_or_ip_address  localTCPPort\n")
+    main()
+    
