From 165fe0b00eded356850c6d1cba33971b7ffe6821 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 1 Dec 2006 23:23:58 +0100 Subject: [PATCH] Several cleanups --- sugar-emulator | 10 ++-- sugar/activity/ActivityFactory.py | 8 +-- sugar/activity/bundleregistry.py | 21 +------- sugar/setup.py | 89 ------------------------------- sugar/util.py | 32 ++++++----- 5 files changed, 27 insertions(+), 133 deletions(-) delete mode 100755 sugar/setup.py diff --git a/sugar-emulator b/sugar-emulator index 6def3c1f..6e829e14 100755 --- a/sugar-emulator +++ b/sugar-emulator @@ -28,7 +28,7 @@ else: sourcedir = None from sugar import env -from sugar import setup +from sugar import util if sourcedir: if os.environ.has_key('PYTHONPATH'): @@ -50,13 +50,13 @@ if sourcedir: bin = os.path.join(sourcedir, 'services/presence/sugar-presence-service') - setup.write_service('org.laptop.Presence', bin, - env.get_user_service_dir()) + util.write_service('org.laptop.Presence', bin, + env.get_user_service_dir()) bin = os.path.join(sourcedir, 'services/clipboard/sugar-clipboard') - setup.write_service('org.laptop.Clipboard', bin, - env.get_user_service_dir()) + util.write_service('org.laptop.Clipboard', bin, + env.get_user_service_dir()) from sugar.emulator import Emulator diff --git a/sugar/activity/ActivityFactory.py b/sugar/activity/ActivityFactory.py index e20c217f..66eba74d 100644 --- a/sugar/activity/ActivityFactory.py +++ b/sugar/activity/ActivityFactory.py @@ -30,10 +30,6 @@ def get_path(activity_name): """Returns the activity path""" return '/' + activity_name.replace('.', '/') -def _get_factory(activity_name): - """Returns the activity factory""" - return activity_name + '.Factory' - class ActivityFactory(dbus.service.Object): """Dbus service that takes care of creating new instances of an activity""" @@ -55,7 +51,7 @@ class ActivityFactory(dbus.service.Object): self._constructor = getattr(module, class_name) bus = dbus.SessionBus() - factory = _get_factory(activity_type) + factory = activity_type bus_name = dbus.service.BusName(factory, bus = bus) dbus.service.Object.__init__(self, bus_name, get_path(factory)) @@ -82,7 +78,7 @@ def create(activity_name): """Create a new activity from his name.""" bus = dbus.SessionBus() - factory_name = _get_factory(activity_name) + factory_name = activity_name factory_path = get_path(factory_name) proxy_obj = bus.get_object(factory_name, factory_path) diff --git a/sugar/activity/bundleregistry.py b/sugar/activity/bundleregistry.py index 02bf3021..c6cfa480 100644 --- a/sugar/activity/bundleregistry.py +++ b/sugar/activity/bundleregistry.py @@ -3,10 +3,7 @@ from ConfigParser import ConfigParser from sugar.activity.bundle import Bundle from sugar import env - -class _ServiceParser(ConfigParser): - def optionxform(self, option): - return option +from sugar import util class _ServiceManager(object): def __init__(self): @@ -15,24 +12,10 @@ class _ServiceManager(object): def add(self, bundle): name = bundle.get_service_name() - service_cp = _ServiceParser() - - section = 'D-BUS Service' - service_cp.add_section(section) - - # Compatibility with the old activity registry, remove after BTest-1 - # service_cp.set(section, 'Name', name) - service_cp.set(section, 'Name', name + '.Factory') - - # FIXME total hack full_exec = env.get_shell_bin_dir() + '/' + bundle.get_exec() full_exec += ' ' + bundle.get_path() - service_cp.set(section, 'Exec', full_exec) - dest = os.path.join(self._path, name + '.service') - fileobject = open(dest, 'w') - service_cp.write(fileobject) - fileobject.close() + util.write_service(name, full_exec, self._path) class BundleRegistry: """Service that tracks the available activity bundles""" diff --git a/sugar/setup.py b/sugar/setup.py deleted file mode 100755 index e4d8ae7a..00000000 --- a/sugar/setup.py +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/python - -# Copyright (C) 2006, Red Hat, Inc. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the -# Free Software Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. - -import os -import sys -import shutil -import logging -from ConfigParser import ConfigParser -from ConfigParser import NoOptionError - -class ServiceParser(ConfigParser): - def optionxform(self, option): - return option - -def write_service(name, bin, path): - service_cp = ServiceParser() - section = 'D-BUS Service' - service_cp.add_section(section) - service_cp.set(section, 'Name', name) - service_cp.set(section, 'Exec', bin) - - dest_filename = os.path.join(path, name + '.service') - fileobject = open(dest_filename, 'w') - service_cp.write(fileobject) - fileobject.close() - -def setup_activity(source, dest_path, bin): - """Copy an activity to the destination path and setup it""" - filename = os.path.basename(source) - dest = os.path.join(dest_path, filename) - print 'Install ' + filename + ' ...' - shutil.copyfile(source, dest) - - cp = ConfigParser() - cp.read([source]) - - try: - activity_id = cp.get('Activity', 'id') - except NoOptionError: - logging.error('%s miss the required id option' % (path)) - return False - - 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') - python_module = cp.get('Activity', 'python_module') - activity_exec = '%s %s %s' % (bin, activity_id, python_module) - else: - logging.error('%s must specifiy exec or python_module' % (source)) - return False - - write_service(activity_id + '.Factory', activity_exec, dest_path) - -def setup_activities(source_path, dest_path, bin): - """Scan a directory for activities and install them.""" - if not os.path.isdir(dest_path): - os.mkdir(dest_path) - else: - # FIXME delete the whole directory - pass - - if os.path.isdir(source_path): - for filename in os.listdir(source_path): - activity_dir = os.path.join(source_path, filename) - if os.path.isdir(activity_dir): - for filename in os.listdir(activity_dir): - if filename.endswith(".activity"): - source = os.path.join(activity_dir, filename) - setup_activity(source, dest_path, bin) - -if __name__=='__main__': - setup_activities(sys.argv[1], sys.argv[2], sys.argv[3]) diff --git a/sugar/util.py b/sugar/util.py index dd297d1a..108c48e7 100644 --- a/sugar/util.py +++ b/sugar/util.py @@ -20,20 +20,9 @@ import sha import random import binascii import string - -import gobject - -class GObjectSingletonMeta(gobject.GObjectMeta): - """GObject Singleton Metaclass""" - - def __init__(klass, name, bases, dict): - gobject.GObjectMeta.__init__(klass, name, bases, dict) - klass.__instance = None - - def __call__(klass, *args, **kwargs): - if klass.__instance is None: - klass.__instance = gobject.GObjectMeta.__call__(klass, *args, **kwargs) - return klass.__instance +import os +from ConfigParser import ConfigParser +from ConfigParser import NoOptionError def printable_hash(in_hash): """Convert binary hash data into printable characters.""" @@ -68,3 +57,18 @@ def validate_activity_id(actid): return False return True +class _ServiceParser(ConfigParser): + def optionxform(self, option): + return option + +def write_service(name, bin, path): + service_cp = _ServiceParser() + section = 'D-BUS Service' + service_cp.add_section(section) + service_cp.set(section, 'Name', name) + service_cp.set(section, 'Exec', bin) + + dest_filename = os.path.join(path, name + '.service') + fileobject = open(dest_filename, 'w') + service_cp.write(fileobject) + fileobject.close()