diff options
author | Marco Pesenti Gritti <marco@localhost.localdomain> | 2006-07-12 11:20:41 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <marco@localhost.localdomain> | 2006-07-12 11:20:41 (GMT) |
commit | ca2b08f8b6fb1bc54a4e4f9cfc457f57cf958c7f (patch) | |
tree | 8fe41e84baa9f16f4a4d8aa99aa30f1851a24c09 /shell/ActivityRegistry.py | |
parent | e959a6f37f07550e62d670ce6bad69a7e1ad8270 (diff) |
Cleanup and document session creation and activity registry
Diffstat (limited to 'shell/ActivityRegistry.py')
-rw-r--r-- | shell/ActivityRegistry.py | 72 |
1 files changed, 58 insertions, 14 deletions
diff --git a/shell/ActivityRegistry.py b/shell/ActivityRegistry.py index 96ec3b1..9f1e857 100644 --- a/shell/ActivityRegistry.py +++ b/shell/ActivityRegistry.py @@ -1,29 +1,73 @@ -import dbus +import logging -class ActivityInfo: - def __init__(self, name, title): +class ActivityModule: + """Info about an activity module. Wraps a .activity file.""" + + def __init__(self, name, activity_id, activity_exec, directory): self._name = name - self._title = title + self._id = activity_id + self._directory = directory + self._exec = activity_exec def get_name(self): + """Get the activity user visible name.""" return self._name - def get_title(self): - return self._title + def get_id(self): + """Get the activity identifier""" + return self._id + + def get_class(self): + """Get the activity executable""" + return self._class -class ActivityRegistry(dbus.service.Object): - """Dbus service that tracks the available activities""" + def get_directory(self): + """Get the path to activity directory.""" + return self._directory + +class ActivityRegistry: + """Service that tracks the available activities""" def __init__(self): self._activities = [] - bus = dbus.SessionBus() - bus_name = dbus.service.BusName('com.redhat.Sugar.ActivityRegistry', bus = bus) - dbus.service.Object.__init__(self, bus_name, '/com/redhat/Sugar/ActivityRegistry') + def scan_directory(self, path): + """Scan a directory for activities and add them to the registry.""" + if os.path.isdir(base_dir): + for filename in os.listdir(base_dir): + activity_dir = os.path.join(base_dir, filename) + if os.path.isdir(activity_dir): + for filename in os.listdir(activity_dir): + if filename.endswith(".activity"): + self.add(os.path.join(activity_dir, filename)) + + def add(self, path): + """Add an activity to the registry. The path points to a .activity file.""" + cp = ConfigParser() + cp.read([path]) + + directory = os.path.dirname(path) + + try: + activity_id = cp.get('Activity', 'id') + name = cp.get('Activity', 'name') + except NoOptionError: + logging.error('%s miss a required option' % (path)) + + if cp.has_option('Activity', 'exec'): + activity_exec = cp.get('Activity', 'exec') + elif cp.has_option('Activity', 'python_module'): + python_module = cp.get('Activity', 'python_module') + activity_exec = 'python -m sugar/activity/Activity %s %s' \ + % (name, python_module) + else: + logging.error('%s must specifiy exec or python_module' % (path)) + + module = ActivityModule(name, activity_id, activity_exec, directory) + self._activities.append(module) - @dbus.service.method("com.redhat.Sugar.ActivityRegistry") - def add(self, name, title): - self._activities.append(ActivityInfo(name, title)) + return True def list_activities(self): + """Enumerate the registered activities as an ActivityModule list.""" return self._activities |