mirror of
https://github.com/evennia/evennia.git
synced 2026-03-22 07:46:30 +01:00
Migrations work under sqlite3, both from latest dev, from new install and from trunk. There might be some consistency issues though (it seems the character list is not properly migrated), so more testing is required.
This commit is contained in:
parent
8bd8193ab9
commit
230d73cfa0
16 changed files with 2941 additions and 463 deletions
|
|
@ -68,222 +68,6 @@ _DA = object.__delattr__
|
|||
#
|
||||
#------------------------------------------------------------
|
||||
|
||||
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
|
||||
def __str__(self):
|
||||
return "%s(#%s)" % (self.key, self.id)
|
||||
def __unicode__(self):
|
||||
return u"%s(#%s)" % (self.key, self.id)
|
||||
|
||||
class PackedDict(dict):
|
||||
"""
|
||||
Attribute helper class.
|
||||
A variant of dict that stores itself to the database when
|
||||
updating one of its keys. This is called and handled by
|
||||
Attribute.validate_data().
|
||||
"""
|
||||
def __init__(self, db_obj, *args, **kwargs):
|
||||
"""
|
||||
Sets up the packing dict. The db_store variable
|
||||
is set by Attribute.validate_data() when returned in
|
||||
order to allow custom updates to the dict.
|
||||
|
||||
db_obj - the Attribute object storing this dict.
|
||||
|
||||
The 'parent' property is set to 'init' at creation,
|
||||
this stops the system from saving itself over and over
|
||||
when first assigning the dict. Once initialization
|
||||
is over, the Attribute from_attr() method will assign
|
||||
the parent (or None, if at the root)
|
||||
|
||||
"""
|
||||
self.db_obj = db_obj
|
||||
self.parent = 'init'
|
||||
super(PackedDict, self).__init__(*args, **kwargs)
|
||||
def __str__(self):
|
||||
return "{%s}" % ", ".join("%s:%s" % (key, str(val)) for key, val in self.items())
|
||||
def save(self):
|
||||
"Relay save operation upwards in tree until we hit the root."
|
||||
if self.parent == 'init':
|
||||
pass
|
||||
elif self.parent:
|
||||
self.parent.save()
|
||||
else:
|
||||
self.db_obj.value = self
|
||||
def __setitem__(self, *args, **kwargs):
|
||||
"assign item to this dict"
|
||||
super(PackedDict, self).__setitem__(*args, **kwargs)
|
||||
self.save()
|
||||
def __delitem__(self, *args, **kwargs):
|
||||
"delete with del self[key]"
|
||||
super(PackedDict, self).__delitem__(*args, **kwargs)
|
||||
self.save()
|
||||
def clear(self, *args, **kwargs):
|
||||
"Custom clear"
|
||||
super(PackedDict, self).clear(*args, **kwargs)
|
||||
self.save()
|
||||
def pop(self, *args, **kwargs):
|
||||
"Custom pop"
|
||||
ret = super(PackedDict, self).pop(*args, **kwargs)
|
||||
self.save()
|
||||
return ret
|
||||
def popitem(self, *args, **kwargs):
|
||||
"Custom popitem"
|
||||
ret = super(PackedDict, self).popitem(*args, **kwargs)
|
||||
self.save()
|
||||
return ret
|
||||
def setdefault(self, *args, **kwargs):
|
||||
"Custom setdefault"
|
||||
super(PackedDict, self).setdefault(*args, **kwargs)
|
||||
self.save()
|
||||
def update(self, *args, **kwargs):
|
||||
"Custom update"
|
||||
super(PackedDict, self).update(*args, **kwargs)
|
||||
self.save()
|
||||
|
||||
class PackedList(list):
|
||||
"""
|
||||
Attribute helper class.
|
||||
A variant of list that stores itself to the database when
|
||||
updating one of its keys. This is called and handled by
|
||||
Attribute.validate_data().
|
||||
"""
|
||||
def __init__(self, db_obj, *args, **kwargs):
|
||||
"""
|
||||
sets up the packing list.
|
||||
db_obj - the attribute object storing this list.
|
||||
|
||||
the 'parent' property is set to 'init' at creation,
|
||||
this stops the system from saving itself over and over
|
||||
when first assigning the dict. once initialization
|
||||
is over, the attribute from_attr() method will assign
|
||||
the parent (or none, if at the root)
|
||||
|
||||
"""
|
||||
self.db_obj = db_obj
|
||||
self.parent = 'init'
|
||||
super(PackedList, self).__init__(*args, **kwargs)
|
||||
def __str__(self):
|
||||
return "[%s]" % ", ".join(str(val) for val in self)
|
||||
def save(self):
|
||||
"relay save operation upwards in tree until we hit the root."
|
||||
if self.parent == 'init':
|
||||
pass
|
||||
elif self.parent:
|
||||
self.parent.save()
|
||||
else:
|
||||
self.db_obj.value = self
|
||||
def __setitem__(self, *args, **kwargs):
|
||||
"Custom setitem that stores changed list to database."
|
||||
super(PackedList, self).__setitem__(*args, **kwargs)
|
||||
self.save()
|
||||
def __delitem__(self, *args, **kwargs):
|
||||
"delete with del self[index]"
|
||||
super(PackedList, self).__delitem__(*args, **kwargs)
|
||||
self.save()
|
||||
def append(self, *args, **kwargs):
|
||||
"Custom append"
|
||||
super(PackedList, self).append(*args, **kwargs)
|
||||
self.save()
|
||||
def extend(self, *args, **kwargs):
|
||||
"Custom extend"
|
||||
super(PackedList, self).extend(*args, **kwargs)
|
||||
self.save()
|
||||
def insert(self, *args, **kwargs):
|
||||
"Custom insert"
|
||||
super(PackedList, self).insert(*args, **kwargs)
|
||||
self.save()
|
||||
def remove(self, *args, **kwargs):
|
||||
"Custom remove"
|
||||
super(PackedList, self).remove(*args, **kwargs)
|
||||
self.save()
|
||||
def pop(self, *args, **kwargs):
|
||||
"Custom pop"
|
||||
ret = super(PackedList, self).pop(*args, **kwargs)
|
||||
self.save()
|
||||
return ret
|
||||
def reverse(self, *args, **kwargs):
|
||||
"Custom reverse"
|
||||
super(PackedList, self).reverse(*args, **kwargs)
|
||||
self.save()
|
||||
def sort(self, *args, **kwargs):
|
||||
"Custom sort"
|
||||
super(PackedList, self).sort(*args, **kwargs)
|
||||
self.save()
|
||||
|
||||
class PackedSet(set):
|
||||
"""
|
||||
A variant of Set that stores new updates to the databse.
|
||||
"""
|
||||
def __init__(self, db_obj, *args, **kwargs):
|
||||
"""
|
||||
sets up the packing set.
|
||||
db_obj - the attribute object storing this set
|
||||
|
||||
the 'parent' property is set to 'init' at creation,
|
||||
this stops the system from saving itself over and over
|
||||
when first assigning the dict. once initialization
|
||||
is over, the attribute from_attr() method will assign
|
||||
the parent (or none, if at the root)
|
||||
|
||||
"""
|
||||
self.db_obj = db_obj
|
||||
self.parent = 'init'
|
||||
super(PackedSet, self).__init__(*args, **kwargs)
|
||||
def __str__(self):
|
||||
return "{%s}" % ", ".join(str(val) for val in self)
|
||||
def save(self):
|
||||
"relay save operation upwards in tree until we hit the root."
|
||||
if self.parent == 'init':
|
||||
pass
|
||||
elif self.parent:
|
||||
self.parent.save()
|
||||
else:
|
||||
self.db_obj.value = self
|
||||
def add(self, *args, **kwargs):
|
||||
"Add an element to the set"
|
||||
super(PackedSet, self).add(*args, **kwargs)
|
||||
self.save()
|
||||
def clear(self, *args, **kwargs):
|
||||
"Remove all elements from this set"
|
||||
super(PackedSet, self).clear(*args, **kwargs)
|
||||
self.save()
|
||||
def difference_update(self, *args, **kwargs):
|
||||
"Remove all elements of another set from this set."
|
||||
super(PackedSet, self).difference_update(*args, **kwargs)
|
||||
self.save()
|
||||
def discard(self, *args, **kwargs):
|
||||
"Remove an element from a set if it is a member.\nIf not a member, do nothing."
|
||||
super(PackedSet, self).discard(*args, **kwargs)
|
||||
self.save()
|
||||
def intersection_update(self, *args, **kwargs):
|
||||
"Update a set with the intersection of itself and another."
|
||||
super(PackedSet, self).intersection_update(*args, **kwargs)
|
||||
self.save()
|
||||
def pop(self, *args, **kwargs):
|
||||
"Remove and return an arbitrary set element.\nRaises KeyError if the set is empty."
|
||||
super(PackedSet, self).pop(*args, **kwargs)
|
||||
self.save()
|
||||
def remove(self, *args, **kwargs):
|
||||
"Remove an element from a set; it must be a member.\nIf the element is not a member, raise a KeyError."
|
||||
super(PackedSet, self).remove(*args, **kwargs)
|
||||
self.save()
|
||||
def symmetric_difference_update(self, *args, **kwargs):
|
||||
"Update a set with the symmetric difference of itself and another."
|
||||
super(PackedSet, self).symmetric_difference_update(*args, **kwargs)
|
||||
self.save()
|
||||
def update(self, *args, **kwargs):
|
||||
"Update a set with the union of itself and others."
|
||||
super(PackedSet, self).update(*args, **kwargs)
|
||||
self.save()
|
||||
|
||||
class Attribute(SharedMemoryModel):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue