[d-feet] Check source for pep8
- From: Thomas Bechtold <toabctl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [d-feet] Check source for pep8
- Date: Wed, 15 May 2013 04:33:06 +0000 (UTC)
commit 62351612a4ccb779e1e80dbff848fa2dbaae8992
Author: Thomas Bechtold <thomasbechtold jpberlin de>
Date: Wed May 15 06:32:21 2013 +0200
Check source for pep8
configure.ac | 2 +
src/dfeet/addconnectiondialog.py | 9 ++--
src/dfeet/application.py | 12 +----
src/dfeet/bus_watch.py | 58 ++++++++++------------
src/dfeet/dbus_utils.py | 28 ++++++----
src/dfeet/executemethoddialog.py | 38 ++++++++------
src/dfeet/introspection.py | 98 ++++++++++++++++++++++---------------
src/dfeet/introspection_helper.py | 58 +++++++++++++--------
src/dfeet/settings.py | 33 ++++++------
src/dfeet/uiloader.py | 24 +++++-----
src/dfeet/wnck_utils.py | 16 +++---
src/tests/Makefile.am | 9 +++-
src/tests/tests.py | 23 ++++-----
13 files changed, 223 insertions(+), 185 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 0c4b151..2c099b9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -21,6 +21,8 @@ PKG_CHECK_MODULES(DFEET, [
gtk+-3.0 >= 3.6
])
+AC_CHECK_PROG([PEP8], [pep8], [yes])
+test -z "$PEP8" && AC_MSG_ERROR([pep8 binary not found but needed for testsuite])
# i18n stuff
IT_PROG_INTLTOOL([0.40.0])
diff --git a/src/dfeet/addconnectiondialog.py b/src/dfeet/addconnectiondialog.py
index a1a500c..87b71fb 100644
--- a/src/dfeet/addconnectiondialog.py
+++ b/src/dfeet/addconnectiondialog.py
@@ -2,6 +2,7 @@
from gi.repository import Gtk, Gio
from dfeet.uiloader import UILoader
+
class AddConnectionDialog:
def __init__(self, data_dir, parent, address_bus_history=[]):
@@ -12,7 +13,8 @@ class AddConnectionDialog:
#get the hbox and add address combo box with model
hbox1 = ui.get_widget('hbox1')
self.address_combo_box_store = Gtk.ListStore(str)
- self.address_combo_box = Gtk.ComboBox.new_with_model_and_entry(self.address_combo_box_store)
+ self.address_combo_box = Gtk.ComboBox.new_with_model_and_entry(
+ self.address_combo_box_store)
self.address_combo_box.set_entry_text_column(0)
self.label_status = ui.get_widget('label_status')
@@ -26,11 +28,10 @@ class AddConnectionDialog:
self.dialog.add_button('gtk-cancel', Gtk.ResponseType.CANCEL)
self.dialog.add_button('gtk-connect', Gtk.ResponseType.OK)
-
@property
def address(self):
tree_iter = self.address_combo_box.get_active_iter()
- if tree_iter != None:
+ if tree_iter is not None:
model = self.address_combo_box.get_model()
return model[tree_iter][0]
else:
@@ -51,7 +52,5 @@ class AddConnectionDialog:
else:
return Gtk.ResponseType.OK
-
def destroy(self):
self.dialog.destroy()
-
diff --git a/src/dfeet/application.py b/src/dfeet/application.py
index 0d3fbad..6835c50 100644
--- a/src/dfeet/application.py
+++ b/src/dfeet/application.py
@@ -14,6 +14,7 @@ class NotebookTabLabel(Gtk.Box):
__gsignals__ = {
"close-clicked": (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ()),
}
+
def __init__(self, label_text):
Gtk.Box.__init__(self)
self.set_orientation(Gtk.Orientation.HORIZONTAL)
@@ -78,34 +79,28 @@ class DFeetApp(Gtk.Application):
self.__systembus_connect_cb(None)
self.__sessionbus_connect_cb(None)
-
def on_application_activate_cb(self, data=None):
self.main_window.show()
self.add_window(self.main_window)
-
@property
def bus_history(self):
return self.__bus_history
-
@bus_history.setter
def bus_history(self, history_new):
self.__bus_history = history_new
-
def __systembus_connect_cb(self, action):
"""connect to system bus"""
bw = BusWatch(self.data_dir, Gio.BusType.SYSTEM)
self.__notebook_append_page(bw.paned_buswatch, "System Bus")
-
def __sessionbus_connect_cb(self, action):
"""connect to session bus"""
bw = BusWatch(self.data_dir, Gio.BusType.SESSION)
self.__notebook_append_page(bw.paned_buswatch, "Session Bus")
-
def __otherbus_connect_cb(self, action):
"""connect to other bus"""
dialog = AddConnectionDialog(self.data_dir, self.main_window, self.bus_history)
@@ -133,32 +128,27 @@ class DFeetApp(Gtk.Application):
print("can not connect to '%s': %s" % (address, str(e)))
dialog.destroy()
-
def __action_about_activate_cb(self, action):
"""show the about dialog"""
self.about_dialog.set_visible(True)
self.about_dialog.run()
self.about_dialog.set_visible(False)
-
def __notebook_append_page(self, widget, text):
"""add a page to the notebook"""
ntl = NotebookTabLabel(text)
page_nbr = self.notebook.append_page(widget, ntl)
ntl.connect("close-clicked", self.__notebook_page_close_clicked_cb, widget)
-
def __notebook_page_close_clicked_cb(self, button, widget):
"""remove a page from the notebook"""
nbr = self.notebook.page_num(widget)
self.notebook.remove_page(nbr)
-
def __close_cb(self, action):
"""quit program"""
self.__quit_dfeet(self.main_window, None)
-
def __quit_dfeet(self, main_window, event):
"""quit d-feet application and store some settings"""
settings = Settings.get_instance()
diff --git a/src/dfeet/bus_watch.py b/src/dfeet/bus_watch.py
index 5d4d4ac..4fbeb65 100644
--- a/src/dfeet/bus_watch.py
+++ b/src/dfeet/bus_watch.py
@@ -67,21 +67,22 @@ class BusWatch(object):
self.label_bus_name_selected_name = ui.get_widget('label_bus_name_selected_name')
self.label_bus_name_selected_pid = ui.get_widget('label_bus_name_selected_pid')
self.label_bus_name_selected_cmdline = ui.get_widget('label_bus_name_selected_cmdline')
- self.addr_info = None # hold the currently selected AddressInfo object
+ self.addr_info = None # hold the currently selected AddressInfo object
self.treeview.connect('cursor-changed',
- self.__tree_view_cursor_changed_cb)
+ self.__tree_view_cursor_changed_cb)
self.entry_filter.connect("changed",
self.__entry_filter_changed_cb)
-
#setup the conection
if self.address == Gio.BusType.SYSTEM or self.address == Gio.BusType.SESSION:
self.connection = Gio.bus_get_sync(self.address, None)
elif Gio.dbus_is_supported_address(self.address):
- self.connection = Gio.DBusConnection.new_for_address_sync(self.address,
-
Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT | Gio.DBusConnectionFlags.MESSAGE_BUS_CONNECTION,
- None, None)
+ self.connection = Gio.DBusConnection.new_for_address_sync(
+ self.address,
+ Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT |
+ Gio.DBusConnectionFlags.MESSAGE_BUS_CONNECTION,
+ None, None)
#setup signals
self.connection.signal_subscribe(None, "org.freedesktop.DBus", "NameOwnerChanged",
@@ -99,7 +100,6 @@ class BusWatch(object):
result_handler=self.__list_names_handler,
error_handler=self.__list_names_error_handler)
-
def __treemodelfilter_buswatch_cb(self, model, iter, user_data):
#return model.get_value(iter, 1) in data
bus_name_obj = model.get(iter, 0)[0]
@@ -109,7 +109,6 @@ class BusWatch(object):
def __entry_filter_changed_cb(self, entry_filter):
self.treemodelfilter_buswatch.refilter()
-
def __tree_view_cursor_changed_cb(self, treeview):
"""do something when a row is selected"""
selection = self.treeview.get_selection()
@@ -129,7 +128,8 @@ class BusWatch(object):
pass
#add Introspection to paned
- self.addr_info = AddressInfo(self.data_dir, self.address, bus_name_obj.bus_name_unique,
connection_is_bus=True)
+ self.addr_info = AddressInfo(
+ self.data_dir, self.address, bus_name_obj.bus_name_unique, connection_is_bus=True)
self.paned_buswatch.add2(self.addr_info.introspect_box)
#update info about selected bus name
@@ -138,17 +138,17 @@ class BusWatch(object):
self.label_bus_name_selected_cmdline.set_text(bus_name_obj.cmdline)
self.grid_bus_name_selected_info.set_visible(True)
-
def __liststore_model_add(self, bus_name_obj):
"""add a DBusBusName object to the liststore model"""
#update bus info stuff
- self.bus_proxy.GetConnectionUnixProcessID('(s)', bus_name_obj.bus_name_unique,
- result_handler = self.__get_unix_process_id_cb,
- error_handler = self.__get_unix_process_id_error_cb,
- user_data=bus_name_obj)
+ self.bus_proxy.GetConnectionUnixProcessID(
+ '(s)', bus_name_obj.bus_name_unique,
+ result_handler=self.__get_unix_process_id_cb,
+ error_handler=self.__get_unix_process_id_error_cb,
+ user_data=bus_name_obj)
#add bus to liststore
- return self.liststore_model.append([bus_name_obj, 0, "%s" % (bus_name_obj.bus_name_unique),
bus_name_obj.cmdline])
-
+ return self.liststore_model.append(
+ [bus_name_obj, 0, "%s" % (bus_name_obj.bus_name_unique), bus_name_obj.cmdline])
def __liststore_model_remove(self, bus_name_obj):
"""remove a DBusBusName object to the liststore model"""
@@ -164,8 +164,9 @@ class BusWatch(object):
return obj
raise Exception("bus name object '%s' not found in liststore" % (bus_name_obj))
-
- def __name_owner_changed_cb(self, connection, sender_name, object_path, interface_name, signal_name,
parameters, user_data):
+ def __name_owner_changed_cb(self, connection, sender_name,
+ object_path, interface_name, signal_name,
+ parameters, user_data):
"""bus name added or removed"""
bus_name = parameters[0]
old_owner = parameters[1]
@@ -178,43 +179,40 @@ class BusWatch(object):
self.__liststore_model_add(bus_name_obj)
else:
self.__liststore_model_remove(bus_name_obj)
- else :
+ else:
if new_owner:
self.__liststore_model_add(bus_name_obj)
if old_owner:
self.__liststore_model_remove(bus_name_obj)
-
def __list_names_handler(self, obj, names, userdata):
for n in names:
bus_name_obj = DBusBusName(n)
self.__liststore_model_add(bus_name_obj)
-
def __list_names_error_handler(self, obj, error, userdata):
print("error getting bus names: %s" % str(error))
-
def __get_unix_process_id_cb(self, obj, pid, bus_name_obj):
bus_name_obj.pid = pid
-
def __get_unix_process_id_error_cb(self, obj, error, bus_name_obj):
- print("error getting unix process id for %s: %s" % (bus_name_obj.bus_name_unique, str(error)))
+ print(
+ "error getting unix process id for %s: %s" % (
+ bus_name_obj.bus_name_unique, str(error)))
bus_name_obj.pid = 0
-
def __sort_on_name(self, model, iter1, iter2, user_data):
un1 = model.get_value(iter1, 2)
un2 = model.get_value(iter2, 2)
# covert to integers if comparing two unique names
if un1[0] == ':' and un2[0] == ':':
- un1 = un1[1:].split('.')
- un1 = tuple(map(int, un1))
+ un1 = un1[1:].split('.')
+ un1 = tuple(map(int, un1))
- un2 = un2[1:].split('.')
- un2 = tuple(map(int, un2))
+ un2 = un2[1:].split('.')
+ un2 = tuple(map(int, un2))
elif un1[0] == ':' and un2[0] != ':':
return 1
@@ -259,5 +257,3 @@ if __name__ == "__main__":
Gtk.main()
except (KeyboardInterrupt, SystemExit):
Gtk.main_quit()
-
-
diff --git a/src/dfeet/dbus_utils.py b/src/dfeet/dbus_utils.py
index 2b5c48b..381d1c1 100644
--- a/src/dfeet/dbus_utils.py
+++ b/src/dfeet/dbus_utils.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
+
def convert_complex_type(subsig):
result = None
len_consumed = 0
@@ -34,9 +35,9 @@ def convert_complex_type(subsig):
subtypelist = [key, value]
len_consumed += 1
- result = ['Dict of {', subtypelist,'}']
+ result = ['Dict of {', subtypelist, '}']
- elif c == 'a': # handle an array
+ elif c == 'a': # handle an array
ss = subsig[1:]
(r, lc) = convert_complex_type(ss)
if r:
@@ -55,18 +56,19 @@ def convert_complex_type(subsig):
len_ss = len(ss)
while i < len_ss and paren_count != 0:
if ss[i] == '(':
- paren_count+=1
+ paren_count += 1
elif ss[i] == ')':
- paren_count-=1
+ paren_count -= 1
+
+ i += 1
- i+=1
-
len_consumed = i
- ss = ss[0:i-1]
- result = ['Struct of (', sig_to_type_list(ss), ')']
+ ss = ss[0:i - 1]
+ result = ['Struct of (', sig_to_type_list(ss), ')']
return (result, len_consumed)
+
def convert_simple_type(c):
result = None
@@ -99,6 +101,7 @@ def convert_simple_type(c):
return result
+
def sig_to_type_list(sig):
i = 0
result = []
@@ -120,10 +123,11 @@ def sig_to_type_list(sig):
else:
result.append(type_)
- i+=1
-
+ i += 1
+
return result
+
def type_list_to_string(type_list):
result = ''
add_cap = False
@@ -146,6 +150,7 @@ def type_list_to_string(type_list):
return result[2:]
+
def sig_to_markup(sig, span_attr_str):
list_ = sig_to_type_list(sig)
markedup_list = []
@@ -153,7 +158,8 @@ def sig_to_markup(sig, span_attr_str):
m += type_list_to_string(list_)
m += '</span>'
- return m
+ return m
+
def sig_to_string(sig):
return type_list_to_string(sig_to_type_list(sig))
diff --git a/src/dfeet/executemethoddialog.py b/src/dfeet/executemethoddialog.py
index 1148e92..73200e6 100644
--- a/src/dfeet/executemethoddialog.py
+++ b/src/dfeet/executemethoddialog.py
@@ -9,9 +9,9 @@ from dfeet.uiloader import UILoader
class ExecuteMethodDialog:
def __init__(self, data_dir, connection, connection_is_bus, bus_name, method_obj):
signal_dict = {
- 'execute_dbus_method_cb' : self.execute_cb,
- 'execute_dialog_close_cb': self.close_cb
- }
+ 'execute_dbus_method_cb': self.execute_cb,
+ 'execute_dialog_close_cb': self.close_cb
+ }
self.connection = connection
self.connection_is_bus = connection_is_bus
@@ -59,11 +59,11 @@ class ExecuteMethodDialog:
params_gvariant = GLib.Variant(params_code, eval(params))
else:
params_gvariant = None
-
+
if self.connection_is_bus:
proxy = Gio.DBusProxy.new_sync(self.connection,
- Gio.DBusProxyFlags.NONE,
- None,
+ Gio.DBusProxyFlags.NONE,
+ None,
self.bus_name,
self.method_obj.object_path,
self.method_obj.iface_info.name,
@@ -71,19 +71,22 @@ class ExecuteMethodDialog:
#call the function
for i in range(0, self.method_execution_count_spinbutton.get_value_as_int()):
user_data['method_call_time_start'] = time.time()
- proxy.call(self.method_obj.method_info.name, params_gvariant, Gio.DBusCallFlags.NONE,
-1, None, self.method_connection_bus_cb, user_data)
+ proxy.call(
+ self.method_obj.method_info.name, params_gvariant,
+ Gio.DBusCallFlags.NONE, -1, None, self.method_connection_bus_cb, user_data)
else:
#FIXME: implement p2p connection execution
raise Exception("Function execution on p2p connections not yet implemented")
- #self.connection.call(None, object_path, self.method_obj.iface_obj.iface_info.name,
self.method_obj.method_info.name, params_gvariant, GLib.VariantType.new("(s)"), Gio.DBusCallFlags.NONE, -1,
None)
+ #self.connection.call(
+ #None, object_path, self.method_obj.iface_obj.iface_info.name,
+ #self.method_obj.method_info.name, params_gvariant,
+ #GLib.VariantType.new("(s)"), Gio.DBusCallFlags.NONE, -1, None)
-
except Exception as e:
#output the exception
self.source_textview.get_buffer().set_text(str(e))
self.prettyprint_textview.get_buffer().set_text(pformat(str(e)))
-
def method_connection_bus_cb(self, proxy, res_async, user_data):
"""async callback for executed method"""
try:
@@ -92,27 +95,30 @@ class ExecuteMethodDialog:
#remember the needed time for the method call
method_call_time_end = time.time()
method_call_time_needed = method_call_time_end - user_data['method_call_time_start']
-
+
#update avg, min, max
user_data['avg'] += method_call_time_needed
user_data['count'] += 1
self.label_avg.set_text("%.4f" % (float(user_data['avg'] / user_data['count'])))
- self.label_min.set_text("%.4f" % min(float(self.label_min.get_text() or "999"),
method_call_time_needed))
- self.label_max.set_text("%.4f" % max(float(self.label_max.get_text() or "0"),
method_call_time_needed))
+ self.label_min.set_text(
+ "%.4f" % min(float(self.label_min.get_text() or "999"), method_call_time_needed))
+ self.label_max.set_text(
+ "%.4f" % max(float(self.label_max.get_text() or "0"), method_call_time_needed))
#output result
if result:
self.source_textview.get_buffer().set_text(str(result))
self.prettyprint_textview.get_buffer().set_text(str(result.unpack()[0]))
else:
- self.prettyprint_textview.get_buffer().set_text('This method did not return anything')
+ self.prettyprint_textview.get_buffer().set_text(
+ 'This method did not return anything')
except Exception as e:
#output the exception
self.source_textview.get_buffer().set_text(str(e))
self.prettyprint_textview.get_buffer().set_text(pformat(str(e)))
-
+
def run(self):
- response =self.dialog.run()
+ response = self.dialog.run()
if response == Gtk.ResponseType.DELETE_EVENT or response == Gtk.ResponseType.CLOSE:
self.dialog.destroy()
diff --git a/src/dfeet/introspection.py b/src/dfeet/introspection.py
index 544e168..3224036 100644
--- a/src/dfeet/introspection.py
+++ b/src/dfeet/introspection.py
@@ -6,7 +6,11 @@ from dfeet.executemethoddialog import ExecuteMethodDialog
from dfeet.uiloader import UILoader
-from dfeet.introspection_helper import DBusNode, DBusInterface, DBusProperty, DBusSignal, DBusMethod
+from dfeet.introspection_helper import DBusNode
+from dfeet.introspection_helper import DBusInterface
+from dfeet.introspection_helper import DBusProperty
+from dfeet.introspection_helper import DBusSignal
+from dfeet.introspection_helper import DBusMethod
class AddressInfo():
@@ -23,20 +27,21 @@ class AddressInfo():
def __init__(self, data_dir, address, name, connection_is_bus=True):
self.data_dir = data_dir
signal_dict = {
- 'treeview_row_activated_cb' : self.__treeview_row_activated_cb,
- 'treeview_row_expanded_cb' : self.__treeview_row_expanded_cb,
- 'button_reload_clicked_cb' : self.__button_reload_clicked_cb,
+ 'treeview_row_activated_cb': self.__treeview_row_activated_cb,
+ 'treeview_row_expanded_cb': self.__treeview_row_expanded_cb,
+ 'button_reload_clicked_cb': self.__button_reload_clicked_cb,
}
- self.address = address # can be Gio.BusType.SYSTEM or Gio.BusType.SYSTEM or an other address
- self.name = name #the bus name or None
- self.connection_is_bus = connection_is_bus # is it a bus or a p2p connection?
+ self.address = address # can be Gio.BusType.SYSTEM or Gio.BusType.SYSTEM or other address
+ self.name = name # the bus name or None
+ self.connection_is_bus = connection_is_bus # is it a bus or a p2p connection?
#setup UI
ui = UILoader(self.data_dir, UILoader.UI_INTROSPECTION)
- self.introspect_box = ui.get_root_widget() #this is the main box with the treeview
- self.__spinner = ui.get_widget('spinner') #the spinner is used to show progress during the
introspection
- self.__scrolledwindow = ui.get_widget('scrolledwindow') #the scrolledwindow contains the treeview
+ self.introspect_box = ui.get_root_widget() # this is the main box with the treeview
+ self.__spinner = ui.get_widget('spinner') # progress during the introspection
+ self.__scrolledwindow = \
+ ui.get_widget('scrolledwindow') # the scrolledwindow contains the treeview
self.__treemodel = ui.get_widget('treestore')
self.__treemodel.set_sort_func(0, self.__sort_model)
self.__treemodel.set_sort_column_id(0, Gtk.SortType.ASCENDING)
@@ -52,11 +57,14 @@ class AddressInfo():
#we expect a bus connection
if self.address == Gio.BusType.SYSTEM or self.address == Gio.BusType.SESSION:
self.connection = Gio.bus_get_sync(self.address, None)
- self.__label_address.set_text(Gio.dbus_address_get_for_bus_sync(self.address, None))
+ self.__label_address.set_text(
+ Gio.dbus_address_get_for_bus_sync(self.address, None))
elif Gio.dbus_is_supported_address(self.address):
- self.connection = Gio.DBusConnection.new_for_address_sync(self.address,
-
Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT | Gio.DBusConnectionFlags.MESSAGE_BUS_CONNECTION,
- None, None)
+ self.connection = Gio.DBusConnection.new_for_address_sync(
+ self.address,
+ Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT |
+ Gio.DBusConnectionFlags.MESSAGE_BUS_CONNECTION,
+ None, None)
self.__label_address.set_text(self.address)
else:
self.connection = None
@@ -64,9 +72,10 @@ class AddressInfo():
else:
#we have a peer-to-peer connection
if Gio.dbus_is_supported_address(self.address):
- self.connection = Gio.DBusConnection.new_for_address_sync(self.address,
-
Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT,
- None, None)
+ self.connection = Gio.DBusConnection.new_for_address_sync(
+ self.address,
+ Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT,
+ None, None)
self.__label_address.set_text(self.address)
else:
self.connection = None
@@ -78,7 +87,6 @@ class AddressInfo():
def __messagedialog_close_cb(self, dialog):
self.__messagedialog.destroy()
-
def __treeview_row_activated_cb(self, treeview, path, view_column):
model = treeview.get_model()
iter_ = model.get_iter(path)
@@ -87,7 +95,8 @@ class AddressInfo():
if isinstance(obj, DBusMethod):
#execute the selected method
- dialog = ExecuteMethodDialog(self.data_dir, self.connection, self.connection_is_bus, self.name,
obj)
+ dialog = ExecuteMethodDialog(
+ self.data_dir, self.connection, self.connection_is_bus, self.name, obj)
dialog.run()
elif isinstance(obj, DBusProperty):
#update the selected property (TODO: do this async)
@@ -109,19 +118,17 @@ class AddressInfo():
else:
treeview.expand_row(path, False)
-
def __treeview_row_expanded_cb(self, treeview, iter_, path):
model = treeview.get_model()
node = model.get(iter_, 1)[0]
if isinstance(node, DBusNode):
if model.iter_has_child(iter_):
childiter = model.iter_children(iter_)
- while childiter != None:
+ while childiter is not None:
childpath = model.get_path(childiter)
treeview.expand_to_path(childpath)
childiter = model.iter_next(childiter)
-
def __sort_model(self, model, iter1, iter2, user_data):
"""objects with small path depth first"""
un1 = model.get_value(iter1, 0)
@@ -143,7 +150,6 @@ class AddressInfo():
else:
return un1 > un2
-
def introspect_start(self):
"""introspect the given bus name and update the tree model"""
#cleanup current tree model
@@ -151,12 +157,10 @@ class AddressInfo():
#start introspection
self.__dbus_node_introspect("/")
-
def __button_reload_clicked_cb(self, widget):
"""reload the introspection data"""
self.introspect_start()
-
def __dbus_node_introspect_cb(self, connection, result_async, object_path):
"""callback when Introspect dbus function call finished"""
try:
@@ -179,33 +183,48 @@ class AddressInfo():
#append interfaces to tree model
if len(node_info.interfaces) > 0:
- name_iter = self.__treemodel.append(tree_iter, ["<b>Interfaces</b>", None])
+ name_iter = self.__treemodel.append(tree_iter,
+ ["<b>Interfaces</b>", None])
for iface in node_info.interfaces:
iface_obj = DBusInterface(node_obj, iface)
- iface_iter = self.__treemodel.append(name_iter, ["%s" % iface.name, iface_obj])
+ iface_iter = self.__treemodel.append(
+ name_iter,
+ ["%s" % iface.name, iface_obj])
#interface methods
if len(iface.methods) > 0:
- iface_methods_iter = self.__treemodel.append(iface_iter, ["<b>Methods</b>",
None])
+ iface_methods_iter = self.__treemodel.append(
+ iface_iter, ["<b>Methods</b>", None])
for iface_method in iface.methods:
method_obj = DBusMethod(iface_obj, iface_method)
- self.__treemodel.append(iface_methods_iter, ["%s" % method_obj.markup_str,
method_obj])
+ self.__treemodel.append(
+ iface_methods_iter,
+ ["%s" % method_obj.markup_str, method_obj])
#interface signals
if len(iface.signals) > 0:
- iface_signals_iter = self.__treemodel.append(iface_iter, ["<b>Signals</b>",
None])
+ iface_signals_iter = self.__treemodel.append(
+ iface_iter, ["<b>Signals</b>", None])
for iface_signal in iface.signals:
signal_obj = DBusSignal(iface_obj, iface_signal)
- self.__treemodel.append(iface_signals_iter, ["%s" % signal_obj.markup_str,
signal_obj])
+ self.__treemodel.append(
+ iface_signals_iter,
+ ["%s" % signal_obj.markup_str, signal_obj])
#interface properties
if len(iface.properties) > 0:
- iface_properties_iter = self.__treemodel.append(iface_iter,
["<b>Properties</b>", None])
+ iface_properties_iter = self.__treemodel.append(
+ iface_iter, ["<b>Properties</b>", None])
for iface_property in iface.properties:
property_obj = DBusProperty(iface_obj, iface_property)
- self.__treemodel.append(iface_properties_iter, ["%s" %
property_obj.markup_str, property_obj])
+ self.__treemodel.append(
+ iface_properties_iter,
+ ["%s" % property_obj.markup_str, property_obj])
#interface annotations #FIXME: add Annotation object!!!
if len(iface.annotations) > 0:
- iface_annotations_iter = self.__treemodel.append(iface_iter,
["<b>Annotations</b>", None])
+ iface_annotations_iter = self.__treemodel.append(
+ iface_iter, ["<b>Annotations</b>", None])
for iface_annotation in iface.annotations:
- self.__treemodel.append(iface_annotations_iter, ["%s" %
iface_annotation.name, iface_annotation])
+ self.__treemodel.append(
+ iface_annotations_iter,
+ ["%s" % iface_annotation.name, iface_annotation])
#are more nodes left?
if len(node_info.nodes) > 0:
@@ -228,16 +247,16 @@ class AddressInfo():
self.introspect_box.show_all()
-
def __dbus_node_introspect(self, object_path):
"""Introspect the given object path. This function will be called recursive"""
#start spinner
self.__spinner.start()
self.__spinner.set_visible(True)
#start async dbus call
- self.connection.call(self.name, object_path, 'org.freedesktop.DBus.Introspectable', 'Introspect',
- None, GLib.VariantType.new("(s)"), Gio.DBusCallFlags.NONE, -1,
- None, self.__dbus_node_introspect_cb, object_path)
+ self.connection.call(
+ self.name, object_path, 'org.freedesktop.DBus.Introspectable', 'Introspect',
+ None, GLib.VariantType.new("(s)"), Gio.DBusCallFlags.NONE, -1,
+ None, self.__dbus_node_introspect_cb, object_path)
if __name__ == "__main__":
@@ -257,7 +276,6 @@ if __name__ == "__main__":
else:
addr = p.addr
-
name = p.name
ai = AddressInfo(addr, name, not p.p2p)
win = Gtk.Window()
diff --git a/src/dfeet/introspection_helper.py b/src/dfeet/introspection_helper.py
index db69d0a..3341dd2 100644
--- a/src/dfeet/introspection_helper.py
+++ b/src/dfeet/introspection_helper.py
@@ -7,21 +7,22 @@ from dfeet import dbus_utils
def args_signature_markup(arg_signature):
return '<small><span foreground="#2E8B57">%s</span></small>' % (arg_signature)
+
def args_name_markup(arg_name):
return '<small><span foreground="#000000">%s</span></small>' % (arg_name)
-
class DBusNode(GObject.GObject):
"""object to represent a DBus Node (object path)"""
def __init__(self, name, object_path, node_info):
GObject.GObject.__init__(self)
self.__name = name
self.__object_path = object_path
- self.__node_info = node_info # Gio.GDBusNodeInfo object
+ self.__node_info = node_info # Gio.GDBusNodeInfo object
def __repr__(self):
- return "Name: %s ; ObjPath: %s ; NodeInfo: %s" % (self.name, self.object_path, self.node_info)
+ return "Name: %s ; ObjPath: %s ; NodeInfo: %s" % (
+ self.name, self.object_path, self.node_info)
@property
def name(self):
@@ -39,8 +40,9 @@ class DBusNode(GObject.GObject):
class DBusInterface(DBusNode):
"""object to represent a DBus Interface"""
def __init__(self, dbus_node_obj, iface_info):
- DBusNode.__init__(self, dbus_node_obj.name, dbus_node_obj.object_path, dbus_node_obj.node_info)
- self.__iface_info = iface_info # Gio.GDBusInterfaceInfo object
+ DBusNode.__init__(self, dbus_node_obj.name,
+ dbus_node_obj.object_path, dbus_node_obj.node_info)
+ self.__iface_info = iface_info # Gio.GDBusInterfaceInfo object
def __repr__(self):
return "iface '%s' on node '%s'" % (self.iface_info.name, self.node_info.path)
@@ -54,8 +56,8 @@ class DBusProperty(DBusInterface):
"""object to represent a DBus Property"""
def __init__(self, dbus_iface_obj, property_info):
DBusInterface.__init__(self, dbus_iface_obj, dbus_iface_obj.iface_info)
- self.__property_info = property_info # Gio.GDBusPropertyInfo object
- self.__value = None #the value
+ self.__property_info = property_info # Gio.GDBusPropertyInfo object
+ self.__value = None # the value
def __repr__(self):
sig = dbus_utils.sig_to_string(self.property_info.signature)
@@ -73,7 +75,6 @@ class DBusProperty(DBusInterface):
def value(self, new_val):
self.__value = new_val
-
@property
def markup_str(self):
sig = dbus_utils.sig_to_string(self.property_info.signature)
@@ -82,21 +83,27 @@ class DBusProperty(DBusInterface):
readwrite.append("read")
if self.writable:
readwrite.append("write")
- s = "%s %s <small>(%s)</small>" % (args_signature_markup(sig),
args_name_markup(self.property_info.name), " / ".join(readwrite))
+ s = "%s %s <small>(%s)</small>" % (
+ args_signature_markup(sig),
+ args_name_markup(self.property_info.name), " / ".join(readwrite))
if self.value:
s += " = %s" % (self.value)
return s
@property
def readable(self):
- if int(self.property_info.flags) == int(Gio.DBusPropertyInfoFlags.READABLE) or
int(self.property_info.flags) == (int(Gio.DBusPropertyInfoFlags.WRITABLE |
Gio.DBusPropertyInfoFlags.READABLE)):
+ if int(self.property_info.flags) == int(Gio.DBusPropertyInfoFlags.READABLE) or \
+ int(self.property_info.flags) == \
+ (int(Gio.DBusPropertyInfoFlags.WRITABLE | Gio.DBusPropertyInfoFlags.READABLE)):
return True
else:
return False
@property
def writable(self):
- if int(self.property_info.flags) == int(Gio.DBusPropertyInfoFlags.WRITABLE) or
int(self.property_info.flags) == (int(Gio.DBusPropertyInfoFlags.WRITABLE |
Gio.DBusPropertyInfoFlags.READABLE)):
+ if int(self.property_info.flags) == int(Gio.DBusPropertyInfoFlags.WRITABLE) or \
+ int(self.property_info.flags) == \
+ (int(Gio.DBusPropertyInfoFlags.WRITABLE | Gio.DBusPropertyInfoFlags.READABLE)):
return True
else:
return False
@@ -105,12 +112,13 @@ class DBusProperty(DBusInterface):
class DBusSignal(DBusInterface):
"""object to represent a DBus Signal"""
def __init__(self, dbus_iface_obj, signal_info):
- DBusInterface.__init__(self, dbus_iface_obj, dbus_iface_obj.iface_info)
- self.__signal_info = signal_info #Gio.GDBusSignalInfo object
+ DBusInterface.__init__(self, dbus_iface_obj,
+ dbus_iface_obj.iface_info)
+ self.__signal_info = signal_info # Gio.GDBusSignalInfo object
def __repr__(self):
return "%s" % (self.signal_info.name)
-
+
@property
def signal_info(self):
return self.__signal_info
@@ -140,10 +148,12 @@ class DBusMethod(DBusInterface):
"""object to represent a DBus Method"""
def __init__(self, dbus_iface_obj, method_info):
DBusInterface.__init__(self, dbus_iface_obj, dbus_iface_obj.iface_info)
- self.__method_info = method_info #Gio.GDBusMethodInfo object
+ self.__method_info = method_info # Gio.GDBusMethodInfo object
def __repr__(self):
- return "%s(%s) ↦ %s (%s)" % (self.method_info.name, self.in_args_str, self.out_args_str,
DBusInterface.__repr__(self))
+ return "%s(%s) ↦ %s (%s)" % (
+ self.method_info.name, self.in_args_str,
+ self.out_args_str, DBusInterface.__repr__(self))
@property
def in_args_code(self):
@@ -158,7 +168,8 @@ class DBusMethod(DBusInterface):
@property
def markup_str(self):
- return "%s %s <b>↦</b> %s" % (self.method_info.name, self.in_args_markup_str,
self.out_args_markup_str)
+ return "%s %s <b>↦</b> %s" % (
+ self.method_info.name, self.in_args_markup_str, self.out_args_markup_str)
@property
def in_args(self):
@@ -175,13 +186,13 @@ class DBusMethod(DBusInterface):
sig = dbus_utils.sig_to_string(out_arg.signature)
out_args.append({'signature': sig, 'name': out_arg.name})
return out_args
-
+
@property
def in_args_str(self):
result = ""
for arg in self.in_args:
result += "%s %s, " % (arg['signature'], arg['name'])
-
+
return result[0:-2]
@property
@@ -189,21 +200,24 @@ class DBusMethod(DBusInterface):
result = ""
for arg in self.out_args:
result += "%s %s, " % (arg['signature'], arg['name'])
-
+
return result[0:-2]
def __args_markup_str(self, args):
"""markup a given list of args"""
result = ''
result += '<span foreground="#FF00FF">(</span>'
- result += ', '.join('%s %s' % (args_signature_markup(arg['signature']),
args_name_markup(arg['name'])) for arg in args)
+ result += ', '.join(
+ '%s %s' % (
+ args_signature_markup(arg['signature']),
+ args_name_markup(arg['name'])) for arg in args)
result += '<span foreground="#FF00FF">)</span>'
return result
@property
def in_args_markup_str(self):
return self.__args_markup_str(self.in_args)
-
+
@property
def out_args_markup_str(self):
return self.__args_markup_str(self.out_args)
diff --git a/src/dfeet/settings.py b/src/dfeet/settings.py
index 47c256f..3c0d008 100644
--- a/src/dfeet/settings.py
+++ b/src/dfeet/settings.py
@@ -13,6 +13,7 @@ except:
import os
import re
+
class ConfigTokenizer():
COMMA = re.compile(",")
FALLTHROUGH = re.compile('(?:[^,.])+')
@@ -24,8 +25,8 @@ class ConfigTokenizer():
_parse_order = [STRING, NUMBER, WHITESPACE, COMMA, FALLTHROUGH]
class Match():
- ENDWHITESPACE=re.compile('\s$')
- UNESCAPE=re.compile('\\\(.)')
+ ENDWHITESPACE = re.compile('\s$')
+ UNESCAPE = re.compile('\\\(.)')
def __init__(self, match, regex):
self.match = match
@@ -42,13 +43,12 @@ class ConfigTokenizer():
return False
def is_value(self):
- if (self.regex == ConfigTokenizer.STRING or
- self.regex == ConfigTokenizer.NUMBER or
- self.regex == ConfigTokenizer.FALLTHROUGH):
+ if self.regex == ConfigTokenizer.STRING or \
+ self.regex == ConfigTokenizer.NUMBER or \
+ self.regex == ConfigTokenizer.FALLTHROUGH:
return True
return False
-
def strip(self, s):
return self.ENDWHITESPACE.sub('', s)
@@ -90,6 +90,7 @@ class ConfigTokenizer():
raise StopIteration
+
class Settings:
"""
Handles loading/saving settings from/to a file on disk.
@@ -98,15 +99,15 @@ class Settings:
instance = None
# the different settings in each config block
- general = {
- "windowheight" : 550,
- "windowwidth" : 900,
- "windowstate" : None,
- "bustabs_list" : [],
- "addbus_list" : []
- }
-
- def __init__(self, filename = None):
+ general = {
+ "windowheight": 550,
+ "windowwidth": 900,
+ "windowstate": None,
+ "bustabs_list": [],
+ "addbus_list": [],
+ }
+
+ def __init__(self, filename=None):
"""
Creates a new instance of Settings.
@@ -174,7 +175,7 @@ class Settings:
self.general[key][i] = self.quote(self.general[key][i])
self.general[key] = ','.join(self.general[key])
- if self.general[key] == None:
+ if self.general[key] is None:
self.general[key] = ''
self.config.set("General", str(key), str(self.general[key]))
diff --git a/src/dfeet/uiloader.py b/src/dfeet/uiloader.py
index 21c66cf..08dda4b 100644
--- a/src/dfeet/uiloader.py
+++ b/src/dfeet/uiloader.py
@@ -13,20 +13,20 @@ class UILoader:
UI_BUSWATCH,
UI_EXECUTEDIALOG,
UI_ADDCONNECTIONDIALOG
- ) = range(UI_COUNT)
+ ) = range(UI_COUNT)
# {ui_id: ((files,...), root widget)}
- _ui_map = {UI_MAINWINDOW : (('mainwindow.ui',),
- 'appwindow1'),
- UI_INTROSPECTION : (('introspection.ui',),
- 'box_introspectview'),
- UI_BUSWATCH : (('buswatch.ui',),
- 'paned_buswatch'),
- UI_EXECUTEDIALOG : (('executedialog.ui',),
- 'executedialog1'),
- UI_ADDCONNECTIONDIALOG : (('addconnectiondialog.ui',),
- 'add_connection_dialog1')
- }
+ _ui_map = {UI_MAINWINDOW: (('mainwindow.ui',),
+ 'appwindow1'),
+ UI_INTROSPECTION: (('introspection.ui',),
+ 'box_introspectview'),
+ UI_BUSWATCH: (('buswatch.ui',),
+ 'paned_buswatch'),
+ UI_EXECUTEDIALOG: (('executedialog.ui',),
+ 'executedialog1'),
+ UI_ADDCONNECTIONDIALOG: (('addconnectiondialog.ui',),
+ 'add_connection_dialog1')
+ }
def __init__(self, data_dir, ui):
ui_info = self._ui_map[ui]
diff --git a/src/dfeet/wnck_utils.py b/src/dfeet/wnck_utils.py
index 19afb1f..b744d45 100644
--- a/src/dfeet/wnck_utils.py
+++ b/src/dfeet/wnck_utils.py
@@ -11,11 +11,12 @@ try:
except:
has_libwnck = False
+
class IconTable:
instance = None
def __init__(self):
- # {pid: icon}
+ # {pid: icon}
self.app_map = {}
icon_theme = Gtk.IconTheme.get_default()
@@ -31,7 +32,7 @@ class IconTable:
pid = app.get_pid()
icon = app.get_mini_icon()
- if not self.app_map.has_key(pid):
+ if not pid in self.app_map.keys():
self.app_map[pid] = icon
def on_app_open(self, screen, app):
@@ -40,17 +41,17 @@ class IconTable:
self.app_map[app.get_pid()] = icon
def on_app_close(self, screen, app):
- return # this is a leak but some apps still exist even if all their
- # top level windows don't. We need to have a better cleanup
- # based on when an app's services go away
+ return # this is a leak but some apps still exist even if all their
+ # top level windows don't. We need to have a better cleanup
+ # based on when an app's services go away
pid = app.get_pid()
- if self.app_map.has_key(pid):
+ if not pid in self.app_map.keys():
del self.app_map[pid]
def get_icon(self, pid):
icon = None
- if self.app_map.has_key(pid):
+ if not pid in self.app_map.keys():
icon = self.app_map[pid]
if not icon:
@@ -64,4 +65,3 @@ class IconTable:
cls.instance = IconTable()
return cls.instance
-
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
index 994fb22..7437e52 100644
--- a/src/tests/Makefile.am
+++ b/src/tests/Makefile.am
@@ -2,4 +2,11 @@ TESTS = tests.py
check_SCRIPTS = tests.py
-EXTRA_DIST = tests.py
\ No newline at end of file
+EXTRA_DIST = tests.py
+
+
+# Default pep8.py --exclude + emacs backup files
+PEP8_EXCLUDES=--exclude='.svn,CVS,.bzr,.hg,.git,__pycache__,.\#*'
+
+check-local:
+ pep8 --max-line-length=99 --ignore=E123 $(PEP8_EXCLUDES) $(top_srcdir)/src/
diff --git a/src/tests/tests.py b/src/tests/tests.py
index 209ed3c..453bb8d 100755
--- a/src/tests/tests.py
+++ b/src/tests/tests.py
@@ -1,10 +1,17 @@
#!/usr/bin/env python
-import sys, os
+import sys
+import os
sys.path.insert(0, os.path.abspath(os.path.join(__file__, "../../")))
-from gi.repository import Gtk, Gio, GLib
+from gi.repository import Gtk
+from gi.repository import Gio
+from gi.repository import GLib
from dfeet.introspection import AddressInfo
-from dfeet.introspection_helper import DBusNode, DBusInterface, DBusProperty, DBusSignal, DBusMethod
+from dfeet.introspection_helper import DBusNode
+from dfeet.introspection_helper import DBusInterface
+from dfeet.introspection_helper import DBusProperty
+from dfeet.introspection_helper import DBusSignal
+from dfeet.introspection_helper import DBusMethod
import unittest
XML = """
@@ -26,6 +33,7 @@ XML = """
DATA_DIR = os.path.abspath("../../data/")
+
class IntrospectionHelperTest(unittest.TestCase):
"""tests for the introspection helper classes"""
def setUp(self):
@@ -92,14 +100,5 @@ class AddressInfoTest(unittest.TestCase):
pass
if __name__ == "__main__":
- #FIXME: this is copied from the file "f-deet"
- ENV_PATHS = {"DFEET_DATA_PATH" : "ui/",
- "DFEET_IMAGE_PATH" : "ui/",
- "DFEET_LOCALE_PATH" : "locale/",
- "DFEET_HELP_PATH" : "/usr/share/gnome/dfeet/"
- }
- for var, path in ENV_PATHS.iteritems():
- os.environ.setdefault(var, path)
-
#run tests
unittest.main()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]