pep8'd sugar3.activity

master
William Orr 11 years ago committed by Daniel Narvaez
parent 3e5c37f3f8
commit 8a6c935dd0

@ -67,9 +67,9 @@ import dbus.service
from dbus import PROPERTIES_IFACE
from telepathy.server import DBusProperties
from telepathy.interfaces import CHANNEL, \
CHANNEL_TYPE_TEXT, \
CLIENT, \
CLIENT_HANDLER
CHANNEL_TYPE_TEXT, \
CLIENT, \
CLIENT_HANDLER
from telepathy.constants import CONNECTION_HANDLE_TYPE_CONTACT
from telepathy.constants import CONNECTION_HANDLE_TYPE_ROOM
@ -111,7 +111,7 @@ class _ActivitySession(GObject.GObject):
self._xsmp_client = XSMPClient()
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.startup()
@ -346,8 +346,8 @@ class Activity(Window, Gtk.Container):
if handle.invited:
wait_loop = GObject.MainLoop()
self._client_handler = _ClientHandler(
self.get_bundle_id(),
partial(self.__got_channel_cb, wait_loop))
self.get_bundle_id(),
partial(self.__got_channel_cb, wait_loop))
# FIXME: The current API requires that self.shared_activity is set
# before exiting from __init__, so we wait until we have got the
# 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)
elif share_scope != SCOPE_PRIVATE:
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
# restart the share
if share_scope == SCOPE_INVITE_ONLY:
@ -470,8 +470,8 @@ class Activity(Window, Gtk.Container):
self._max_participants = participants
max_participants = GObject.property(
type=int, default=0, getter=get_max_participants,
setter=set_max_participants)
type=int, default=0, getter=get_max_participants,
setter=set_max_participants)
def get_id(self):
"""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._owns_file and os.path.isfile(self._jobject.file_path):
logging.debug('_cleanup_jobject: removing %r',
self._jobject.file_path)
self._jobject.file_path)
os.remove(self._jobject.file_path)
self._owns_file = False
self._jobject.destroy()
@ -752,9 +752,9 @@ class Activity(Window, Gtk.Container):
else:
self._updating_jobject = True
datastore.write(self._jobject,
transfer_ownership=True,
reply_handler=self.__save_cb,
error_handler=self.__save_error_cb)
transfer_ownership=True,
reply_handler=self.__save_cb,
error_handler=self.__save_error_cb)
def copy(self):
"""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):
if not success:
logging.debug('Share of activity %s failed: %s.',
self._activity_id, err)
self._activity_id, err)
return
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.connect('notify::private',
self.__privacy_changed_cb)
self.__privacy_changed_cb)
self.emit('shared')
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)
if buddy:
self.shared_activity.invite(
buddy, '', self._invite_response_cb)
buddy, '', self._invite_response_cb)
else:
logging.error('Cannot invite %s %s, no such buddy',
account_path, contact_id)
@ -845,7 +845,7 @@ class Activity(Window, Gtk.Container):
self._invites_queue.append((account_path, contact_id))
if (self.shared_activity is None
or not self.shared_activity.props.joined):
or not self.shared_activity.props.joined):
self.share(True)
else:
self._send_invites()
@ -864,7 +864,7 @@ class Activity(Window, Gtk.Container):
self._activity_id)
verb = private and 'private' or 'public'
logging.debug('Requesting %s share of activity %s.', verb,
self._activity_id)
self._activity_id)
pservice = presenceservice.get_instance()
pservice.connect('activity-shared', self.__share_cb)
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')
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')
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, {
'Interfaces': lambda: list(self._interfaces),
})
})
self._implement_property_get(CLIENT_HANDLER, {
'HandlerChannelFilter': self.__get_filters_cb,
})
})
def __get_filters_cb(self):
logging.debug('__get_filters_cb')
filters = {
CHANNEL + '.ChannelType': CHANNEL_TYPE_TEXT,
CHANNEL + '.TargetHandleType': CONNECTION_HANDLE_TYPE_CONTACT,
}
}
filter_dict = dbus.Dictionary(filters, signature='sv')
logging.debug('__get_filters_cb %r', dbus.Array([filter_dict],
signature='a{sv}'))
@ -1016,10 +1017,10 @@ class _ClientHandler(dbus.service.Object, DBusProperties):
@dbus.service.method(dbus_interface=CLIENT_HANDLER,
in_signature='ooa(oa{sv})aota{sv}', out_signature='')
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',
account, connection, channels, requests_satisfied,
user_action_time, handler_info)
account, connection, channels, requests_satisfied,
user_action_time, handler_info)
try:
for object_path, properties in channels:
channel_type = properties[CHANNEL + '.ChannelType']

@ -96,7 +96,7 @@ def get_environment(activity):
if activity.get_path().startswith(env.get_user_activities_path()):
environ['SUGAR_LOCALEDIR'] = os.path.join(activity.get_path(),
'locale')
'locale')
return environ
@ -200,10 +200,12 @@ class ActivityCreationHandler(GObject.GObject):
self._launch_activity()
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,
reply_handler=self._activate_reply_handler,
error_handler=self._activate_error_handler)
reply_handler=
self._activate_reply_handler,
error_handler=
self._activate_error_handler)
else:
self._create_activity()
@ -212,9 +214,9 @@ class ActivityCreationHandler(GObject.GObject):
self._handle.activity_id = create_activity_id()
self._shell.NotifyLaunch(
self._service_name, self._handle.activity_id,
reply_handler=self._no_reply_handler,
error_handler=self._notify_launch_error_handler)
self._service_name, self._handle.activity_id,
reply_handler=self._no_reply_handler,
error_handler=self._notify_launch_error_handler)
environ = get_environment(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')
environment_dir = None
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')
if use_rainbow:
environment_dir = tempfile.mkdtemp()
@ -241,7 +243,7 @@ class ActivityCreationHandler(GObject.GObject):
'-i', environ['SUGAR_BUNDLE_ID'],
'-e', environment_dir,
'--',
] + command
] + command
for key, value in environ.items():
file_path = os.path.join(environment_dir, str(key))
@ -251,12 +253,12 @@ class ActivityCreationHandler(GObject.GObject):
dev_null = file('/dev/null', 'r')
child = subprocess.Popen([str(s) for s in command],
env=environ,
cwd=str(self._bundle.get_path()),
close_fds=True,
stdin=dev_null.fileno(),
stdout=log_file.fileno(),
stderr=log_file.fileno())
env=environ,
cwd=str(self._bundle.get_path()),
close_fds=True,
stdin=dev_null.fileno(),
stdout=log_file.fileno(),
stderr=log_file.fileno())
GObject.child_watch_add(child.pid,
_child_watch_cb,
@ -281,11 +283,11 @@ class ActivityCreationHandler(GObject.GObject):
def _create_reply_handler(self):
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):
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._handle.activity_id, reply_handler=self._no_reply_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
# main window, see http://bugs.sugarlabs.org/ticket/1447#comment:19
shell.NotifyLaunchFailure(activity_id,
reply_handler=reply_handler_cb,
error_handler=error_handler_cb)
reply_handler=reply_handler_cb,
error_handler=error_handler_cb)

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

@ -160,16 +160,16 @@ class Packager(object):
stdout=subprocess.PIPE,
cwd=self.config.source_dir)
except OSError:
logging.warn('Packager: git is not installed, ' \
'fall back to filtered list')
logging.warn('Packager: git is not installed, '
'fall back to filtered list')
return list_files(self.config.source_dir,
IGNORE_DIRS, IGNORE_FILES)
stdout, _ = git_ls.communicate()
if git_ls.returncode:
# Fall back to filtered list
logging.warn('Packager: this is not a git repository, ' \
'fall back to filtered list')
logging.warn('Packager: this is not a git repository, '
'fall back to filtered list')
return list_files(self.config.source_dir,
IGNORE_DIRS, IGNORE_FILES)
@ -363,7 +363,7 @@ def cmd_genpot(config, args):
f.close()
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
retcode = subprocess.call(args)

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

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

Loading…
Cancel
Save