trim EOL (end-of-line) spaces on source files

This commit is contained in:
Sascha Silbe
2009-08-25 19:55:48 +02:00
parent 6c3fd0346c
commit ecdaf6b795
53 changed files with 446 additions and 446 deletions
+10 -10
View File
@@ -18,12 +18,12 @@
"""Activity implementation code for Sugar-based activities
Each activity within the OLPC environment must provide two
dbus services. The first, patterned after the
dbus services. The first, patterned after the
sugar.activity.activityfactory.ActivityFactory
class is responsible for providing a "create" method which
takes a small dictionary with values corresponding to a
class is responsible for providing a "create" method which
takes a small dictionary with values corresponding to a
sugar.activity.activityhandle.ActivityHandle
@@ -33,23 +33,23 @@ Each activity so registered is described by a
sugar.activity.bundle.Bundle
instance, which parses a specially formatted activity.info
file (stored in the activity directory's ./activity
subdirectory). The
instance, which parses a specially formatted activity.info
file (stored in the activity directory's ./activity
subdirectory). The
sugar.activity.bundlebuilder
module provides facilities for the standard setup.py module
which produces and registers bundles from activity source
module provides facilities for the standard setup.py module
which produces and registers bundles from activity source
directories.
Once instantiated by the ActivityFactory's create method,
each activity must provide an introspection API patterned
each activity must provide an introspection API patterned
after the
sugar.activity.activityservice.ActivityService
class. This class allows for querying the ID of the root
class. This class allows for querying the ID of the root
window, requesting sharing across the network, and basic
"what type of application are you" queries.
"""
+70 -70
View File
@@ -1,6 +1,6 @@
"""Base class for activities written in Python
This is currently the only definitive reference for what an
This is currently the only definitive reference for what an
activity must do to participate in the Sugar desktop.
A Basic Activity
@@ -10,11 +10,11 @@ The convention is to call it ActivitynameActivity, but this is not required as
the activity.info file associated with your activity will tell the sugar-shell
which class to start.
For example the most minimal Activity:
For example the most minimal Activity:
from sugar.activity import activity
class ReadActivity(activity.Activity):
pass
@@ -61,7 +61,7 @@ import dbus
import dbus.service
import cjson
from sugar import util
from sugar import util
from sugar.presence import presenceservice
from sugar.activity.activityservice import ActivityService
from sugar.activity.namingalert import NamingAlert
@@ -136,67 +136,67 @@ class _ActivitySession(gobject.GObject):
class Activity(Window, gtk.Container):
"""This is the base Activity class that all other Activities derive from.
This is where your activity starts.
To get a working Activity:
0. Derive your Activity from this class:
class MyActivity(activity.Activity):
...
1. implement an __init__() method for your Activity class.
Use your init method to create your own ActivityToolbar which will
contain some standard buttons:
contain some standard buttons:
toolbox = activity.ActivityToolbox(self)
Add extra Toolbars to your toolbox.
You should setup Activity sharing here too.
Finaly, your Activity may need some resources which you can claim
here too.
The __init__() method is also used to make the distinction between
being resumed from the Journal, or starting with a blank document.
being resumed from the Journal, or starting with a blank document.
2. Implement read_file() and write_file()
Most activities revolve around creating and storing Journal entries.
For example, Write: You create a document, it is saved to the Journal
and then later you resume working on the document.
read_file() and write_file() will be called by sugar to tell your
Activity that it should load or save the document the user is working
on.
3. Implement our Activity Toolbars.
The Toolbars are added to your Activity in step 1 (the toolbox), but
you need to implement them somewhere. Now is a good time.
There are a number of standard Toolbars. The most basic one, the one
your almost absolutely MUST have is the ActivityToolbar. Without
this, you're not really making a proper Sugar Activity (which may be
okay, but you should really stop and think about why not!) You do
this with the ActivityToolbox(self) call in step 1.
this with the ActivityToolbox(self) call in step 1.
Usually, you will also need the standard EditToolbar. This is the one
which has the standard copy and paste buttons. You need to derive
your own EditToolbar class from sugar.EditToolbar:
class EditToolbar(activity.EditToolbar):
...
See EditToolbar for the methods you should implement in your class.
Finaly, your Activity will very likely need some activity specific
buttons and options you can create your own toolbars by deriving a
class from gtk.Toolbar:
class MySpecialToolbar(gtk.Toolbar):
...
4. Use your creativity. Make your Activity something special and share
it with your friends!
Read through the methods of the Activity class below, to learn more about
how to make an Activity work.
how to make an Activity work.
Hint: A good and simple Activity to learn from is the Read activity. To
create your own activity, you may want to copy it and use it as a template.
"""
@@ -208,34 +208,34 @@ class Activity(Window, gtk.Container):
}
def __init__(self, handle, create_jobject=True):
"""Initialise the Activity
"""Initialise the Activity
handle -- sugar.activity.activityhandle.ActivityHandle
instance providing the activity id and access to the
presence service which *may* provide sharing for this
instance providing the activity id and access to the
presence service which *may* provide sharing for this
application
create_jobject -- boolean
define if it should create a journal object if we are
not resuming
Side effects:
Sets the gdk screen DPI setting (resolution) to the
Side effects:
Sets the gdk screen DPI setting (resolution) to the
Sugar screen resolution.
Connects our "destroy" message to our _destroy_cb
method.
Creates a base gtk.Window within this window.
Creates an ActivityService (self._bus) servicing
this application.
Usage:
Usage:
If your Activity implements __init__(), it should call
the base class __init()__ before doing Activity specific things.
"""
Window.__init__(self)
@@ -280,9 +280,9 @@ class Activity(Window, gtk.Container):
share_scope = SCOPE_PRIVATE
if handle.object_id:
self._jobject = datastore.get(handle.object_id)
self._jobject = datastore.get(handle.object_id)
self.set_title(self._jobject.metadata['title'])
if self._jobject.metadata.has_key('share-scope'):
share_scope = self._jobject.metadata['share-scope']
@@ -364,7 +364,7 @@ class Activity(Window, gtk.Container):
def get_id(self):
"""Returns the activity id of the current instance of your activity.
The activity id is sort-of-like the unix process id (PID). However,
unlike PIDs it is only different for each new instance (with
create_jobject = True set) and stays the same everytime a user
@@ -379,7 +379,7 @@ class Activity(Window, gtk.Container):
def set_canvas(self, canvas):
"""Sets the 'work area' of your activity with the canvas of your choice.
One commonly used canvas is gtk.ScrolledWindow
"""
Window.set_canvas(self, canvas)
@@ -412,21 +412,21 @@ class Activity(Window, gtk.Container):
logging.debug('Error creating activity datastore object: %s', err)
def get_activity_root(self):
""" FIXME: Deprecated. This part of the API has been moved
""" FIXME: Deprecated. This part of the API has been moved
out of this class to the module itself
Returns a path for saving Activity specific preferences, etc.
Returns a path to the location in the filesystem where the activity can
store activity related data that doesn't pertain to the current
execution of the activity and thus cannot go into the DataStore.
Currently, this will return something like
~/.sugar/default/MyActivityName/
Activities should ONLY save settings, user preferences and other data
which isn't specific to a journal item here. If (meta-)data is in anyway
specific to a journal entry, it MUST be stored in the DataStore.
specific to a journal entry, it MUST be stored in the DataStore.
"""
if os.environ.has_key('SUGAR_ACTIVITY_ROOT') and \
os.environ['SUGAR_ACTIVITY_ROOT']:
@@ -438,17 +438,17 @@ class Activity(Window, gtk.Container):
"""
Subclasses implement this method if they support resuming objects from
the journal. 'file_path' is the file to read from.
You should immediately open the file from the file_path, because the
file_name will be deleted immediately after returning from read_file().
Once the file has been opened, you do not have to read it immediately:
After you have opened it, the file will only be really gone when you
close it.
Although not required, this is also a good time to read all meta-data:
the file itself cannot be changed externally, but the title, description
and other metadata['tags'] may change. So if it is important for you to
notice changes, this is the time to record the originals.
notice changes, this is the time to record the originals.
"""
raise NotImplementedError
@@ -456,17 +456,17 @@ class Activity(Window, gtk.Container):
"""
Subclasses implement this method if they support saving data to objects
in the journal. 'file_path' is the file to write to.
If the user did make changes, you should create the file_path and save
all document data to it.
Additionally, you should also write any metadata needed to resume your
activity. For example, the Read activity saves the current page and zoom
level, so it can display the page.
Note: Currently, the file_path *WILL* be different from the one you
received in file_read(). Even if you kept the file_path from file_read()
open until now, you must still write the entire file to this file_path.
open until now, you must still write the entire file to this file_path.
"""
raise NotImplementedError
@@ -539,11 +539,11 @@ class Activity(Window, gtk.Container):
def save(self):
"""Request that the activity is saved to the Journal.
This method is called by the close() method below. In general,
activities should not override this method. This method is part of the
public API of an Acivity, and should behave in standard ways. Use your
own implementation of write_file() to save your Activity specific data.
own implementation of write_file() to save your Activity specific data.
"""
if self._jobject is None:
@@ -590,7 +590,7 @@ class Activity(Window, gtk.Container):
def copy(self):
"""Request that the activity 'Keep in Journal' the current state
of the activity.
Activities should not override this method. Instead, like save() do any
copy work that needs to be done in write_file()
"""
@@ -656,7 +656,7 @@ class Activity(Window, gtk.Container):
def _send_invites(self):
while self._invites_queue:
buddy_key = self._invites_queue.pop()
buddy_key = self._invites_queue.pop()
buddy = self._pservice.get_buddy(buddy_key)
if buddy:
self.shared_activity.invite(
@@ -666,10 +666,10 @@ class Activity(Window, gtk.Container):
def invite(self, buddy_key):
"""Invite a buddy to join this Activity.
Side Effects:
Calls self.share(True) to privately share the activity if it wasn't
shared before.
shared before.
"""
self._invites_queue.append(buddy_key)
@@ -681,7 +681,7 @@ class Activity(Window, gtk.Container):
def share(self, private=False):
"""Request that the activity be shared on the network.
private -- bool: True to share by invitation only,
False to advertise as shared to everyone.
@@ -694,7 +694,7 @@ class Activity(Window, gtk.Container):
verb = private and 'private' or 'public'
logging.debug('Requesting %s share of activity %s.', verb,
self._activity_id)
self._share_id = self._pservice.connect("activity-shared",
self._share_id = self._pservice.connect("activity-shared",
self.__share_cb)
self._pservice.share_activity(self, private=private)
@@ -752,7 +752,7 @@ class Activity(Window, gtk.Container):
def close(self, skip_save=False):
"""Request that the activity be stopped and saved to the Journal
Activities should not override this method, but should implement
write_file() to do any state saving instead. If the application wants
to control wether it can close, it should override can_close().
@@ -783,13 +783,13 @@ class Activity(Window, gtk.Container):
def get_metadata(self):
"""Returns the jobject metadata or None if there is no jobject.
Activities can set metadata in write_file() using:
Activities can set metadata in write_file() using:
self.metadata['MyKey'] = "Something"
and retrieve metadata in read_file() using:
and retrieve metadata in read_file() using:
self.metadata.get('MyKey', 'aDefaultValue')
Note: Make sure your activity works properly if one or more of the
metadata items is missing. Never assume they will all be present.
"""
@@ -822,7 +822,7 @@ def _get_session():
def get_bundle_name():
"""Return the bundle name for the current process' bundle"""
return os.environ['SUGAR_BUNDLE_NAME']
def get_bundle_path():
"""Return the bundle path for the current process' bundle"""
return os.environ['SUGAR_BUNDLE_PATH']
+1 -1
View File
@@ -197,7 +197,7 @@ class ActivityCreationHandler(gobject.GObject):
self._bundle = bundle
self._service_name = bundle.get_bundle_id()
self._handle = handle
bus = dbus.SessionBus()
bus_object = bus.get_object(_SHELL_SERVICE, _SHELL_PATH)
self._shell = dbus.Interface(bus_object, _SHELL_IFACE)
+14 -14
View File
@@ -25,25 +25,25 @@ class ActivityHandle(object):
self, activity_id=None, object_id=None, uri=None
):
"""Initialise the handle from activity_id
activity_id -- unique id for the activity to be
created
object_id -- identity of the journal object
associated with the activity. It was used by
the journal prototype implementation, might
change when we do the real one.
When you resume an activity from the journal
the object_id will be passed in. It's optional
since new activities does not have an
object_id -- identity of the journal object
associated with the activity. It was used by
the journal prototype implementation, might
change when we do the real one.
When you resume an activity from the journal
the object_id will be passed in. It's optional
since new activities does not have an
associated object (yet).
XXX Not clear how this relates to the activity
id yet, i.e. not sure we really need both. TBF
uri -- URI associated with the activity. Used when
opening an external file or resource in the
activity, rather than a journal object
(downloads stored on the file system for
uri -- URI associated with the activity. Used when
opening an external file or resource in the
activity, rather than a journal object
(downloads stored on the file system for
example or web pages)
"""
self.activity_id = activity_id
+6 -6
View File
@@ -30,20 +30,20 @@ _ACTIVITY_INTERFACE = "org.laptop.Activity"
class ActivityService(dbus.service.Object):
"""Base dbus service object that each Activity uses to export dbus methods.
The dbus service is separate from the actual Activity object so that we can
tightly control what stuff passes through the dbus python bindings."""
def __init__(self, activity):
"""Initialise the service for the given activity
activity -- sugar.activity.activity.Activity instance
Creates dbus services that use the instance's activity_id
as discriminants among all active services
of this type. That is, the services are all available
as discriminants among all active services
of this type. That is, the services are all available
as names/paths derived from the instance's activity_id.
The various methods exposed on dbus are just forwarded
to the client Activity object's equally-named methods.
"""
+11 -11
View File
@@ -36,7 +36,7 @@ from sugar.bundle.activitybundle import ActivityBundle
IGNORE_DIRS = ['dist', '.git']
IGNORE_FILES = ['.gitignore', 'MANIFEST', '*.pyc', '*~', '*.bak', 'pseudo.po']
def list_files(base_dir, ignore_dirs=None, ignore_files=None):
result = []
@@ -46,7 +46,7 @@ def list_files(base_dir, ignore_dirs=None, ignore_files=None):
if ignore_files:
for pattern in ignore_files:
files = [f for f in files if not fnmatch(f, pattern)]
rel_path = root[len(base_dir) + 1:]
for f in files:
result.append(os.path.join(rel_path, f))
@@ -83,7 +83,7 @@ class Config(object):
self.bundle_name = reduce(lambda x, y:x+y, self.activity_name.split())
self.bundle_root_dir = self.bundle_name + '.activity'
self.tar_root_dir = '%s-%d' % (self.bundle_name, self.version)
if self.dist_name:
self.xo_name = self.tar_name = self.dist_name
else:
@@ -103,7 +103,7 @@ class Builder(object):
if not self.config.bundle.is_dir(po_dir):
logging.warn("Missing po/ dir, cannot build_locale")
return
locale_dir = os.path.join(self.config.source_dir, 'locale')
if os.path.exists(locale_dir):
@@ -154,15 +154,15 @@ class Builder(object):
missing_files.append(path)
return missing_files
def fix_manifest(self):
self.build()
manifest = self.config.bundle.manifest
for path in self.check_manifest():
manifest.append(path)
f = open(os.path.join(self.config.source_dir, "MANIFEST"), "wb")
for line in manifest:
f.write(line + "\n")
@@ -186,7 +186,7 @@ class XOPackager(Packager):
def package(self):
bundle_zip = zipfile.ZipFile(self.package_path, 'w',
zipfile.ZIP_DEFLATED)
missing_files = self.builder.check_manifest()
if missing_files:
logging.warn('These files are not included in the manifest ' \
@@ -207,14 +207,14 @@ class SourcePackager(Packager):
self.config.tar_name)
def get_files(self):
git_ls = subprocess.Popen(['git', 'ls-files'], stdout=subprocess.PIPE,
git_ls = subprocess.Popen(['git', 'ls-files'], stdout=subprocess.PIPE,
cwd=self.config.source_dir)
stdout, _ = git_ls.communicate()
if git_ls.returncode :
# Fall back to filtered list
return list_files(self.config.source_dir,
IGNORE_DIRS, IGNORE_FILES)
return [path.strip() for path in stdout.strip('\n').split('\n')]
def package(self):
@@ -286,7 +286,7 @@ def cmd_dist_xo(config, args):
if args:
print 'Usage: %prog dist_xo'
return
packager = XOPackager(Builder(config))
packager.package()
+3 -3
View File
@@ -43,7 +43,7 @@ def get_single_process_path(bundle_id):
class SingleProcess(dbus.service.Object):
def __init__(self, name_service, constructor):
self.constructor = constructor
bus = dbus.SessionBus()
bus_name = dbus.service.BusName(name_service, bus=bus)
object_path = get_single_process_path(name_service)
@@ -77,7 +77,7 @@ def main():
if len(args) == 0:
print 'A python class must be specified as first argument.'
sys.exit(1)
sys.exit(1)
bundle_path = os.environ['SUGAR_BUNDLE_PATH']
sys.path.append(bundle_path)
@@ -102,7 +102,7 @@ def main():
module_name = splitted_module[0]
class_name = splitted_module[1]
module = __import__(module_name)
module = __import__(module_name)
for comp in module_name.split('.')[1:]:
module = getattr(module, comp)
+11 -11
View File
@@ -69,7 +69,7 @@ class NamingToolbar(gtk.Toolbar):
client = gconf.client_get_default()
color = XoColor(client.get_string('/desktop/sugar/user/color'))
icon = Icon()
icon.set_from_icon_name('activity-journal',
icon.set_from_icon_name('activity-journal',
gtk.ICON_SIZE_LARGE_TOOLBAR)
icon.props.xo_color = color
self._add_widget(icon)
@@ -78,7 +78,7 @@ class NamingToolbar(gtk.Toolbar):
self._title = gtk.Label(_('Name this entry'))
self._add_widget(self._title)
self._add_separator(True)
self._keep_button = ToolButton('dialog-ok', tooltip=_('Keep'))
@@ -170,7 +170,7 @@ class NamingAlert(gtk.Window):
width = gtk.gdk.screen_width() - offset * 2
height = gtk.gdk.screen_height() - offset * 2
self.set_size_request(width, height)
self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
self.set_decorated(False)
self.set_resizable(False)
self.set_modal(True)
@@ -230,13 +230,13 @@ class NamingAlert(gtk.Window):
self._favorite_icon = self._create_favorite_icon()
header.append(self._favorite_icon)
entry_icon = self._create_entry_icon()
header.append(entry_icon)
self._title = self._create_title()
header.append(self._title, hippo.PACK_EXPAND)
if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL:
header.reverse()
@@ -251,7 +251,7 @@ class NamingAlert(gtk.Window):
def _create_favorite_icon(self):
favorite_icon = FavoriteIcon(False)
return favorite_icon
def _create_entry_icon(self):
bundle_id = self._activity.metadata.get('activity', '')
if not bundle_id:
@@ -259,7 +259,7 @@ class NamingAlert(gtk.Window):
if bundle_id == '':
file_name = _get_icon_name(self._activity.metadata)
else:
else:
activity_bundle = ActivityBundle(self._bundle_path)
file_name = activity_bundle.get_icon()
entry_icon = CanvasIcon(file_name=file_name)
@@ -268,7 +268,7 @@ class NamingAlert(gtk.Window):
entry_icon.props.xo_color = XoColor( \
self._activity.metadata['icon-color'])
return entry_icon
def _create_title(self):
title = CanvasEntry()
title.set_background(style.COLOR_WHITE.get_html())
@@ -302,7 +302,7 @@ class NamingAlert(gtk.Window):
def _create_tags(self):
vbox = hippo.CanvasBox()
vbox.props.spacing = style.DEFAULT_SPACING
text = hippo.CanvasText(text=_('Tags:'),
font_desc=style.FONT_NORMAL.get_pango_desc())
text.props.color = style.COLOR_BUTTON_GREY.get_int()
@@ -313,7 +313,7 @@ class NamingAlert(gtk.Window):
text.props.xalign = hippo.ALIGNMENT_START
vbox.append(text)
tags = self._activity.metadata.get('tags', '')
text_view = CanvasTextView(tags, box_height=style.GRID_CELL_SIZE * 2)
vbox.append(text_view, hippo.PACK_EXPAND)