From 11a923d4b10842d65b07456f25522e7d662f3edc Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Thu, 18 May 2006 00:24:32 -0400 Subject: [PATCH] Load session from .activity files --- sugar/__installed__.py.in | 7 +++---- sugar/__uninstalled__.py | 11 ++--------- sugar/browser/Makefile.am | 6 ++++++ sugar/browser/browser.py | 3 +++ sugar/chat/Makefile.am | 3 +++ sugar/env.py | 24 ++++++++++++++++++++---- sugar/p2p/MostlyReliablePipe.py | 24 +++++++----------------- sugar/session/session.py | 16 +++++++++++++++- 8 files changed, 59 insertions(+), 35 deletions(-) diff --git a/sugar/__installed__.py.in b/sugar/__installed__.py.in index 7e7352f0..fd39247c 100644 --- a/sugar/__installed__.py.in +++ b/sugar/__installed__.py.in @@ -1,4 +1,3 @@ -import os - -def internal_get_data_file(filename): - return os.path.join('@prefix@/share/sugar', filename) +data_basedir = '@prefix@/share/' +data_dirs = [ 'sugar' ] +activities_dir = 'activities' diff --git a/sugar/__uninstalled__.py b/sugar/__uninstalled__.py index dd7818ed..4813b164 100644 --- a/sugar/__uninstalled__.py +++ b/sugar/__uninstalled__.py @@ -1,12 +1,5 @@ import os -basedir = os.path.dirname(os.path.dirname(__file__)) +data_basedir = os.path.dirname(os.path.dirname(__file__)) data_dirs = [ 'sugar/browser', 'sugar/chat' ] - -def internal_get_data_file(filename): - for data_dir in data_dirs: - path = os.path.abspath(os.path.join(basedir, data_dir, filename)) - if os.path.isfile(path): - return path - - return None +activities_dir = '' diff --git a/sugar/browser/Makefile.am b/sugar/browser/Makefile.am index e3892a33..4bf03d2a 100644 --- a/sugar/browser/Makefile.am +++ b/sugar/browser/Makefile.am @@ -9,5 +9,11 @@ icon_DATA = \ fold.png \ unfold.png +rcdir = $(pkgdatadir) +rc_DATA = browser.rc + +activitydir = $(pkgdatadir)/activities +activity_DATA = browser.activity + EXTRA_DIST = \ $(icon_DATA) diff --git a/sugar/browser/browser.py b/sugar/browser/browser.py index de53a7a4..2797d81a 100755 --- a/sugar/browser/browser.py +++ b/sugar/browser/browser.py @@ -340,5 +340,8 @@ if len(sys.argv) > 1 and sys.argv[1] == "--console": sys.stdout = LogWriter("Web Browser") sys.stderr = LogWriter("Web Browser") +gtk.rc_parse(sugar.env.get_data_file('browser.rc')) + BrowserShell.get_instance().open_web_activity() + gtk.main() diff --git a/sugar/chat/Makefile.am b/sugar/chat/Makefile.am index 0dbf1cb8..4197815e 100644 --- a/sugar/chat/Makefile.am +++ b/sugar/chat/Makefile.am @@ -9,4 +9,7 @@ icon_DATA = \ bubble.png \ bubbleOutline.png +activitydir = $(pkgdatadir)/activities +activity_DATA = chat.activity + EXTRA_DIST = $(icon_DATA) diff --git a/sugar/env.py b/sugar/env.py index 3b812d32..9359409b 100644 --- a/sugar/env.py +++ b/sugar/env.py @@ -1,7 +1,23 @@ +import os + try: - from sugar.__uninstalled__ import internal_get_data_file + from sugar.__uninstalled__ import * except ImportError: - from sugar.__installed__ import internal_get_data_file - + from sugar.__installed__ import * + def get_data_file(filename): - return internal_get_data_file(filename) + for data_dir in get_data_dirs(): + path = os.path.join(data_dir, filename) + if os.path.isfile(path): + return path + return None + +def get_data_dirs(): + dirs = [] + for data_dir in data_dirs: + path = os.path.join(data_basedir, data_dir) + dirs.append(path) + return dirs + +def get_activities_dir(): + return activities_dir diff --git a/sugar/p2p/MostlyReliablePipe.py b/sugar/p2p/MostlyReliablePipe.py index fbc65bd7..4a951e45 100644 --- a/sugar/p2p/MostlyReliablePipe.py +++ b/sugar/p2p/MostlyReliablePipe.py @@ -781,18 +781,14 @@ class RetransmitSegmentTestCase(SegmentBaseTestCase): assert seg.rt_master_sha() == self._DEF_MASTER_SHA, "RT master SHA after segment creation didn't match expected." assert seg.rt_segment_number() == self._DEF_SEGNO, "RT segment number after segment creation didn't match expected." - def _new_from_data(self, rt_msg_seq_num, rt_master_sha, rt_segment_number): - payload = struct.pack(RetransmitSegment.data_template(), rt_msg_seq_num, rt_master_sha, rt_segment_number) - payload_sha = _sha_data(payload) - header_template = SegmentBase.header_template() - header = struct.pack(header_template, self._SEG_MAGIC, SegmentBase.type_retransmit(), 1, 1, - self._DEF_MSG_SEQ_NUM, payload_sha) - return header + payload - def _test_new_from_data_fail(self, rt_msg_seq_num, rt_master_sha, rt_segment_number, fail_msg): try: - packet = self._new_from_data(rt_msg_seq_num, rt_master_sha, rt_segment_number) - seg = SegmentBase.new_from_data(self._DEF_ADDRESS, packet) + payload = struct.pack(RetransmitSegment.data_template(), rt_msg_seq_num, rt_master_sha, rt_segment_number) + payload_sha = _sha_data(payload) + header_template = SegmentBase.header_template() + header = struct.pack(header_template, self._SEG_MAGIC, SegmentBase.type_retransmit(), 1, 1, + self._DEF_MSG_SEQ_NUM, payload_sha) + seg = SegmentBase.new_from_data(self._DEF_ADDRESS, header + payload) except ValueError, exc: pass else: @@ -806,13 +802,7 @@ class RetransmitSegmentTestCase(SegmentBaseTestCase): self._test_new_from_data_fail(self._DEF_MSG_SEQ_NUM, self._DEF_MASTER_SHA, 0, "invalid RT segment number") self._test_new_from_data_fail(self._DEF_MSG_SEQ_NUM, self._DEF_MASTER_SHA, 65536, "invalid RT segment number") - # Ensure something that should work - packet = self._new_from_data(self._DEF_MSG_SEQ_NUM, self._DEF_MASTER_SHA, self._DEF_SEGNO) - seg = SegmentBase.new_from_data(self._DEF_ADDRESS, packet) - assert seg.segment_type() == SegmentBase.type_retransmit(), "Segment wasn't expected type." - assert seg.rt_msg_seq_num() == self._DEF_MSG_SEQ_NUM, "Segment RT message sequence number didn't match expected." - assert seg.rt_master_sha() == self._DEF_MASTER_SHA, "Segment RT master SHA didn't match expected." - assert seg.rt_segment_number() == self._DEF_SEGNO, "Segment RT segment number didn't match expected." + # TODO: Ensure something that should work def addToSuite(suite): suite.addTest(RetransmitSegmentTestCase("testInit")) diff --git a/sugar/session/session.py b/sugar/session/session.py index b58dfd94..415d3097 100644 --- a/sugar/session/session.py +++ b/sugar/session/session.py @@ -1,16 +1,30 @@ import os import sys +from ConfigParser import ConfigParser import pygtk pygtk.require('2.0') import gtk from sugar.shell import shell +from sugar import env def start(console): shell.main() - activities = ['sugar/chat/chat', 'sugar/browser/browser'] + activities = [] + + for data_dir in env.get_data_dirs(): + activities_dir = os.path.join(data_dir, env.get_activities_dir()) + for filename in os.listdir(activities_dir): + if filename.endswith(".activity"): + path = os.path.join(activities_dir, filename) + + cp = ConfigParser() + cp.read([path]) + python_class = cp.get('Activity', "python_class") + + activities.append(python_class) for activity in activities: args = [ 'python', '-m', activity ]