From 3b887678655c909116f29e77b8e2c1531fae6be8 Mon Sep 17 00:00:00 2001 From: Griatch Date: Wed, 15 Feb 2012 14:27:26 +0100 Subject: [PATCH] Made fixes to the migrations. --- game/evennia.py | 60 +++++++++---------- .../migrations/0009_converting_attributes.py | 11 +++- .../migrations/0008_converting_attributes.py | 11 +++- .../migrations/0005_converting_attributes.py | 11 +++- src/typeclasses/models.py | 21 +++---- 5 files changed, 71 insertions(+), 43 deletions(-) diff --git a/game/evennia.py b/game/evennia.py index 12d77e61d..5af08023c 100755 --- a/game/evennia.py +++ b/game/evennia.py @@ -18,9 +18,38 @@ from subprocess import Popen, call sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) os.environ['DJANGO_SETTINGS_MODULE'] = 'game.settings' +if not os.path.exists('settings.py'): + # make sure we have a settings.py file. + print _(" No settings.py file found. launching manage.py ...") + + import game.manage + + print _(""" + ... A new settings file was created. Edit this file to configure + Evennia as desired by copy&pasting options from + src/settings_default.py. + + You should then also create/configure the database using + + python manage.py syncdb + + Make sure to create a new admin user when prompted -- this will be + user #1 in-game. If you use django-south, you'll see mentions of + migrating things in the above run. You then also have to run + + python manage.py migrate + + If you use default sqlite3 database, you will find a file + evennia.db appearing. This is the database file. Just delete this + and repeat the above manage.py steps to start with a fresh + database. + + When you are set up, run evennia.py again to start the server.""") + sys.exit() + # i18n from django.utils.translation import ugettext as _ - +# signal processing SIG = signal.SIGINT HELPENTRY = \ @@ -107,35 +136,6 @@ PORTAL_PIDFILE = "portal.pid" SERVER_RESTART = "server.restart" PORTAL_RESTART = "portal.restart" -if not os.path.exists('settings.py'): - # make sure we have a settings.py file. - print _(" No settings.py file found. launching manage.py ...") - - import game.manage - - print _(""" - ... A new settings file was created. Edit this file to configure - Evennia as desired by copy&pasting options from - src/settings_default.py. - - You should then also create/configure the database using - - python manage.py syncdb - - Make sure to create a new admin user when prompted -- this will be - user #1 in-game. If you use django-south, you'll see mentions of - migrating things in the above run. You then also have to run - - python manage.py migrate - - If you use default sqlite3 database, you will find a file - evennia.db appearing. This is the database file. Just delete this - and repeat the above manage.py steps to start with a fresh - database. - - When you are set up, run evennia.py again to start the server.""") - sys.exit() - # Get the settings from django.conf import settings diff --git a/src/objects/migrations/0009_converting_attributes.py b/src/objects/migrations/0009_converting_attributes.py index 8352462ad..4d7240931 100644 --- a/src/objects/migrations/0009_converting_attributes.py +++ b/src/objects/migrations/0009_converting_attributes.py @@ -9,13 +9,22 @@ try: except ImportError: import pickle from src.utils.utils import to_str, to_unicode +from src.typeclasses.models import PackedDBobject class Migration(DataMigration): def forwards(self, orm): "Write your forwards methods here." for attr in orm.ObjAttribute.objects.all(): - attr.value = pickle.loads(to_str(attr.db_value)) + # repack attr into new format, and reimport + val = pickle.loads(to_str(attr.db_value)) + if hasattr(val, '__iter__'): + val = ("iter", val) + elif type(val) == PackedDBobject: + val = ("dbobj", val) + else: + val = ("simple", val) + attr.value = attr.from_attr(val) def backwards(self, orm): "Write your backwards methods here." diff --git a/src/players/migrations/0008_converting_attributes.py b/src/players/migrations/0008_converting_attributes.py index 765e8dd3b..1314bcf6b 100644 --- a/src/players/migrations/0008_converting_attributes.py +++ b/src/players/migrations/0008_converting_attributes.py @@ -9,13 +9,22 @@ try: except ImportError: import pickle from src.utils.utils import to_str, to_unicode +from src.typeclasses.models import PackedDBobject class Migration(DataMigration): def forwards(self, orm): "Write your forwards methods here." for attr in orm.PlayerAttribute.objects.all(): - attr.value = pickle.loads(to_str(attr.db_value)) + # repack attr into new format, and reimport + val = pickle.loads(to_str(attr.db_value)) + if hasattr(val, '__iter__'): + val = ("iter", val) + elif type(val) == PackedDBobject: + val = ("dbobj", val) + else: + val = ("simple", val) + attr.value = attr.from_attr(val) def backwards(self, orm): "Write your backwards methods here." diff --git a/src/scripts/migrations/0005_converting_attributes.py b/src/scripts/migrations/0005_converting_attributes.py index bb02b4f0c..80acc3532 100644 --- a/src/scripts/migrations/0005_converting_attributes.py +++ b/src/scripts/migrations/0005_converting_attributes.py @@ -9,13 +9,22 @@ try: except ImportError: import pickle from src.utils.utils import to_str, to_unicode +from src.typeclasses.models import PackedDBobject class Migration(DataMigration): def forwards(self, orm): "Write your forwards methods here." for attr in orm.ScriptAttribute.objects.all(): - attr.value = pickle.loads(to_str(attr.db_value)) + # repack attr into new format, and reimport + val = pickle.loads(to_str(attr.db_value)) + if hasattr(val, '__iter__'): + val = ("iter", val) + elif type(val) == PackedDBobject: + val = ("dbobj", val) + else: + val = ("simple", val) + attr.value = attr.from_attr(val) def backwards(self, orm): "Write your backwards methods here." diff --git a/src/typeclasses/models.py b/src/typeclasses/models.py index 778b12f4c..b285f308e 100644 --- a/src/typeclasses/models.py +++ b/src/typeclasses/models.py @@ -70,20 +70,20 @@ PDUMPS = pickle.dumps # #------------------------------------------------------------ -class PackedDBobject(dict): +class PackedDBobject(object): """ Attribute helper class. A container for storing and easily identifying database objects in the database (which doesn't suppport storing db_objects directly). """ def __init__(self, ID, db_model, db_key): - self['id'] = ID - self['db_model'] = db_model - self['key'] = db_key + self.id = ID + self.db_model = db_model + self.key = db_key def __str__(self): - return "%s(#%s)" % (self['key'], self['id']) + return "%s(#%s)" % (self.key, self.id) def __unicode__(self): - return u"%s(#%s)" % (self['key'], self['id']) + return u"%s(#%s)" % (self.key, self.id) class PackedDict(dict): """ @@ -418,7 +418,7 @@ class Attribute(SharedMemoryModel): if db_model_name == "typeclass": # typeclass cannot help us, we want the actual child object model name db_model_name = GA(data.dbobj, "db_model_name") - return ("dbobj", PackedDBobject(data.id, db_model_name, data.db_key)) + return ("dbobj", PackedDBobject(data.id, db_model_name, data.db_key)) elif hasattr(data, "__iter__"): return ("iter", iter_db2id(data)) else: @@ -447,12 +447,13 @@ class Attribute(SharedMemoryModel): """ Convert db-stored dbref back to object """ - mclass = CTYPEGET(model=data["db_model"]).model_class() + mclass = CTYPEGET(model=data.db_model).model_class() try: - return mclass.objects.dbref_search(data['id']) + return mclass.objects.dbref_search(data.id) + except AttributeError: try: - return mclass.objects.get(id=data['id']) + return mclass.objects.get(id=data.id) except mclass.DoesNotExist: # could happen if object was deleted in the interim. return None