Made fixes to the migrations.

This commit is contained in:
Griatch 2012-02-15 14:27:26 +01:00
parent d594357335
commit 3b88767865
5 changed files with 71 additions and 43 deletions

View file

@ -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

View file

@ -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."

View file

@ -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."

View file

@ -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."

View file

@ -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