diff options
author | Aleksey Lim <alsroot@member.fsf.org> | 2009-01-17 03:36:32 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@member.fsf.org> | 2009-01-17 03:36:32 (GMT) |
commit | 3061a2a691589cd9d855e2d7607681bc46e2c57f (patch) | |
tree | 4fdedb4b69802c86d39932d26815f8c9436a44da /StoryBuilder.py | |
parent | 418fe31c7d3989c1a796748b0972f7095b546b90 (diff) |
remove redundant stuff, since we have journaled storage and native activity title
Diffstat (limited to 'StoryBuilder.py')
-rw-r--r-- | StoryBuilder.py | 91 |
1 files changed, 2 insertions, 89 deletions
diff --git a/StoryBuilder.py b/StoryBuilder.py index 4a83f5e..e64e7c0 100644 --- a/StoryBuilder.py +++ b/StoryBuilder.py @@ -30,12 +30,6 @@ from datetime import date from gettext import gettext as _ from olpcgames import eventwrap -try: - from hashlib import sha1 -except ImportError: - # Python < 2.5 - from sha import new as sha1 - import pygame from pygame.locals import * @@ -307,22 +301,11 @@ class Game: self.canvas = pygame.Surface(self.screen.get_size()).convert() self.canvas.fill((0xAC, 0xAC, 0xAC)) - self.author = 'you' # FIXME: When integrated with sugar, use owner - self.createdate = date.today() - self.journal_path = os.path.join( - os.getenv("SUGAR_ACTIVITY_ROOT"), "data") - if (not os.path.exists(self.journal_path)): - os.makedirs(self.journal_path) - self.journal_index = os.path.join(self.journal_path, 'index.txt') - - self._journal_index_load() - self._themes = load_themes() self.current_theme = 0 self.layout = Layout('layout.png', surfsize=self.screen.get_size()) self.set_theme() self.text = '' - self.title = '' self.screen.blit(self.canvas, (0, 0)) pygame.display.flip() @@ -343,16 +326,10 @@ class Game: self.lesson_plan_texts = [] self.lesson_plan_area = None - title_input = gui.Input(value=self.title, size=86) - title_input.connect(gui.CHANGE, self.update_title_cb) - guicontainer.add(title_input, 90+self.layout.rect.left, - 559+self.layout.rect.top) - self.title_input = title_input - text_input = gui.TextArea(value=self.text, width=875, height=95) text_input.connect(gui.CHANGE, self.update_text_cb) guicontainer.add(text_input, 90+self.layout.rect.left, - 595+self.layout.rect.top) + 560+self.layout.rect.top) self.text_input = text_input self.guicontainer = guicontainer @@ -402,15 +379,10 @@ class Game: Widget(THEME_RIGHT, self.layout, self.next_theme), ] - def save(self, filename, update_index=True): + def save(self, filename): """Save the story. - - Pass update_index=True if you need to make sure - this poll is in the journal index file. For example, - when creating a new poll. """ f = open(filename, 'w') - pickle.dump(self.title, f) pickle.dump(self.current_theme, f) pickle.dump(self.text, f) pickle.dump(len(self.stickersprites.sprites()), f) @@ -418,60 +390,6 @@ class Game: pickle.dump(character.name, f) pickle.dump(character.rect.topleft, f) f.close() - if update_index: - self._journal_index_add() - - def _journal_index_add(self): - """Write the current poll to the journal index.""" - self._journal_index_load() - # insert self - self._stories_index[self.title] = { - 'author': self.author, - 'createdate': self.createdate, - 'sha': self._get_sha(), - } - # write index - self._journal_index_write() - - def _get_sha(self): - """Return a sha1 hash of something about this story. - - Currently we sha1 the story title and author. - This is used for the filename of the saved poll. - It will probably be used for the mesh networking too. - """ - sha = sha1(self.title + self.author).hexdigest() - return sha - - def _journal_index_load(self): - """Load the journal index of saved stories.""" - self._stories_index = {} - try: - lines = open(self.journal_index).readlines() - except IOError: # File does not exist - lines = [] - for line in lines: - try: - title, author, createdate, sha =\ - line.strip().split('\t') - except ValueError: - # incompatible file format change - continue - self._stories_index[title] = { - 'author': author, - 'createdate': date.fromordinal(int(createdate)), 'sha': sha} - - def _journal_index_write(self): - """Write the journal file.""" - # XXX Need to validate self._stories_index! - f = open(self.journal_index, 'w') - for title in self._stories_index.keys(): - f.write('%s\t%s\t%d\t%s\n' % - (title, - self._stories_index[title]['author'], - self._stories_index[title]['createdate'].toordinal(), - self._stories_index[title]['sha'])) - f.close() def lesson_plan_cb(self): if not self.lesson_plan_texts: @@ -542,8 +460,6 @@ class Game: fail = False f = open(filename) try: - self.title = pickle.load(f) - self.title_input.value = self.title self.current_theme = pickle.load(f) self.set_theme() self.text = pickle.load(f) @@ -575,9 +491,6 @@ class Game: return True return False - def update_title_cb(self): - self.title = self.title_input.value - def update_text_cb(self): self.text = self.text_input.value |