[Sugar-devel] [PATCH sugar v2 02/21] style cleanup: move globals before class and method definitions

Sascha Silbe sascha-pgp at silbe.org
Fri Nov 19 16:13:10 EST 2010


This only touches the globals that were flagged by pep8 due to white space
issues or contain "instance" in their name (singleton pattern).

I've also left the sunflower layout variables alone. AFAICT this layout is
currently unused and should be removed instead (or factored out like the snow
flake layout and reenabled).

Reviewed-by: James Cameron <quozl at laptop.org>
CC: Aleksey Lim <alsroot at member.fsf.org>
Signed-off-by: Sascha Silbe <sascha-pgp at silbe.org>

diff --git a/src/jarabe/desktop/favoritesview.py b/src/jarabe/desktop/favoritesview.py
index ada55e0..d582433 100644
--- a/src/jarabe/desktop/favoritesview.py
+++ b/src/jarabe/desktop/favoritesview.py
@@ -61,6 +61,9 @@ LAYOUT_MAP = {favoriteslayout.RingLayout.key: favoriteslayout.RingLayout,
 `FavoritesLayout` which implement the layouts.  Additional information
 about the layout can be accessed with fields of the class."""
 
+_favorites_settings = None
+
+
 class FavoritesView(hippo.Canvas):
     __gtype_name__ = 'SugarFavoritesView'
 
@@ -659,7 +662,6 @@ class FavoritesSetting(object):
 
     layout = property(get_layout, set_layout)
 
-_favorites_settings = None
 
 def get_settings():
     global _favorites_settings
diff --git a/src/jarabe/desktop/homewindow.py b/src/jarabe/desktop/homewindow.py
index fec4289..ae970be 100644
--- a/src/jarabe/desktop/homewindow.py
+++ b/src/jarabe/desktop/homewindow.py
@@ -33,6 +33,9 @@ _GROUP_PAGE      = 1
 _MESH_PAGE       = 2
 _TRANSITION_PAGE = 3
 
+_instance = None
+
+
 class HomeWindow(gtk.Window):
     def __init__(self):
         logging.debug('STARTUP: Loading the desktop window')
@@ -183,7 +186,6 @@ class HomeWindow(gtk.Window):
     def get_home_box(self):
         return self._home_box
 
-_instance = None
 
 def get_instance():
     global _instance
diff --git a/src/jarabe/desktop/keydialog.py b/src/jarabe/desktop/keydialog.py
index 1e6d17a..a83f77b 100644
--- a/src/jarabe/desktop/keydialog.py
+++ b/src/jarabe/desktop/keydialog.py
@@ -27,6 +27,11 @@ from jarabe.model.network import Secrets
 IW_AUTH_ALG_OPEN_SYSTEM = 'open'
 IW_AUTH_ALG_SHARED_KEY  = 'shared'
 
+WEP_PASSPHRASE = 1
+WEP_HEX = 2
+WEP_ASCII = 3
+
+
 def string_is_hex(key):
     is_hex = True
     for c in key:
@@ -108,9 +113,6 @@ class KeyDialog(gtk.Dialog):
     def get_response_object(self):
         return self._response
 
-WEP_PASSPHRASE = 1
-WEP_HEX = 2
-WEP_ASCII = 3
 
 class WEPKeyDialog(KeyDialog):
     def __init__(self, ssid, flags, wpa_flags, rsn_flags, dev_caps, settings,
diff --git a/src/jarabe/desktop/meshbox.py b/src/jarabe/desktop/meshbox.py
index 036f00a..18e3b1c 100644
--- a/src/jarabe/desktop/meshbox.py
+++ b/src/jarabe/desktop/meshbox.py
@@ -59,6 +59,9 @@ _NM_ACTIVE_CONN_IFACE = 'org.freedesktop.NetworkManager.Connection.Active'
 _AP_ICON_NAME = 'network-wireless'
 _OLPC_MESH_ICON_NAME = 'network-mesh'
 
+_AUTOSEARCH_TIMEOUT = 1000
+
+
 class ActivityView(hippo.CanvasBox):
     def __init__(self, model):
         hippo.CanvasBox.__init__(self)
@@ -148,8 +151,6 @@ class ActivityView(hippo.CanvasBox):
             if hasattr(icon, 'set_filter'):
                 icon.set_filter(query)
 
-_AUTOSEARCH_TIMEOUT = 1000
-
 
 class MeshToolbar(gtk.Toolbar):
     __gtype_name__ = 'MeshToolbar'
diff --git a/src/jarabe/frame/clipboard.py b/src/jarabe/frame/clipboard.py
index 3b9f745..8e237dd 100644
--- a/src/jarabe/frame/clipboard.py
+++ b/src/jarabe/frame/clipboard.py
@@ -26,6 +26,10 @@ from sugar import mime
 
 from jarabe.frame.clipboardobject import ClipboardObject, Format
 
+
+_instance = None
+
+
 class Clipboard(gobject.GObject):
 
     __gsignals__ = {
@@ -140,7 +144,6 @@ class Clipboard(gobject.GObject):
 
         return 'file://' + new_file_path
 
-_instance = None
 
 def get_instance():
     global _instance
diff --git a/src/jarabe/journal/journalactivity.py b/src/jarabe/journal/journalactivity.py
index beb0962..3b6fed9 100644
--- a/src/jarabe/journal/journalactivity.py
+++ b/src/jarabe/journal/journalactivity.py
@@ -53,6 +53,9 @@ J_DBUS_PATH = '/org/laptop/Journal'
 _SPACE_TRESHOLD = 52428800
 _BUNDLE_ID = 'org.laptop.JournalActivity'
 
+_journal = None
+
+
 class JournalActivityDBusService(dbus.service.Object):
     def __init__(self, parent):
         self._parent = parent
@@ -359,7 +362,6 @@ class JournalActivity(JournalWindow):
         self.show_main_view()
         self.search_grab_focus()
 
-_journal = None
 
 def get_journal():
     global _journal
diff --git a/src/jarabe/journal/model.py b/src/jarabe/journal/model.py
index 81ca7d4..bbc3778 100644
--- a/src/jarabe/journal/model.py
+++ b/src/jarabe/journal/model.py
@@ -44,6 +44,12 @@ PROPERTIES = ['uid', 'title', 'mtime', 'timestamp', 'creation_time', 'filesize',
 MIN_PAGES_TO_CACHE = 3
 MAX_PAGES_TO_CACHE = 5
 
+_datastore = None
+created = dispatch.Signal()
+updated = dispatch.Signal()
+deleted = dispatch.Signal()
+
+
 class _Cache(object):
 
     __gtype_name__ = 'model_Cache'
@@ -356,7 +362,7 @@ def _get_file_metadata(path, stat):
             'icon-color': client.get_string('/desktop/sugar/user/color'),
             'description': path}
 
-_datastore = None
+
 def _get_datastore():
     global _datastore
     if _datastore is None:
@@ -541,7 +547,3 @@ def _get_unique_file_name(mount_point, file_name):
 def is_editable(metadata):
     mountpoint = metadata.get('mountpoint', '/')
     return mountpoint == '/'
-
-created = dispatch.Signal()
-updated = dispatch.Signal()
-deleted = dispatch.Signal()
diff --git a/src/jarabe/model/adhoc.py b/src/jarabe/model/adhoc.py
index ad0c941..99fc880 100644
--- a/src/jarabe/model/adhoc.py
+++ b/src/jarabe/model/adhoc.py
@@ -32,8 +32,9 @@ _NM_WIRELESS_IFACE = 'org.freedesktop.NetworkManager.Device.Wireless'
 _NM_ACCESSPOINT_IFACE = 'org.freedesktop.NetworkManager.AccessPoint'
 _NM_ACTIVE_CONN_IFACE = 'org.freedesktop.NetworkManager.Connection.Active'
 
-
 _adhoc_manager_instance = None
+
+
 def get_adhoc_manager_instance():
     global _adhoc_manager_instance
     if _adhoc_manager_instance is None:
diff --git a/src/jarabe/model/buddy.py b/src/jarabe/model/buddy.py
index 5f3176e..46a9366 100644
--- a/src/jarabe/model/buddy.py
+++ b/src/jarabe/model/buddy.py
@@ -30,6 +30,9 @@ from jarabe.util.telepathy import connection_watcher
 
 CONNECTION_INTERFACE_BUDDY_INFO = 'org.laptop.Telepathy.BuddyInfo'
 
+_owner_instance = None
+
+
 class BaseBuddyModel(gobject.GObject):
     __gtype_name__ = 'SugarBaseBuddyModel'
 
@@ -180,7 +183,6 @@ class OwnerBuddyModel(BaseBuddyModel):
         return True
 
 
-_owner_instance = None
 def get_owner_instance():
     global _owner_instance
     if _owner_instance is None:
diff --git a/src/jarabe/model/bundleregistry.py b/src/jarabe/model/bundleregistry.py
index 4de7e3f..8e037a8 100644
--- a/src/jarabe/model/bundleregistry.py
+++ b/src/jarabe/model/bundleregistry.py
@@ -34,6 +34,10 @@ from sugar import env
 from jarabe import config
 from jarabe.model import mimeregistry
 
+
+_instance = None
+
+
 class BundleRegistry(gobject.GObject):
     """Tracks the available activity bundles"""
 
@@ -449,7 +453,6 @@ class BundleRegistry(gobject.GObject):
 
         self.install(bundle)
 
-_instance = None
 
 def get_registry():
     global _instance
diff --git a/src/jarabe/model/filetransfer.py b/src/jarabe/model/filetransfer.py
index 0d21793..7d2d5dd 100644
--- a/src/jarabe/model/filetransfer.py
+++ b/src/jarabe/model/filetransfer.py
@@ -52,6 +52,9 @@ FT_REASON_REMOTE_ERROR = 6
 CHANNEL_TYPE_FILE_TRANSFER = \
         'org.freedesktop.Telepathy.Channel.Type.FileTransfer'
 
+new_file_transfer = dispatch.Signal()
+
+
 # TODO Move to use splice_async() in Sugar 0.88
 class StreamSplicer(gobject.GObject):
     _CHUNK_SIZE = 10240 # 10K
@@ -337,7 +340,6 @@ def file_transfer_available():
 
         return False
 
-new_file_transfer = dispatch.Signal()
 
 if __name__ == '__main__':
     import tempfile
diff --git a/src/jarabe/model/friends.py b/src/jarabe/model/friends.py
index 98bff96..ffd655b 100644
--- a/src/jarabe/model/friends.py
+++ b/src/jarabe/model/friends.py
@@ -27,6 +27,10 @@ from sugar.graphics.xocolor import XoColor
 from jarabe.model.buddy import BuddyModel
 from jarabe.model import neighborhood
 
+
+_model = None
+
+
 class FriendBuddyModel(BuddyModel):
     __gtype_name__ = 'SugarFriendBuddyModel'
 
@@ -176,7 +180,6 @@ class Friends(gobject.GObject):
                 reply_handler=friends_synced,
                 error_handler=friends_synced_error)
 
-_model = None
 
 def get_model():
     global _model
diff --git a/src/jarabe/model/invites.py b/src/jarabe/model/invites.py
index e5a4d9d..7020b8f 100644
--- a/src/jarabe/model/invites.py
+++ b/src/jarabe/model/invites.py
@@ -41,6 +41,8 @@ from jarabe.journal import misc
 CONNECTION_INTERFACE_ACTIVITY_PROPERTIES = \
         'org.laptop.Telepathy.ActivityProperties'
 
+_instance = None
+
 
 class ActivityInvite(object):
     """Invitation to a shared activity."""
@@ -230,8 +232,6 @@ class Invites(gobject.GObject):
         return self._dispatch_operations.values().__iter__()
 
 
-_instance = None
-
 def get_instance():
     global _instance
     if not _instance:
diff --git a/src/jarabe/model/mimeregistry.py b/src/jarabe/model/mimeregistry.py
index 537f6f3..7fb5bcf 100644
--- a/src/jarabe/model/mimeregistry.py
+++ b/src/jarabe/model/mimeregistry.py
@@ -21,6 +21,7 @@ import gconf
 
 _DEFAULTS_KEY = '/desktop/sugar/journal/defaults'
 _GCONF_INVALID_CHARS = re.compile('[^a-zA-Z0-9-_/.]')
+
 _instance = None
 
 
diff --git a/src/jarabe/model/neighborhood.py b/src/jarabe/model/neighborhood.py
index 91dd059..3885b38 100644
--- a/src/jarabe/model/neighborhood.py
+++ b/src/jarabe/model/neighborhood.py
@@ -65,6 +65,9 @@ Time in seconds to wait when querying contact properties. Some jabber servers
 will be very slow in returning these queries, so just be patient.
 """
 
+_model = None
+
+
 class ActivityModel(gobject.GObject):
     __gsignals__ = {
         'current-buddy-added':   (gobject.SIGNAL_RUN_FIRST,
@@ -987,7 +990,6 @@ class Neighborhood(gobject.GObject):
     def get_activities(self):
         return self._activities.values()
 
-_model = None
 
 def get_model():
     global _model
diff --git a/src/jarabe/model/notifications.py b/src/jarabe/model/notifications.py
index f2e2d65..b5a6822 100644
--- a/src/jarabe/model/notifications.py
+++ b/src/jarabe/model/notifications.py
@@ -27,6 +27,9 @@ _DBUS_SERVICE = "org.freedesktop.Notifications"
 _DBUS_IFACE = "org.freedesktop.Notifications"
 _DBUS_PATH = "/org/freedesktop/Notifications"
 
+_instance = None
+
+
 class NotificationService(dbus.service.Object):
     def __init__(self):
         bus = dbus.SessionBus()
@@ -82,7 +85,6 @@ class NotificationService(dbus.service.Object):
     def ActionInvoked(self, notification_id, action_key):
         pass
 
-_instance = None
 
 def get_service():
     global _instance
diff --git a/src/jarabe/model/shell.py b/src/jarabe/model/shell.py
index db0e050..65d1c26 100644
--- a/src/jarabe/model/shell.py
+++ b/src/jarabe/model/shell.py
@@ -35,6 +35,8 @@ _SERVICE_NAME = "org.laptop.Activity"
 _SERVICE_PATH = "/org/laptop/Activity"
 _SERVICE_INTERFACE = "org.laptop.Activity"
 
+_model = None
+
 
 class Activity(gobject.GObject):
     """Activity which appears in the "Home View" of the Sugar shell
@@ -631,8 +633,6 @@ class ShellModel(gobject.GObject):
         return False
 
 
-_model = None
-
 def get_model():
     global _model
     if _model is None:
diff --git a/src/jarabe/model/sound.py b/src/jarabe/model/sound.py
index 65090a4..16e69b5 100644
--- a/src/jarabe/model/sound.py
+++ b/src/jarabe/model/sound.py
@@ -25,6 +25,9 @@ VOLUME_STEP = 10
 muted_changed = dispatch.Signal()
 volume_changed = dispatch.Signal()
 
+_volume = _sugarext.VolumeAlsa()
+
+
 def get_muted():
     return _volume.get_mute()
 
@@ -54,5 +57,3 @@ def restore():
     if env.is_emulator() is False:
         client = gconf.client_get_default()
         set_volume(client.get_int('/desktop/sugar/sound/volume'))
-
-_volume = _sugarext.VolumeAlsa()
diff --git a/src/jarabe/model/telepathyclient.py b/src/jarabe/model/telepathyclient.py
index f4eccc3..189e344 100644
--- a/src/jarabe/model/telepathyclient.py
+++ b/src/jarabe/model/telepathyclient.py
@@ -29,6 +29,9 @@ from sugar import dispatch
 SUGAR_CLIENT_SERVICE = 'org.freedesktop.Telepathy.Client.Sugar'
 SUGAR_CLIENT_PATH = '/org/freedesktop/Telepathy/Client/Sugar'
 
+_instance = None
+
+
 class TelepathyClient(dbus.service.Object, DBusProperties):
     def __init__(self):
         self._interfaces = set([CLIENT, CLIENT_HANDLER,
@@ -91,7 +94,6 @@ class TelepathyClient(dbus.service.Object, DBusProperties):
         except Exception, e:
             logging.exception(e)
 
-_instance = None
 
 def get_instance():
     global _instance
diff --git a/src/jarabe/util/emulator.py b/src/jarabe/util/emulator.py
index 9ab1979..b6ce9dc 100644
--- a/src/jarabe/util/emulator.py
+++ b/src/jarabe/util/emulator.py
@@ -30,9 +30,9 @@ from sugar import env
 
 ERROR_NO_DISPLAY = 30
 ERROR_NO_SERVER = 31
+default_dimensions = (800, 600)
 
 
-default_dimensions = (800, 600)
 def _run_xephyr(display, dpi, dimensions, fullscreen):
     cmd = [ 'Xephyr' ]
     cmd.append(':%d' % display)
diff --git a/src/jarabe/util/telepathy/connection_watcher.py b/src/jarabe/util/telepathy/connection_watcher.py
index 391bdd5..27ac018 100644
--- a/src/jarabe/util/telepathy/connection_watcher.py
+++ b/src/jarabe/util/telepathy/connection_watcher.py
@@ -28,6 +28,10 @@ from telepathy.interfaces import CONN_INTERFACE
 from telepathy.constants import CONNECTION_STATUS_CONNECTED, \
                                 CONNECTION_STATUS_DISCONNECTED
 
+
+_instance = None
+
+
 class ConnectionWatcher(gobject.GObject):
     __gsignals__ = {
         'connection-added': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
@@ -93,7 +97,6 @@ class ConnectionWatcher(gobject.GObject):
     def get_connections(self):
         return self._connections.values()
 
-_instance = None
 
 def get_instance():
     global _instance
diff --git a/src/jarabe/view/keyhandler.py b/src/jarabe/view/keyhandler.py
index 8a85ac7..93ddf47 100644
--- a/src/jarabe/view/keyhandler.py
+++ b/src/jarabe/view/keyhandler.py
@@ -67,6 +67,9 @@ SPEECH_DBUS_SERVICE = 'org.laptop.Speech'
 SPEECH_DBUS_PATH = '/org/laptop/Speech'
 SPEECH_DBUS_INTERFACE = 'org.laptop.Speech'
 
+_instance = None
+
+
 class KeyHandler(object):
     def __init__(self, frame):
         self._frame = frame
@@ -230,7 +233,6 @@ class KeyHandler(object):
             return True
         return False
 
-_instance = None
 
 def setup(frame):
     global _instance
-- 
1.7.2.3



More information about the Sugar-devel mailing list