Load session from .activity files

This commit is contained in:
Marco Pesenti Gritti 2006-05-18 00:24:32 -04:00
parent 64dc217f52
commit 11a923d4b1
8 changed files with 59 additions and 35 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -9,4 +9,7 @@ icon_DATA = \
bubble.png \
bubbleOutline.png
activitydir = $(pkgdatadir)/activities
activity_DATA = chat.activity
EXTRA_DIST = $(icon_DATA)

View File

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

View File

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

View File

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