-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

The attached patch add a pokernetwork twisted plugin, and update init
and packaging scripts.

It allows the following commandline interactions with twistd.
jpoker:/usr/src/poker-network# twistd pokerserver --help
/usr/lib/python2.5/site-packages/twisted/plugins/twisted_web2.py:22:
Usage: twistd [options] pokerserver [options]
Options:
  -c, --config=  The configuration file to use. [default:
/etc/poker-network/poker.server.xml]
        --version
      --help     Display this help and exit.
jpoker:/usr/src/poker-network# grep tcp /etc/poker-network/poker.server2.xml
  <listen tcp="20000" tcp_ssl="19381" http="19382" http_ssl="19383"
rest="19384" rest_ssl="19385" />
jpoker:/usr/src/poker-network# twistd -no pokerserver --config
/etc/poker-network/poker.server2.xml
Removing stale pidfile /usr/src/poker-network/twistd.pid
2008-10-29 14:51:41+0000 [-] Log opened.
2008-10-29 14:51:41+0000 [-] twistd 8.1.0 (/usr/bin/python 2.5.2)
starting up
2008-10-29 14:51:41+0000 [-] reactor class: <class
'twisted.internet.selectreactor.SelectReactor'>
2008-10-29 14:51:41+0000 [-]
pokernetwork.pokerservice.PokerFactoryFromPokerService starting on 20000
2008-10-29 14:51:41+0000 [-] Starting factory
<pokernetwork.pokerservice.PokerFactoryFromPokerService instance at
0xb6be8f0c>

Feel free to review and apply it to poker-network trunk


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEUEARECAAYFAkkIeXMACgkQZmEdV9SHoe6RzQCfWBhCTeo3O+CfqrYssIJOL4L+
RXsAmJFFQGYPed/KK1OYdmjbRbwX/s8=
=Mqlu
-----END PGP SIGNATURE-----
Index: debian/python-poker-network.init
===================================================================
--- debian/python-poker-network.init    (revision 4779)
+++ debian/python-poker-network.init    (working copy)
@@ -63,13 +63,8 @@
 
 serverpidfile=/var/run/poker-network-server.pid
 serverlogfile=/var/log/poker-network-server.log
-serverscript=/usr/lib/python/site-packages/pokernetwork/pokerserver.py
-if ! test -f $serverscript ; then
-    
serverscript=/usr/share/pycentral/python-poker-network/site-packages/pokernetwork/pokerserver.py
-fi
-if ! test -f $serverscript ; then
-    serverscript=`pycentral pycentraldir 
python-poker-network`/pokernetwork/pokerserver.py
-fi
+serverplugin=pokerserver
+#serverconfig=/etc/poker-network/poker.server2.xml
 
 botpidfile=/var/run/poker-network-bot.pid
 botlogfile=/var/log/poker-network-bot.log
@@ -97,9 +92,10 @@
            exit 0;
        fi
        ${python} ${twistd} \
-           --pidfile=${serverpidfile} --python ${serverscript} \
+           --pidfile=${serverpidfile} \
            --logfile=${serverlogfile} --quiet ${more_args} \
-           --reactor=${reactor}
+           --reactor=${reactor} \
+           ${serverplugin} #--config=${serverconfig}
         if $RUN_BOTS ; then
            ${python} ${twistd} \
                --pidfile=${botpidfile} --python ${botscript} \
Index: debian/python-poker-network.install
===================================================================
--- debian/python-poker-network.install (revision 4779)
+++ debian/python-poker-network.install (working copy)
@@ -1,5 +1,6 @@
 debian/tmp/usr/lib/python???/site-packages/pokernetwork
 debian/tmp/usr/lib/python???/site-packages/pokerui
+debian/tmp/usr/lib/python???/site-packages/twisted/plugins
 debian/tmp/usr/share/poker-network/*.sql
 debian/tmp/usr/sbin
 debian/tmp/usr/share/poker-network/conf/poker.server.xml
Index: pokernetwork/pokerserver.py
===================================================================
--- pokernetwork/pokerserver.py (revision 4779)
+++ pokernetwork/pokerserver.py (working copy)
@@ -47,32 +47,19 @@
         
 
 from twisted.application import internet, service, app
-from twisted.internet import pollreactor
-if platform.system() != "Windows":
-        if not sys.modules.has_key('twisted.internet.reactor'):
-                print "installing poll reactor"
-                pollreactor.install()
-        else:
-                print "poll reactor already installed"
-from twisted.internet import reactor
 from twisted.web import resource,server
 
 from pokernetwork.pokernetworkconfig import Config
 from pokernetwork.pokerservice import PokerTree, PokerRestTree, PokerService, 
IPokerFactory, SSLContextFactory
 from pokernetwork.pokersite import PokerSite
 
-def makeApplication(argv):
-    default_path = "/etc/poker-network" + sys.version[:3] + "/poker.server.xml"
-    if not exists(default_path):
-        default_path = "/etc/poker-network/poker.server.xml"
-    configuration = argv[-1][-4:] == ".xml" and argv[-1] or default_path
+def makeService(configuration):
     settings = Config([''])
     settings.load(configuration)
     if not settings.header:
         sys.exit(1)
 
-    application = service.Application('poker')
-    serviceCollection = service.IServiceCollection(application)
+    serviceCollection = service.MultiService()
     poker_service = PokerService(settings)
     poker_service.setServiceParent(serviceCollection)
 
@@ -119,12 +106,30 @@
     if HAS_OPENSSL and http_ssl_port:
             internet.SSLServer(http_ssl_port, http_site, 
SSLContextFactory(settings)
                                ).setServiceParent(serviceCollection)
+    return serviceCollection
+
+def makeApplication(argv):
+    default_path = "/etc/poker-network" + sys.version[:3] + "/poker.server.xml"
+    if not exists(default_path):
+        default_path = "/etc/poker-network/poker.server.xml"
+    configuration = argv[-1][-4:] == ".xml" and argv[-1] or default_path    
+    application = service.Application('poker')
+    serviceCollection = service.IServiceCollection(application)
+    poker_service = makeService(configuration)
+    poker_service.setServiceParent(serviceCollection)
     return application
-        
-application = makeApplication(sys.argv)
 
 def run():
+    if platform.system() != "Windows":
+        if not sys.modules.has_key('twisted.internet.reactor'):
+                print "installing poll reactor"
+                pollreactor.install()
+        else:
+                print "poll reactor already installed"
+    from twisted.internet import reactor
+    application = makeApplication(sys.argv)
     app.startApplication(application, None)
+    from twisted.internet import pollreactor
     reactor.run()
 
 if __name__ == '__main__':
Index: twisted/plugins/pokernetwork_plugin.py
===================================================================
--- twisted/plugins/pokernetwork_plugin.py      (revision 0)
+++ twisted/plugins/pokernetwork_plugin.py      (revision 0)
@@ -0,0 +1,49 @@
+#
+# -*- coding: iso-8859-1 -*-
+#
+# Copyright (C) 2008 Johan Euphrosine <[EMAIL PROTECTED]>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
+#
+# Authors:
+#  Johan Euphrosine <[EMAIL PROTECTED]>
+#
+
+from zope.interface import implements
+
+from twisted.python import usage
+from twisted.plugin import IPlugin
+from twisted.application.service import IServiceMaker
+from twisted.application import internet
+
+from pokernetwork import pokerserver
+
+class Options(usage.Options):
+    optParameters = [["config", "c", "/etc/poker-network/poker.server.xml", 
"The configuration file to use."]]
+
+class PokerNetworkServiceMaker(object):
+    implements(IServiceMaker, IPlugin)
+    tapname = "pokerserver"
+    description = "A pokerserver twisted multi-service."
+    options = Options
+
+    def makeService(self, options):
+        return pokerserver.makeService(options["config"])
+
+# Now construct an object which *provides* the relevant interfaces
+# The name of this variable is irrelevant, as long as there is *some*
+# name bound to a provider of IPlugin and IServiceMaker.
+
+serviceMaker = PokerNetworkServiceMaker()
Index: Makefile.am
===================================================================
--- Makefile.am (revision 4779)
+++ Makefile.am (working copy)
@@ -126,6 +126,10 @@
        pokerui/pokeranimation.py \
        pokerui/pokerchat.py
 
+twistedpluginsdir = ${pythondir}/twisted/plugins/
+twistedplugins_PYTHON = \
+       twisted/plugins/pokernetwork_plugin.py
+
 pokerdbdir=${pkgdatadir}
 dist_pokerdb_DATA = \
        database/schema.sql \
_______________________________________________
Pokersource-users mailing list
[email protected]
https://mail.gna.org/listinfo/pokersource-users

Reply via email to