Fix references to contrib and ev. Allows Ampoule tests to run. They're severely broken, however.

This commit is contained in:
Jonathan Piacenti 2015-02-22 18:24:54 -06:00 committed by Griatch
parent c03bac5efd
commit 65adb0982b
18 changed files with 80 additions and 51 deletions

View file

@ -136,7 +136,7 @@ class CmdPy(MuxCommand):
inherits_from(obj, parent) : check object inheritance
You can explore The evennia API from inside the game by calling
ev.help(), ev.managers.help() etc.
evennia.help(), evennia.managers.help() etc.
{rNote: In the wrong hands this command is a severe security risk.
It should only be accessible by trusted server admins/superusers.{n

View file

@ -121,7 +121,7 @@ class MsgManager(models.Manager):
get_messages_by_receiver
get_messages_by_channel
text_search
message_search (equivalent to ev.search_messages)
message_search (equivalent to evennia.search_messages)
"""
def identify_object(self, obj):
@ -256,7 +256,7 @@ class ChannelDBManager(TypedObjectManager):
get_all_channels
get_channel(channel)
get_subscriptions(player)
channel_search (equivalent to ev.search_channel)
channel_search (equivalent to evennia.search_channel)
"""
@returns_typeclass_list

View file

@ -33,7 +33,7 @@ from evennia import Command, CmdSet
from evennia import syscmdkeys
from evennia.server.models import ServerConfig
from contrib.menusystem import MenuNode, MenuTree
from evennia.contrib.menusystem import MenuNode, MenuTree
CMD_LOGINSTART = syscmdkeys.CMD_LOGINSTART
CMD_NOINPUT = syscmdkeys.CMD_NOINPUT

View file

@ -281,7 +281,7 @@ class MenuNode(object):
code - functional code. Deprecated. This will be executed just before this
node is loaded (i.e. as soon after it's been selected from
another node). self.caller is available to call from this
code block, as well as ev.
code block, as well as the evennia flat API.
callback - function callback. This will be called as callback(currentnode) just
before this node is loaded (i.e. as soon as possible as it's
been selected from another node). currentnode.caller is available.

View file

@ -5,10 +5,10 @@ Inherit from this to define a new type of subprocess.
"""
from twisted.python import log
from twisted.internet import error
from twisted.protocols import amp
from contrib.procpools.ampoule.commands import Echo, Shutdown, Ping
from evennia.contrib.procpools.ampoule.commands import Echo, Shutdown, Ping
class AMPChild(amp.AMP):
def __init__(self):

View file

@ -11,7 +11,7 @@ from twisted.protocols import amp
from twisted.python import runtime
from twisted.python.compat import set
from contrib.procpools.ampoule import iampoule
from evennia.contrib.procpools.ampoule import iampoule
gen = itertools.count()
@ -193,7 +193,7 @@ class ProcessStarter(object):
self.uid = uid
self.gid = gid
self.usePTY = usePTY
self.packages = ("ampoule",) + packages
self.packages = ("evennia.contrib.procpools.ampoule",) + packages
self.packages = packages
self.childReactor = childReactor

View file

@ -11,7 +11,7 @@ pop = heapq.heappop
from twisted.internet import defer, task, error
from twisted.python import log, failure
from contrib.procpools.ampoule import commands, main
from evennia.contrib.procpools.ampoule import commands, main
try:
DIE = signal.SIGKILL
@ -19,6 +19,7 @@ except AttributeError:
# Windows doesn't have SIGKILL, let's just use SIGTERM then
DIE = signal.SIGTERM
class ProcessPool(object):
"""
This class generalizes the functionality of a pool of
@ -62,11 +63,11 @@ class ProcessPool(object):
self.starter = starter
self.ampChildArgs = tuple(ampChildArgs)
if starter is None:
self.starter = main.ProcessStarter(packages=("twisted", "ampoule"))
self.starter = main.ProcessStarter(packages=("twisted",))
self.ampParent = ampParent
self.ampChild = ampChild
if ampChild is None:
from contrib.procpools.ampoule.child import AMPChild
from evennia.contrib.procpools.ampoule.child import AMPChild
self.ampChild = AMPChild
self.min = min
self.max = max
@ -396,6 +397,7 @@ class ProcessPool(object):
pp = None
def deferToAMPProcess(command, **kwargs):
"""
Helper function that sends a command to the default process pool

View file

@ -9,8 +9,8 @@ def makeService(options):
"""
ms = service.MultiService()
from contrib.procpools.ampoule.pool import ProcessPool
from contrib.procpools.ampoule.main import ProcessStarter
from evennia.contrib.procpools.ampoule.pool import ProcessPool
from evennia.contrib.procpools.ampoule.main import ProcessStarter
name = options['name']
ampport = options['ampport']
ampinterface = options['ampinterface']
@ -23,7 +23,7 @@ def makeService(options):
childReactor = options['reactor']
timeout = options['timeout']
starter = ProcessStarter(packages=("twisted", "ampoule"), childReactor=childReactor)
starter = ProcessStarter(packages=("twisted",), childReactor=childReactor)
pp = ProcessPool(child, parent, min, max, name, maxIdle, recycle, starter, timeout)
svc = AMPouleService(pp, child, ampport, ampinterface)
svc.setServiceParent(ms)
@ -43,7 +43,7 @@ class AMPouleService(service.Service):
Before reactor.run() is called we setup the system.
"""
service.Service.startService(self)
from contrib.procpools.ampoule import rpool
from evennia.contrib.procpools.ampoule import rpool
from twisted.internet import reactor
try:

View file

@ -1,23 +1,25 @@
from signal import SIGHUP
import math
import os
import os.path
from cStringIO import StringIO as sio
import tempfile
from twisted.internet import error, defer, reactor
from twisted.python import failure, reflect
from twisted.python import failure
from twisted.trial import unittest
from twisted.protocols import amp
from contrib.procpools.ampoule import main, child, commands, pool
from evennia.contrib.procpools.ampoule import main, child, commands, pool
class ShouldntHaveBeenCalled(Exception):
pass
def _raise(_):
raise ShouldntHaveBeenCalled(_)
class _FakeT(object):
closeStdinCalled = False
def __init__(self, s):
@ -29,6 +31,7 @@ class _FakeT(object):
def write(self, data):
self.s.write(data)
class FakeAMP(object):
connector = None
reason = None
@ -48,38 +51,47 @@ class FakeAMP(object):
def dataReceived(self, data):
self.s.write(data)
class Ping(amp.Command):
arguments = [('data', amp.String())]
response = [('response', amp.String())]
class Pong(amp.Command):
arguments = [('data', amp.String())]
response = [('response', amp.String())]
class Pid(amp.Command):
response = [('pid', amp.Integer())]
class Reactor(amp.Command):
response = [('classname', amp.String())]
class NoResponse(amp.Command):
arguments = [('arg', amp.String())]
requiresAnswer = False
class GetResponse(amp.Command):
response = [("response", amp.String())]
class Child(child.AMPChild):
def ping(self, data):
return self.callRemote(Pong, data=data)
Ping.responder(ping)
class PidChild(child.AMPChild):
def pid(self):
import os
return {'pid': os.getpid()}
Pid.responder(pid)
class NoResponseChild(child.AMPChild):
_set = False
def noresponse(self, arg):
@ -91,33 +103,41 @@ class NoResponseChild(child.AMPChild):
return {"response": self._set}
GetResponse.responder(getresponse)
class ReactorChild(child.AMPChild):
def reactor(self):
from twisted.internet import reactor
return {'classname': reactor.__class__.__name__}
Reactor.responder(reactor)
class First(amp.Command):
arguments = [('data', amp.String())]
response = [('response', amp.String())]
class Second(amp.Command):
pass
class WaitingChild(child.AMPChild):
deferred = None
def first(self, data):
self.deferred = defer.Deferred()
return self.deferred.addCallback(lambda _: {'response': data})
First.responder(first)
def second(self):
self.deferred.callback('')
return {}
Second.responder(second)
class Die(amp.Command):
pass
class BadChild(child.AMPChild):
def die(self):
self.shutdown = False
@ -235,7 +255,7 @@ main(sys.argv[1])
"""
starter = main.ProcessStarter(bootstrap=BOOT,
args=(STRING,),
packages=("twisted", "ampoule"))
packages=("twisted",))
amp, finished = starter.startPythonProcess(main.AMPConnector(a))
def _eb(reason):
@ -257,7 +277,7 @@ def main(arg):
raise Exception(arg)
main(sys.argv[1])
"""
starter = main.ProcessStarter(bootstrap=BOOT, args=(STRING,), packages=("twisted", "ampoule"))
starter = main.ProcessStarter(bootstrap=BOOT, args=(STRING,), packages=("twisted",))
ready, finished = starter.startPythonProcess(main.AMPConnector(a), "I'll be ignored")
self.assertFailure(finished, error.ProcessTerminated)
@ -279,9 +299,10 @@ def main():
main()
"""
starter = main.ProcessStarter(bootstrap=BOOT,
packages=("twisted", "ampoule"),
packages=("twisted",),
env={"FOOBAR": STRING})
amp, finished = starter.startPythonProcess(main.AMPConnector(a), "I'll be ignored")
def _eb(reason):
print reason
finished.addErrback(_eb)
@ -294,7 +315,7 @@ main()
"""
STRING = "ciao"
starter = main.ProcessStarter(packages=("twisted", "ampoule"))
starter = main.ProcessStarter(packages=("twisted",))
c, finished = starter.startAMPProcess(child.AMPChild)
c.callRemote(commands.Echo, data=STRING
).addCallback(lambda response:
@ -303,9 +324,10 @@ main()
return finished
def test_BootstrapContext(self):
starter = main.ProcessStarter(packages=('twisted', 'ampoule'))
starter = main.ProcessStarter(packages=('twisted',))
c, finished = starter.startAMPProcess(TempDirChild)
cwd = []
def checkBootstrap(response):
cwd.append(response['cwd'])
self.assertNotEquals(cwd, os.getcwd())
@ -316,10 +338,11 @@ main()
return finished
def test_BootstrapContextInstance(self):
starter = main.ProcessStarter(packages=('twisted', 'ampoule'))
starter = main.ProcessStarter(packages=('twisted',))
c, finished = starter.startAMPProcess(TempDirChild,
ampChildArgs=('foo',))
cwd = []
def checkBootstrap(response):
cwd.append(response['cwd'])
self.assertTrue(cwd[0].endswith('/foo'))
@ -342,7 +365,7 @@ main()
return {'response': DATA+APPEND}
Pong.responder(pong)
starter = main.ProcessStarter(packages=("twisted", "ampoule"))
starter = main.ProcessStarter(packages=("twisted",))
subp, finished = starter.startAMPProcess(ampChild=Child, ampParent=Parent)
subp.callRemote(Ping, data=DATA
@ -359,10 +382,11 @@ main()
class Child(child.AMPChild):
pass
starter = main.ProcessStarter(packages=("twisted", "ampoule"))
starter = main.ProcessStarter(packages=("twisted",))
self.assertRaises(RuntimeError, starter.startAMPProcess, ampChild=Child)
class TestProcessPool(unittest.TestCase):
def test_startStopWorker(self):
@ -485,6 +509,7 @@ class TestProcessPool(unittest.TestCase):
Pong.responder(pong)
pp = pool.ProcessPool(ampChild=Child, ampParent=Parent)
def _checks(_):
return pp.doWork(Ping, data=DATA
).addCallback(lambda response:
@ -493,7 +518,6 @@ class TestProcessPool(unittest.TestCase):
return pp.start().addCallback(_checks).addCallback(lambda _: pp.stop())
def test_deferToAMPProcess(self):
"""
Test that deferToAMPProcess works as expected.
@ -593,6 +617,7 @@ class TestProcessPool(unittest.TestCase):
def _realChecks(_):
from twisted.internet import reactor
d = defer.Deferred()
def _cb():
def __(_):
try:
@ -677,7 +702,6 @@ class TestProcessPool(unittest.TestCase):
d.addCallback(_work)
return d
def test_disableProcessRecycling(self):
"""
Test that by setting 0 to recycleAfter we actually disable process recycling.
@ -724,7 +748,7 @@ class TestProcessPool(unittest.TestCase):
pp = pool.ProcessPool(
starter=main.ProcessStarter(
childReactor=FIRST,
packages=("twisted", "ampoule")),
packages=("twisted",)),
ampChild=ReactorChild, min=MIN, max=MAX)
pp.start()
return pp.doWork(Reactor
@ -735,7 +759,7 @@ class TestProcessPool(unittest.TestCase):
pp = pool.ProcessPool(
starter=main.ProcessStarter(
childReactor=SECOND,
packages=("twisted", "ampoule")),
packages=("twisted",)),
ampChild=ReactorChild, min=MIN, max=MAX)
pp.start()
return pp.doWork(Reactor
@ -772,6 +796,7 @@ class TestProcessPool(unittest.TestCase):
def test_SupplyChildArgs(self):
"""Ensure that arguments for the child constructor are passed in."""
pp = pool.ProcessPool(Writer, ampChildArgs=['body'], min=0)
def _check(result):
return pp.doWork(Write).addCallback(
self.assertEquals, {'response': 'body'})

View file

@ -3,17 +3,20 @@ from twisted.internet.protocol import ClientFactory
from twisted.trial import unittest
from twisted.protocols import amp
from contrib.procpools.ampoule import service, child, pool, main
from contrib.procpools.ampoule.commands import Echo
from evennia.contrib.procpools.ampoule import service, child, pool, main
from evennia.contrib.procpools.ampoule.commands import Echo
class ClientAMP(amp.AMP):
factory = None
def connectionMade(self):
if self.factory is not None:
self.factory.theProto = self
if hasattr(self.factory, 'onMade'):
self.factory.onMade.callback(None)
class TestAMPProxy(unittest.TestCase):
def setUp(self):
"""

View file

@ -21,7 +21,7 @@ the header carefully.
To test it works, make sure to activate the process pool, then try the
following as superuser:
@py from contrib.procpools.python_procpool import run_async;run_async("_return('Wohoo!')", at_return=self.msg, at_err=self.msg)
@py from evennia.contrib.procpools.python_procpool import run_async;run_async("_return('Wohoo!')", at_return=self.msg, at_err=self.msg)
You can also try to import time and do time.sleep(5) before the
_return statement, to test it really is asynchronous.
@ -30,7 +30,7 @@ _return statement, to test it really is asynchronous.
from twisted.protocols import amp
from twisted.internet import threads
from contrib.procpools.ampoule.child import AMPChild
from evennia.contrib.procpools.ampoule.child import AMPChild
from evennia.utils.dbserialize import to_pickle, from_pickle, do_pickle, do_unpickle
from evennia.utils.idmapper.base import PROC_MODIFIED_OBJS
from evennia.utils.utils import clean_object_caches, to_str

View file

@ -72,16 +72,15 @@ def start_plugin_services(server):
# terminal output
print ' amp (Process Pool): %s' % PROCPOOL_PORT
from contrib.procpools.ampoule import main as ampoule_main
from contrib.procpools.ampoule import service as ampoule_service
from contrib.procpools.ampoule import pool as ampoule_pool
from contrib.procpools.ampoule.main import BOOTSTRAP as _BOOTSTRAP
from contrib.procpools.python_procpool import PythonProcPoolChild
from evennia.contrib.procpools.ampoule import main as ampoule_main
from evennia.contrib.procpools.ampoule import service as ampoule_service
from evennia.contrib.procpools.ampoule import pool as ampoule_pool
from evennia.contrib.procpools.ampoule.main import BOOTSTRAP as _BOOTSTRAP
from evennia.contrib.procpools.python_procpool import PythonProcPoolChild
# for some reason absolute paths don't work here, only relative ones.
apackages = ("twisted",
os.path.join(os.pardir, "contrib", "procpools", "ampoule"),
os.path.join(os.pardir, "ev"),
"evennia",
"settings")
aenv = {"DJANGO_SETTINGS_MODULE": "settings",
"DATABASE_NAME": settings.DATABASES.get("default", {}).get("NAME") or settings.DATABASE_NAME}

View file

@ -23,8 +23,8 @@ mob implementation.
"""
from evennia import Object, CmdSet, default_cmds
from contrib import menusystem
from evennia import DefaultObject, CmdSet, default_cmds
from evennia.contrib import menusystem
#
@ -110,7 +110,7 @@ CONV = {"START": {"text": "Hello there, how can I help you?",
}
class TalkingNPC(Object):
class TalkingNPC(DefaultObject):
"""
This implements a simple Object using the talk command and using the
conversation defined above. .

View file

@ -20,7 +20,7 @@ class HelpEntryManager(models.Manager):
find_topicsuggestions
find_topics_with_category
all_to_category
search_help (equivalent to ev.search_helpentry)
search_help (equivalent to evennia.search_helpentry)
"""
def find_topicmatch(self, topicstr, exact=False):

View file

@ -45,7 +45,7 @@ class ObjectDBManager(TypedObjectManager):
get_objs_with_key_or_alias
get_contents
object_search (interface to many of the above methods,
equivalent to ev.search_object)
equivalent to evennia.search_object)
copy_object
"""

View file

@ -102,7 +102,7 @@ class DefaultObject(ObjectDB):
Characters, Exits and Rooms (see the bottom of this module).
Note that all new Objects and their subclasses *must* always be
created using the ev.create_object() function. This is so the
created using the evennia.create_object() function. This is so the
typeclass system can be correctly initiated behind the scenes.
@ -326,7 +326,7 @@ class DefaultObject(ObjectDB):
Perform a standard object search in the database, handling
multiple results and lack thereof gracefully. By default, only
objects in self's current location or inventory is searched.
Note: to find Players, use eg. ev.player_search.
Note: to find Players, use eg. evennia.player_search.
Args:
searchdata (str or obj): Primary search criterion. Will be matched

View file

@ -36,7 +36,7 @@ class PlayerDBManager(TypedObjectManager, UserManager):
get_player_from_email
get_player_from_uid
get_player_from_name
player_search (equivalent to ev.search_player)
player_search (equivalent to evennia.search_player)
#swap_character
"""

View file

@ -31,7 +31,7 @@ class ScriptDBManager(TypedObjectManager):
delete_script
remove_non_persistent
validate
script_search (equivalent to ev.search_script)
script_search (equivalent to evennia.search_script)
copy_script
"""