Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/model_population.py
diff options
context:
space:
mode:
Diffstat (limited to 'model_population.py')
-rw-r--r--model_population.py26
1 files changed, 17 insertions, 9 deletions
diff --git a/model_population.py b/model_population.py
index 0af5bd1..b29fb49 100644
--- a/model_population.py
+++ b/model_population.py
@@ -1,5 +1,5 @@
# coding: UTF-8
-# Copyright 2009 Thomas Jourdan
+# Copyright 2009, 2010 Thomas Jourdan
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+import ka_extensionpoint
#import simplejson as json
import pickle
@@ -30,7 +31,8 @@ STATE_INIT = 'I'
STATE_RANDOMIZED = 'R'
STATE_EVOLVED = 'E'
-MAGIC_NUMBER = 'mk01'
+MAGIC_NUMBER = 'mk'
+VERSION_NUMBER = '01'
class KandidModel(object):
"""
@@ -229,25 +231,31 @@ class KandidModel(object):
return new_at
return -1
-
-def from_buffer(buffer):
+def _get_my_revision():
+ revision = ka_extensionpoint.revision_number
+ return str(revision) if revision > 9 else '0' + str(revision)
+
+def from_buffer(input_buffer):
# ka_debug.info('read from_buffer')
obj = None
try:
- if buffer.startswith(MAGIC_NUMBER):
- obj = pickle.loads(zlib.decompress(buffer[4:]))
+ if input_buffer.startswith(MAGIC_NUMBER):
+ obj = pickle.loads(zlib.decompress(input_buffer[4:]))
+ if not input_buffer.startswith(MAGIC_NUMBER+_get_my_revision()):
+ obj = obj.copy()
else:
ka_debug.err('missing magic number')
except:
- ka_debug.err('failed reading buffer [%s] [%s]' % \
+ ka_debug.err('failed reading input buffer [%s] [%s]' % \
(sys.exc_info()[0], sys.exc_info()[1]))
traceback.print_exc(file=sys.__stderr__)
- return obj.copy()
+ return obj
def to_buffer(obj):
# ka_debug.info('write %s to_buffer' % type(obj))
try:
- return MAGIC_NUMBER + zlib.compress(pickle.dumps(obj, protocol=2))
+ return MAGIC_NUMBER + _get_my_revision() \
+ + zlib.compress(pickle.dumps(obj, protocol=2))
except:
ka_debug.err('failed writing buffer [%s] [%s]' % \
(sys.exc_info()[0], sys.exc_info()[1]))