pep8'd sugar3.activity

This commit is contained in:
William Orr 2013-05-17 01:16:36 -04:00 committed by Daniel Narvaez
parent 3e5c37f3f8
commit 8a6c935dd0
6 changed files with 69 additions and 65 deletions

View File

@ -67,9 +67,9 @@ import dbus.service
from dbus import PROPERTIES_IFACE from dbus import PROPERTIES_IFACE
from telepathy.server import DBusProperties from telepathy.server import DBusProperties
from telepathy.interfaces import CHANNEL, \ from telepathy.interfaces import CHANNEL, \
CHANNEL_TYPE_TEXT, \ CHANNEL_TYPE_TEXT, \
CLIENT, \ CLIENT, \
CLIENT_HANDLER CLIENT_HANDLER
from telepathy.constants import CONNECTION_HANDLE_TYPE_CONTACT from telepathy.constants import CONNECTION_HANDLE_TYPE_CONTACT
from telepathy.constants import CONNECTION_HANDLE_TYPE_ROOM from telepathy.constants import CONNECTION_HANDLE_TYPE_ROOM
@ -111,7 +111,7 @@ class _ActivitySession(GObject.GObject):
self._xsmp_client = XSMPClient() self._xsmp_client = XSMPClient()
self._xsmp_client.connect('quit-requested', self._xsmp_client.connect('quit-requested',
self.__sm_quit_requested_cb) self.__sm_quit_requested_cb)
self._xsmp_client.connect('quit', self.__sm_quit_cb) self._xsmp_client.connect('quit', self.__sm_quit_cb)
self._xsmp_client.startup() self._xsmp_client.startup()
@ -346,8 +346,8 @@ class Activity(Window, Gtk.Container):
if handle.invited: if handle.invited:
wait_loop = GObject.MainLoop() wait_loop = GObject.MainLoop()
self._client_handler = _ClientHandler( self._client_handler = _ClientHandler(
self.get_bundle_id(), self.get_bundle_id(),
partial(self.__got_channel_cb, wait_loop)) partial(self.__got_channel_cb, wait_loop))
# FIXME: The current API requires that self.shared_activity is set # FIXME: The current API requires that self.shared_activity is set
# before exiting from __init__, so we wait until we have got the # before exiting from __init__, so we wait until we have got the
# shared activity. http://bugs.sugarlabs.org/ticket/2168 # shared activity. http://bugs.sugarlabs.org/ticket/2168
@ -422,7 +422,7 @@ class Activity(Window, Gtk.Container):
self.__joined_cb(self.shared_activity, True, None) self.__joined_cb(self.shared_activity, True, None)
elif share_scope != SCOPE_PRIVATE: elif share_scope != SCOPE_PRIVATE:
logging.debug('*** Act %s no existing mesh instance, but used to ' logging.debug('*** Act %s no existing mesh instance, but used to '
'be shared, will share', self._activity_id) 'be shared, will share', self._activity_id)
# no existing mesh instance, but activity used to be shared, so # no existing mesh instance, but activity used to be shared, so
# restart the share # restart the share
if share_scope == SCOPE_INVITE_ONLY: if share_scope == SCOPE_INVITE_ONLY:
@ -470,8 +470,8 @@ class Activity(Window, Gtk.Container):
self._max_participants = participants self._max_participants = participants
max_participants = GObject.property( max_participants = GObject.property(
type=int, default=0, getter=get_max_participants, type=int, default=0, getter=get_max_participants,
setter=set_max_participants) setter=set_max_participants)
def get_id(self): def get_id(self):
"""Returns the activity id of the current instance of your activity. """Returns the activity id of the current instance of your activity.
@ -630,7 +630,7 @@ class Activity(Window, Gtk.Container):
if self._jobject: if self._jobject:
if self._owns_file and os.path.isfile(self._jobject.file_path): if self._owns_file and os.path.isfile(self._jobject.file_path):
logging.debug('_cleanup_jobject: removing %r', logging.debug('_cleanup_jobject: removing %r',
self._jobject.file_path) self._jobject.file_path)
os.remove(self._jobject.file_path) os.remove(self._jobject.file_path)
self._owns_file = False self._owns_file = False
self._jobject.destroy() self._jobject.destroy()
@ -752,9 +752,9 @@ class Activity(Window, Gtk.Container):
else: else:
self._updating_jobject = True self._updating_jobject = True
datastore.write(self._jobject, datastore.write(self._jobject,
transfer_ownership=True, transfer_ownership=True,
reply_handler=self.__save_cb, reply_handler=self.__save_cb,
error_handler=self.__save_error_cb) error_handler=self.__save_error_cb)
def copy(self): def copy(self):
"""Request that the activity 'Keep in Journal' the current state """Request that the activity 'Keep in Journal' the current state
@ -803,7 +803,7 @@ class Activity(Window, Gtk.Container):
def __share_cb(self, ps, success, activity, err): def __share_cb(self, ps, success, activity, err):
if not success: if not success:
logging.debug('Share of activity %s failed: %s.', logging.debug('Share of activity %s failed: %s.',
self._activity_id, err) self._activity_id, err)
return return
logging.debug('Share of activity %s successful, PS activity is %r.', logging.debug('Share of activity %s successful, PS activity is %r.',
@ -813,7 +813,7 @@ class Activity(Window, Gtk.Container):
self.shared_activity = activity self.shared_activity = activity
self.shared_activity.connect('notify::private', self.shared_activity.connect('notify::private',
self.__privacy_changed_cb) self.__privacy_changed_cb)
self.emit('shared') self.emit('shared')
self.__privacy_changed_cb(self.shared_activity, None) self.__privacy_changed_cb(self.shared_activity, None)
@ -830,7 +830,7 @@ class Activity(Window, Gtk.Container):
buddy = pservice.get_buddy(account_path, contact_id) buddy = pservice.get_buddy(account_path, contact_id)
if buddy: if buddy:
self.shared_activity.invite( self.shared_activity.invite(
buddy, '', self._invite_response_cb) buddy, '', self._invite_response_cb)
else: else:
logging.error('Cannot invite %s %s, no such buddy', logging.error('Cannot invite %s %s, no such buddy',
account_path, contact_id) account_path, contact_id)
@ -845,7 +845,7 @@ class Activity(Window, Gtk.Container):
self._invites_queue.append((account_path, contact_id)) self._invites_queue.append((account_path, contact_id))
if (self.shared_activity is None if (self.shared_activity is None
or not self.shared_activity.props.joined): or not self.shared_activity.props.joined):
self.share(True) self.share(True)
else: else:
self._send_invites() self._send_invites()
@ -864,7 +864,7 @@ class Activity(Window, Gtk.Container):
self._activity_id) self._activity_id)
verb = private and 'private' or 'public' verb = private and 'private' or 'public'
logging.debug('Requesting %s share of activity %s.', verb, logging.debug('Requesting %s share of activity %s.', verb,
self._activity_id) self._activity_id)
pservice = presenceservice.get_instance() pservice = presenceservice.get_instance()
pservice.connect('activity-shared', self.__share_cb) pservice.connect('activity-shared', self.__share_cb)
pservice.share_activity(self, private=private) pservice.share_activity(self, private=private)
@ -875,7 +875,8 @@ class Activity(Window, Gtk.Container):
alert.props.msg = _('Keep error: all changes will be lost') alert.props.msg = _('Keep error: all changes will be lost')
cancel_icon = Icon(icon_name='dialog-cancel') cancel_icon = Icon(icon_name='dialog-cancel')
alert.add_button(Gtk.ResponseType.CANCEL, _('Don\'t stop'), cancel_icon) alert.add_button(Gtk.ResponseType.CANCEL, _('Don\'t stop'),
cancel_icon)
stop_icon = Icon(icon_name='dialog-ok') stop_icon = Icon(icon_name='dialog-ok')
alert.add_button(Gtk.ResponseType.OK, _('Stop anyway'), stop_icon) alert.add_button(Gtk.ResponseType.OK, _('Stop anyway'), stop_icon)
@ -997,17 +998,17 @@ class _ClientHandler(dbus.service.Object, DBusProperties):
self._implement_property_get(CLIENT, { self._implement_property_get(CLIENT, {
'Interfaces': lambda: list(self._interfaces), 'Interfaces': lambda: list(self._interfaces),
}) })
self._implement_property_get(CLIENT_HANDLER, { self._implement_property_get(CLIENT_HANDLER, {
'HandlerChannelFilter': self.__get_filters_cb, 'HandlerChannelFilter': self.__get_filters_cb,
}) })
def __get_filters_cb(self): def __get_filters_cb(self):
logging.debug('__get_filters_cb') logging.debug('__get_filters_cb')
filters = { filters = {
CHANNEL + '.ChannelType': CHANNEL_TYPE_TEXT, CHANNEL + '.ChannelType': CHANNEL_TYPE_TEXT,
CHANNEL + '.TargetHandleType': CONNECTION_HANDLE_TYPE_CONTACT, CHANNEL + '.TargetHandleType': CONNECTION_HANDLE_TYPE_CONTACT,
} }
filter_dict = dbus.Dictionary(filters, signature='sv') filter_dict = dbus.Dictionary(filters, signature='sv')
logging.debug('__get_filters_cb %r', dbus.Array([filter_dict], logging.debug('__get_filters_cb %r', dbus.Array([filter_dict],
signature='a{sv}')) signature='a{sv}'))
@ -1016,10 +1017,10 @@ class _ClientHandler(dbus.service.Object, DBusProperties):
@dbus.service.method(dbus_interface=CLIENT_HANDLER, @dbus.service.method(dbus_interface=CLIENT_HANDLER,
in_signature='ooa(oa{sv})aota{sv}', out_signature='') in_signature='ooa(oa{sv})aota{sv}', out_signature='')
def HandleChannels(self, account, connection, channels, requests_satisfied, def HandleChannels(self, account, connection, channels, requests_satisfied,
user_action_time, handler_info): user_action_time, handler_info):
logging.debug('HandleChannels\n\t%r\n\t%r\n\t%r\n\t%r\n\t%r\n\t%r', logging.debug('HandleChannels\n\t%r\n\t%r\n\t%r\n\t%r\n\t%r\n\t%r',
account, connection, channels, requests_satisfied, account, connection, channels, requests_satisfied,
user_action_time, handler_info) user_action_time, handler_info)
try: try:
for object_path, properties in channels: for object_path, properties in channels:
channel_type = properties[CHANNEL + '.ChannelType'] channel_type = properties[CHANNEL + '.ChannelType']

View File

@ -96,7 +96,7 @@ def get_environment(activity):
if activity.get_path().startswith(env.get_user_activities_path()): if activity.get_path().startswith(env.get_user_activities_path()):
environ['SUGAR_LOCALEDIR'] = os.path.join(activity.get_path(), environ['SUGAR_LOCALEDIR'] = os.path.join(activity.get_path(),
'locale') 'locale')
return environ return environ
@ -200,10 +200,12 @@ class ActivityCreationHandler(GObject.GObject):
self._launch_activity() self._launch_activity()
def _launch_activity(self): def _launch_activity(self):
if self._handle.activity_id != None: if self._handle.activity_id is not None:
self._shell.ActivateActivity(self._handle.activity_id, self._shell.ActivateActivity(self._handle.activity_id,
reply_handler=self._activate_reply_handler, reply_handler=
error_handler=self._activate_error_handler) self._activate_reply_handler,
error_handler=
self._activate_error_handler)
else: else:
self._create_activity() self._create_activity()
@ -212,9 +214,9 @@ class ActivityCreationHandler(GObject.GObject):
self._handle.activity_id = create_activity_id() self._handle.activity_id = create_activity_id()
self._shell.NotifyLaunch( self._shell.NotifyLaunch(
self._service_name, self._handle.activity_id, self._service_name, self._handle.activity_id,
reply_handler=self._no_reply_handler, reply_handler=self._no_reply_handler,
error_handler=self._notify_launch_error_handler) error_handler=self._notify_launch_error_handler)
environ = get_environment(self._bundle) environ = get_environment(self._bundle)
(log_path, log_file) = open_log_file(self._bundle) (log_path, log_file) = open_log_file(self._bundle)
@ -225,7 +227,7 @@ class ActivityCreationHandler(GObject.GObject):
dev_null = file('/dev/null', 'w') dev_null = file('/dev/null', 'w')
environment_dir = None environment_dir = None
rainbow_found = subprocess.call(['which', 'rainbow-run'], rainbow_found = subprocess.call(['which', 'rainbow-run'],
stdout=dev_null, stderr=dev_null) == 0 stdout=dev_null, stderr=dev_null) == 0
use_rainbow = rainbow_found and os.path.exists('/etc/olpc-security') use_rainbow = rainbow_found and os.path.exists('/etc/olpc-security')
if use_rainbow: if use_rainbow:
environment_dir = tempfile.mkdtemp() environment_dir = tempfile.mkdtemp()
@ -241,7 +243,7 @@ class ActivityCreationHandler(GObject.GObject):
'-i', environ['SUGAR_BUNDLE_ID'], '-i', environ['SUGAR_BUNDLE_ID'],
'-e', environment_dir, '-e', environment_dir,
'--', '--',
] + command ] + command
for key, value in environ.items(): for key, value in environ.items():
file_path = os.path.join(environment_dir, str(key)) file_path = os.path.join(environment_dir, str(key))
@ -251,12 +253,12 @@ class ActivityCreationHandler(GObject.GObject):
dev_null = file('/dev/null', 'r') dev_null = file('/dev/null', 'r')
child = subprocess.Popen([str(s) for s in command], child = subprocess.Popen([str(s) for s in command],
env=environ, env=environ,
cwd=str(self._bundle.get_path()), cwd=str(self._bundle.get_path()),
close_fds=True, close_fds=True,
stdin=dev_null.fileno(), stdin=dev_null.fileno(),
stdout=log_file.fileno(), stdout=log_file.fileno(),
stderr=log_file.fileno()) stderr=log_file.fileno())
GObject.child_watch_add(child.pid, GObject.child_watch_add(child.pid,
_child_watch_cb, _child_watch_cb,
@ -281,11 +283,11 @@ class ActivityCreationHandler(GObject.GObject):
def _create_reply_handler(self): def _create_reply_handler(self):
logging.debug('Activity created %s (%s).', logging.debug('Activity created %s (%s).',
self._handle.activity_id, self._service_name) self._handle.activity_id, self._service_name)
def _create_error_handler(self, err): def _create_error_handler(self, err):
logging.error("Couldn't create activity %s (%s): %s", logging.error("Couldn't create activity %s (%s): %s",
self._handle.activity_id, self._service_name, err) self._handle.activity_id, self._service_name, err)
self._shell.NotifyLaunchFailure( self._shell.NotifyLaunchFailure(
self._handle.activity_id, reply_handler=self._no_reply_handler, self._handle.activity_id, reply_handler=self._no_reply_handler,
error_handler=self._notify_launch_failure_error_handler) error_handler=self._notify_launch_failure_error_handler)
@ -370,5 +372,5 @@ def _child_watch_cb(pid, condition, user_data):
# TODO send launching failure but activity could already show # TODO send launching failure but activity could already show
# main window, see http://bugs.sugarlabs.org/ticket/1447#comment:19 # main window, see http://bugs.sugarlabs.org/ticket/1447#comment:19
shell.NotifyLaunchFailure(activity_id, shell.NotifyLaunchFailure(activity_id,
reply_handler=reply_handler_cb, reply_handler=reply_handler_cb,
error_handler=error_handler_cb) error_handler=error_handler_cb)

View File

@ -69,7 +69,7 @@ class ActivityHandle(object):
def create_from_dict(handle_dict): def create_from_dict(handle_dict):
"""Create a handle from a dictionary of parameters""" """Create a handle from a dictionary of parameters"""
result = ActivityHandle(handle_dict['activity_id'], result = ActivityHandle(handle_dict['activity_id'],
object_id=handle_dict.get('object_id'), object_id=handle_dict.get('object_id'),
uri=handle_dict.get('uri'), uri=handle_dict.get('uri'),
invited=handle_dict.get('invited')) invited=handle_dict.get('invited'))
return result return result

View File

@ -160,16 +160,16 @@ class Packager(object):
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
cwd=self.config.source_dir) cwd=self.config.source_dir)
except OSError: except OSError:
logging.warn('Packager: git is not installed, ' \ logging.warn('Packager: git is not installed, '
'fall back to filtered list') 'fall back to filtered list')
return list_files(self.config.source_dir, return list_files(self.config.source_dir,
IGNORE_DIRS, IGNORE_FILES) IGNORE_DIRS, IGNORE_FILES)
stdout, _ = git_ls.communicate() stdout, _ = git_ls.communicate()
if git_ls.returncode: if git_ls.returncode:
# Fall back to filtered list # Fall back to filtered list
logging.warn('Packager: this is not a git repository, ' \ logging.warn('Packager: this is not a git repository, '
'fall back to filtered list') 'fall back to filtered list')
return list_files(self.config.source_dir, return list_files(self.config.source_dir,
IGNORE_DIRS, IGNORE_FILES) IGNORE_DIRS, IGNORE_FILES)
@ -363,7 +363,7 @@ def cmd_genpot(config, args):
f.close() f.close()
args = ['xgettext', '--join-existing', '--language=Python', args = ['xgettext', '--join-existing', '--language=Python',
'--keyword=_', '--add-comments=TRANS:', '--output=%s' % pot_file] '--keyword=_', '--add-comments=TRANS:', '--output=%s' % pot_file]
args += python_files args += python_files
retcode = subprocess.call(args) retcode = subprocess.call(args)

View File

@ -53,7 +53,7 @@ def _extract_header(file_path):
version_, num_of_strings = _read_bin(handle, format_string, 8) version_, num_of_strings = _read_bin(handle, format_string, 8)
msgids_hash_offset, msgstrs_hash_offset = _read_bin(handle, \ msgids_hash_offset, msgstrs_hash_offset = _read_bin(handle,
format_string, 8) format_string, 8)
handle.seek(msgids_hash_offset) handle.seek(msgids_hash_offset)
@ -142,9 +142,9 @@ def get_locale_path(bundle_id):
for candidate_dir in candidate_dirs.keys(): for candidate_dir in candidate_dirs.keys():
if os.path.exists(candidate_dir): if os.path.exists(candidate_dir):
full_path = os.path.join(candidate_dir, \ full_path = os.path.join(candidate_dir,
default_locale, 'LC_MESSAGES', \ default_locale, 'LC_MESSAGES',
bundle_id + '.mo') bundle_id + '.mo')
if os.path.exists(full_path): if os.path.exists(full_path):
try: try:
candidate_dirs[candidate_dir] = \ candidate_dirs[candidate_dir] = \
@ -154,7 +154,7 @@ def get_locale_path(bundle_id):
# Set lowest priority # Set lowest priority
candidate_dirs[candidate_dir] = -1 candidate_dirs[candidate_dir] = -1
available_paths = sorted(candidate_dirs.iteritems(), key=lambda (k, v): \ available_paths = sorted(candidate_dirs.iteritems(), key=lambda (k, v):
(v, k), reverse=True) (v, k), reverse=True)
preferred_path = available_paths[0][0] preferred_path = available_paths[0][0]
return preferred_path return preferred_path

View File

@ -129,14 +129,14 @@ class ShareButton(RadioMenuButton):
palette = RadioPalette() palette = RadioPalette()
self.private = RadioToolButton( self.private = RadioToolButton(
icon_name='zoom-home') icon_name='zoom-home')
palette.append(self.private, _('Private')) palette.append(self.private, _('Private'))
self.neighborhood = RadioToolButton( self.neighborhood = RadioToolButton(
icon_name='zoom-neighborhood', icon_name='zoom-neighborhood',
group=self.private) group=self.private)
self._neighborhood_handle = self.neighborhood.connect( self._neighborhood_handle = self.neighborhood.connect(
'clicked', self.__neighborhood_clicked_cb, activity) 'clicked', self.__neighborhood_clicked_cb, activity)
palette.append(self.neighborhood, _('My Neighborhood')) palette.append(self.neighborhood, _('My Neighborhood'))
activity.connect('shared', self.__update_share_cb) activity.connect('shared', self.__update_share_cb)
@ -175,7 +175,8 @@ class TitleEntry(Gtk.ToolItem):
self.entry = Gtk.Entry(**kwargs) self.entry = Gtk.Entry(**kwargs)
self.entry.set_size_request(int(Gdk.Screen.width() / 3), -1) self.entry.set_size_request(int(Gdk.Screen.width() / 3), -1)
self.entry.set_text(activity.metadata['title']) self.entry.set_text(activity.metadata['title'])
self.entry.connect('focus-out-event', self.__title_changed_cb, activity) self.entry.connect(
'focus-out-event', self.__title_changed_cb, activity)
self.entry.connect('button-press-event', self.__button_press_event_cb) self.entry.connect('button-press-event', self.__button_press_event_cb)
self.entry.show() self.entry.show()
self.add(self.entry) self.add(self.entry)
@ -250,7 +251,7 @@ class DescriptionItem(ToolButton):
text_buffer.set_text(activity.metadata['description']) text_buffer.set_text(activity.metadata['description'])
self._text_view.set_buffer(text_buffer) self._text_view.set_buffer(text_buffer)
self._text_view.connect('focus-out-event', self._text_view.connect('focus-out-event',
self.__description_changed_cb, activity) self.__description_changed_cb, activity)
sw.add(self._text_view) sw.add(self._text_view)
description_box.append_item(sw, vertical_padding=0) description_box.append_item(sw, vertical_padding=0)
self._palette.set_content(description_box) self._palette.set_content(description_box)
@ -322,7 +323,7 @@ class ActivityToolbar(Gtk.Toolbar):
self.insert(title_button, -1) self.insert(title_button, -1)
self.title = title_button.entry self.title = title_button.entry
if orientation_left == False: if not orientation_left:
separator = Gtk.SeparatorToolItem() separator = Gtk.SeparatorToolItem()
separator.props.draw = False separator.props.draw = False
separator.set_expand(True) separator.set_expand(True)