diff options
author | Marco Pesenti Gritti <marco@localhost.localdomain> | 2006-06-21 18:23:18 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <marco@localhost.localdomain> | 2006-06-21 18:23:18 (GMT) |
commit | f4e2791c897651d52980d35b84115e7c7f85a249 (patch) | |
tree | 8999ddbed2a6e3cc5864e4d59f9a6320e3fc9038 /shell/session | |
parent | a6974cd597b52c9782e105a38d709784f882bedf (diff) |
Big refactor of the directory structure and packages to
reflect private/public
Diffstat (limited to 'shell/session')
-rw-r--r-- | shell/session/Makefile.am | 5 | ||||
-rw-r--r-- | shell/session/__init__.py | 0 | ||||
-rw-r--r-- | shell/session/session.py | 59 |
3 files changed, 64 insertions, 0 deletions
diff --git a/shell/session/Makefile.am b/shell/session/Makefile.am new file mode 100644 index 0000000..a8ba913 --- /dev/null +++ b/shell/session/Makefile.am @@ -0,0 +1,5 @@ +sugardir = $(pythondir)/sugar/session +sugar_PYTHON = \ + __init__.py \ + session.py \ + LogWriter.py diff --git a/shell/session/__init__.py b/shell/session/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/shell/session/__init__.py diff --git a/shell/session/session.py b/shell/session/session.py new file mode 100644 index 0000000..2ddc554 --- /dev/null +++ b/shell/session/session.py @@ -0,0 +1,59 @@ +import os +import signal +from ConfigParser import ConfigParser + +import pygtk +pygtk.require('2.0') +import gtk + +from shell import Shell +from sugar import env + +class Session: + def __init__(self): + self._activity_processes = {} + + def start(self): + shell = Shell() + shell.connect('close', self._shell_close_cb) + shell.start() + + activities = [] + activities_dirs = [] + + for data_dir in env.get_data_dirs(): + act_dir = os.path.join(data_dir, env.get_activities_dir()) + activities_dirs.append(act_dir) + + activities_dirs.append(os.path.join(env.get_user_dir(), 'activities')) + + for activities_dir in activities_dirs: + if os.path.isdir(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 ] + pid = os.spawnvp(os.P_NOWAIT, 'python', args) + self._activity_processes[activity] = pid + + try: + gtk.main() + except KeyboardInterrupt: + print 'Ctrl+C pressed, exiting...' + self.shutdown() + + def _shell_close_cb(self, shell): + self.shutdown() + + def shutdown(self): + # FIXME Obviously we want to notify the activities to + # shutt down rather then killing them down forcefully. + for name in self._activity_processes.keys(): + print 'Shutting down %s' % (name) + os.kill(self._activity_processes[name], signal.SIGTERM) |