From 9e2ad5966314d0e667a7c57e6f73268afb01bd17 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 16 Jun 2012 14:51:22 +0200 Subject: [PATCH] Added a fix for running with postgresql-psycopg2. This does not actually resolve the problem as much as circumvent it, so I'm not marking Issue 115 as closed just yet. --- src/commands/default/batchprocess.py | 1 - src/players/manager.py | 2 +- src/server/initial_setup.py | 37 ++++++++++++++++++++++------ src/settings_default.py | 5 ++-- src/utils/utils.py | 27 +++++++++++--------- 5 files changed, 48 insertions(+), 24 deletions(-) diff --git a/src/commands/default/batchprocess.py b/src/commands/default/batchprocess.py index 1c2e6fc87e..d82fa4263c 100644 --- a/src/commands/default/batchprocess.py +++ b/src/commands/default/batchprocess.py @@ -242,7 +242,6 @@ class CmdBatchCommands(MuxCommand): show_curr(caller) else: caller.msg("Running Batch-command processor - Automatic mode for %s (this might take some time) ..." % python_path) - # add the 'safety' cmdset in case the batch processing adds cmdsets to us for inum in range(len(commands)): # loop through the batch file diff --git a/src/players/manager.py b/src/players/manager.py index 4cc88b7e01..8d5fc086a9 100644 --- a/src/players/manager.py +++ b/src/players/manager.py @@ -38,7 +38,7 @@ def returns_player_list(method): # there is a 1-1 relation between Users-Players, so we # try to go the other way instead. from src.players.models import PlayerDB - match = PlayerDB.objects.filter(user=user) + match = PlayerDB.objects.filter(user__id=user.id) if match: players.append(match[0]) else: diff --git a/src/server/initial_setup.py b/src/server/initial_setup.py index eff1603b8e..f6127e2700 100644 --- a/src/server/initial_setup.py +++ b/src/server/initial_setup.py @@ -6,6 +6,7 @@ other things. Everything starts at handle_setup() """ +import django from django.contrib.auth.models import User from django.core import management from django.conf import settings @@ -84,6 +85,7 @@ def create_objects(): if not god_character.home: god_character.home = limbo_obj + def create_channels(): """ Creates some sensible default channels. @@ -91,14 +93,32 @@ def create_channels(): print " Creating default channels ..." # public channel - key, aliases, desc, locks = settings.CHANNEL_PUBLIC - pchan = create.create_channel(key, aliases, desc, locks=locks) + key1, aliases, desc, locks = settings.CHANNEL_PUBLIC + pchan = create.create_channel(key1, aliases, desc, locks=locks) # mudinfo channel - key, aliases, desc, locks = settings.CHANNEL_MUDINFO - ichan = create.create_channel(key, aliases, desc, locks=locks) + key2, aliases, desc, locks = settings.CHANNEL_MUDINFO + ichan = create.create_channel(key2, aliases, desc, locks=locks) # connectinfo channel - key, aliases, desc, locks = settings.CHANNEL_CONNECTINFO - cchan = create.create_channel(key, aliases, desc, locks=locks) + key3, aliases, desc, locks = settings.CHANNEL_CONNECTINFO + cchan = create.create_channel(key3, aliases, desc, locks=locks) + + + # TODO: postgresql-psycopg2 has a strange error when trying to connect the user + # to the default channels. It works fine from inside the game, but not from + # the initial startup. We are temporarily bypassing the problem with the following + # fix. See Evennia Issue 151. + if ((".".join(str(i) for i in django.VERSION) < "1.2" and settings.DATABASE_ENGINE == "postgresql_psycopg2") + or (hasattr(settings, 'DATABASES') + and settings.DATABASES.get("default", {}).get('ENGINE', None) + == 'django.db.backends.postgresql_psycopg2')): + warning = """ + PostgreSQL-psycopg2 compatability fix: + The in-game channels %s, %s and %s were created, + but the superuser was not yet connected to them. Please use in-game commands to + connect Player #1 to those channels when first logging in. + """ % (key1, key2, key3) + print warning + return # connect the god user to all these channels by default. goduser = get_god_user() @@ -209,7 +229,7 @@ def reset_server(): It also checks so the warm-reset mechanism works as it should. """ from src.server.sessionhandler import SESSIONS - print " Initial setup complete. Resetting/reloading Server." + print " Initial setup complete. Restarting Server once." SESSIONS.server.shutdown(mode='reset') def handle_setup(last_step): @@ -237,7 +257,8 @@ def handle_setup(last_step): create_admin_media_links, import_MUX_help_files, at_initial_setup, - reset_server] + reset_server + ] if not settings.IMPORT_MUX_HELP: # skip importing of the MUX helpfiles, they are diff --git a/src/settings_default.py b/src/settings_default.py index 3c23f6ceda..90636c0008 100644 --- a/src/settings_default.py +++ b/src/settings_default.py @@ -121,8 +121,7 @@ ATTRIBUTE_CACHE_MAXSIZE = 100 # Evennia Database config ###################################################################### -# Database config syntax for Django 1.2+. You can add several -# database engines in the dictionary (untested). +# Database config syntax for Django 1.2+. # ENGINE - path to the the database backend (replace # sqlite3 in the example with the one you want. # Supported database engines are @@ -142,7 +141,7 @@ DATABASES = { 'HOST':'', 'PORT':'' }} -# Engine Config style for Django versions < 1.2. See above. +# Engine Config style for Django versions < 1.2 only. See above. DATABASE_ENGINE = 'sqlite3' DATABASE_NAME = os.path.join(GAME_DIR, 'evennia.db3') DATABASE_USER = '' diff --git a/src/utils/utils.py b/src/utils/utils.py index f3be8ff8f8..0ede15fc2e 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -449,7 +449,7 @@ def format_table(table, extra_space=1): for icol, col in enumerate(table)]) return ftable -def run_async(async_func, at_return=None, at_err=None): +def run_async(async_func, *args, **kwargs): """ This wrapper will use Twisted's asynchronous features to run a slow function using a separate reactor thread. In effect this means that @@ -467,20 +467,25 @@ def run_async(async_func, at_return=None, at_err=None): your async_func under sqlite3 you will probably run very slow or even get tracebacks. - async_func() - function that should be run asynchroneously - at_return(r) - if given, this function will be called when async_func returns - value r at the end of a successful execution - at_err(e) - if given, this function is called if async_func fails with an exception e. - use e.trap(ExceptionType1, ExceptionType2) + arg: + async_func - function that should be run asynchroneously + + reserved keywords: + at_return(r) - if given, this function will be called when async_func returns + value r at the end of a successful execution + at_err(e) - if given, this function is called if async_func fails with an exception e. + use e.trap(ExceptionType1, ExceptionType2) + + all other arguments/keywords will be used as args/kwargs fro async_func. """ # create deferred object - deferred = threads.deferToThread(async_func) - if at_return: - deferred.addCallback(at_return) - if at_err: - deferred.addErrback(at_err) + deferred = threads.deferToThread(async_func, *args, **kwargs) + if "at_return" in kwargs: + deferred.addCallback(kwargs["at_return"]) + if "at_err" in kwargs: + deferred.addErrback(kwargs["at_err"]) # always add a logging errback as a last catch def default_errback(e): from src.utils import logger