davemds pushed a commit to branch master. http://git.enlightenment.org/apps/espionage.git/commit/?id=5f11ce0622e5e5858f261708df7122bed430e434
commit 5f11ce0622e5e5858f261708df7122bed430e434 Author: Dave Andreoli <d...@gurumeditation.it> Date: Mon Apr 26 07:33:19 2021 +0200 Reformat code to make pycharm happy --- espionage/espionage.py | 97 ++++++++++++++++++++++++++++++++------------------ setup.py | 31 ++++++++-------- 2 files changed, 77 insertions(+), 51 deletions(-) diff --git a/espionage/espionage.py b/espionage/espionage.py index 3ac3af0..bbb5ca1 100644 --- a/espionage/espionage.py +++ b/espionage/espionage.py @@ -54,6 +54,7 @@ EXPAND_HORIZ = EVAS_HINT_EXPAND, 0.0 FILL_BOTH = EVAS_HINT_FILL, EVAS_HINT_FILL FILL_HORIZ = EVAS_HINT_FILL, 0.5 + class Options(object): """class to contain application options""" def __init__(self): @@ -74,33 +75,36 @@ class Options(object): script_path = os.path.dirname(__file__) + def theme_resource_get(fname): return os.path.join(script_path, 'themes', options.theme_name, fname) + def prettify_if_needed(data): if options.pretty_output: return utf8_to_markup(json.dumps(data, indent=2)) else: return utf8_to_markup(str(data)) + def colored_params(plist, omit_braces=False): - p = ', '.join(["<font %s>%s</> <font %s>%s</>" % \ + p = ', '.join(["<font %s>%s</> <font %s>%s</>" % (options.stl_ptype, ty, options.stl_pname, name) - for name, ty in plist]) + for name, ty in plist]) if omit_braces: return p return '<font %s>(</>%s<font %s>)</>' % \ (options.stl_brackets, p, options.stl_brackets) -### connect to session and system buses, and set session as the current one +# connect to session and system buses, and set session as the current one session_bus = dbus.SessionBus(mainloop=DBusEcoreMainLoop()) system_bus = dbus.SystemBus(mainloop=DBusEcoreMainLoop()) bus = session_bus options = Options() -### Classes to describe various DBus nodes +# Classes to describe various DBus nodes class DBusNode(object): """base object for the others DBus nodes""" def __init__(self, name, parent): @@ -130,6 +134,7 @@ class DBusObject(DBusNode): def icon(self): return 'object.png' + class DBusInterface(DBusNode): """object to represent a DBus Interface""" def __init__(self, name, parent_obj): @@ -156,9 +161,10 @@ class DBusInterface(DBusNode): def icon(self): return 'interface.png' + class DBusProperty(DBusNode): """object to represent a DBus Property""" - def __init__(self, name, parent_iface, typ = 'unknown', access = 'unknown'): + def __init__(self, name, parent_iface, typ='unknown', access='unknown'): DBusNode.__init__(self, name, parent_iface) parent_iface.properties.append(self) self._type = typ @@ -190,6 +196,7 @@ class DBusProperty(DBusNode): def icon(self): return 'property.png' + class DBusMethod(DBusNode): """object to represent a DBus Method""" def __init__(self, name, parent_iface): @@ -218,6 +225,7 @@ class DBusMethod(DBusNode): def icon(self): return 'method.png' + class DBusSignal(DBusNode): """object to represent a DBus Signal""" def __init__(self, name, parent_iface): @@ -237,9 +245,9 @@ class DBusSignal(DBusNode): def icon(self): return 'signal.png' -### Introspect a named service and return a list of DBusObjects -def recursive_introspect(bus, named_service, object_path, ret_data=None): +def recursive_introspect(bus, named_service, object_path, ret_data=None): + """ Introspect a named service and return a list of DBusObjects """ # first recursion, create an empty list if ret_data is None: ret_data = [] @@ -279,10 +287,10 @@ def recursive_introspect(bus, named_service, object_path, ret_data=None): for arg in child: if arg.tag == 'arg': if arg.attrib['direction'] == 'out': - L = meth.returns + li = meth.returns else: - L = meth.params - L.append(( + li = meth.params + li.append(( arg.attrib['name'] if 'name' in arg.attrib else '', arg.attrib['type'] if 'type' in arg.attrib else '')) @@ -304,19 +312,23 @@ def recursive_introspect(bus, named_service, object_path, ret_data=None): return ret_data -### Names genlist (the one on the left) +# Names genlist (the one on the left) class NamesListGroupItemClass(GenlistItemClass): def __init__(self): GenlistItemClass.__init__(self, item_style="group_index") + def text_get(self, gl, part, name): return name + class NamesListItemClass(GenlistItemClass): def __init__(self): GenlistItemClass.__init__(self, item_style="default") + def text_get(self, gl, part, name): return name + class NamesList(Genlist): def __init__(self, parent): @@ -333,18 +345,18 @@ class NamesList(Genlist): # add public group item self.public_group = self.item_append(self.itc_g, "Public Services", - flags=ELM_GENLIST_ITEM_GROUP) + flags=ELM_GENLIST_ITEM_GROUP) self.public_group.select_mode_set(ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY) # add activatables group item self.activatable_group = self.item_append(self.itc_g, "Activatable Services", - flags=ELM_GENLIST_ITEM_GROUP) + flags=ELM_GENLIST_ITEM_GROUP) self.activatable_group.select_mode_set(ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY) # add private group item if options.show_private_stuff: self.private_group = self.item_append(self.itc_g, "Private Services", - flags=ELM_GENLIST_ITEM_GROUP) + flags=ELM_GENLIST_ITEM_GROUP) self.private_group.select_mode_set(ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY) # populate the genlist @@ -361,7 +373,8 @@ class NamesList(Genlist): self.service_activatable_add(name) # keep the list updated when a name changes - if self.sig1: self.sig1.remove() + if self.sig1: + self.sig1.remove() self.sig1 = bus.add_signal_receiver(self.name_owner_changed_cb, "NameOwnerChanged") # bus.add_signal_receiver(self.name_acquired_cb, "NameAcquired") @@ -381,6 +394,7 @@ class NamesList(Genlist): "StartServiceByName", "su", (name, 0), None, None) spinner = Progressbar(self.win, style="wheel", pulse_mode=True) spinner.pulse(True) + def stop_waiting_cb(btn): self.waiting_popup.delete() self.waiting_activation = None @@ -432,7 +446,7 @@ class NamesList(Genlist): self.service_del(name) -### Detail genlist (the one on the right) +# Detail genlist (the one on the right) class ObjectItemClass(GenlistItemClass): def __init__(self): GenlistItemClass.__init__(self, item_style="group_index") @@ -445,6 +459,7 @@ class ObjectItemClass(GenlistItemClass): return Icon(gl, size_hint_min=(22, 22), file=theme_resource_get(obj.icon)) + class NodeItemClass(GenlistItemClass): def __init__(self): GenlistItemClass.__init__(self, item_style="default_style") @@ -477,6 +492,7 @@ class NodeItemClass(GenlistItemClass): if part == 'elm.swallow.icon': return Icon(gl, file=theme_resource_get(obj.icon)) + class DetailList(Genlist): def __init__(self, parent): Genlist.__init__(self, parent) @@ -504,21 +520,29 @@ class DetailList(Genlist): for iface in obj.interfaces: if not options.show_introspect_stuff and \ iface.name.startswith("org.freedesktop.DBus"): - continue + continue iface_item = self.item_append(self.itc, iface, parent_item=obj_item, flags=ELM_GENLIST_ITEM_TREE) def sort_cb(self, it1, it2): pri1 = pri2 = 0 - if isinstance(it1.data, DBusProperty): pri1 = 3 - elif isinstance(it1.data, DBusMethod): pri1 = 2 - elif isinstance(it1.data, DBusSignal): pri1 = 1 - if isinstance(it2.data, DBusProperty): pri2 = 3 - elif isinstance(it2.data, DBusMethod): pri2 = 2 - elif isinstance(it2.data, DBusSignal): pri2 = 1 - if pri1 > pri2: return 1 - elif pri1 < pri2: return -1 + if isinstance(it1.data, DBusProperty): + pri1 = 3 + elif isinstance(it1.data, DBusMethod): + pri1 = 2 + elif isinstance(it1.data, DBusSignal): + pri1 = 1 + if isinstance(it2.data, DBusProperty): + pri2 = 3 + elif isinstance(it2.data, DBusMethod): + pri2 = 2 + elif isinstance(it2.data, DBusSignal): + pri2 = 1 + if pri1 > pri2: + return 1 + elif pri1 < pri2: + return -1 return 1 if it1.data.name.lower() < it2.data.name.lower() else -1 def expand_request_cb(self, genlist, item): @@ -543,7 +567,7 @@ class DetailList(Genlist): item.update() -### Methods runner +# Methods runner class MethodRunner(DialogWindow): def __init__(self, parent, method): DialogWindow.__init__(self, parent, "espionage", "Method", autodel=True) @@ -672,10 +696,10 @@ class MethodRunner(DialogWindow): params = ast.literal_eval(user_params) if type(params) is tuple: meth(*params, reply_handler=self.reply_handler, - error_handler=self.error_handler) + error_handler=self.error_handler) else: meth(params, reply_handler=self.reply_handler, - error_handler=self.error_handler) + error_handler=self.error_handler) else: meth(reply_handler=self.reply_handler, error_handler=self.error_handler) @@ -697,7 +721,7 @@ class MethodRunner(DialogWindow): 'Exception:</b><br>%s' % utf8_to_markup(str(e)) -### Signals receiver +# Signals receiver class SignalItemClass(GenlistItemClass): def __init__(self): GenlistItemClass.__init__(self, item_style='default_style') @@ -711,6 +735,7 @@ class SignalItemClass(GenlistItemClass): if part == 'elm.swallow.icon': return Icon(gl, file=theme_resource_get('signal.png')) + class SignalReceiver(Frame): def __init__(self, parent): Frame.__init__(self, parent, text="Signals") @@ -734,7 +759,7 @@ class SignalReceiver(Frame): vbox.pack_end(hbox) bt = Button(self, text='Clear') - bt.callback_clicked_add(lambda b: self.siglist.clear()) + bt.callback_clicked_add(lambda b_: self.siglist.clear()) hbox.pack_end(bt) bt.show() @@ -747,9 +772,10 @@ class SignalReceiver(Frame): ck.show() for b in session_bus, system_bus: - b.add_signal_receiver(self.signal_cb, sender_keyword='sender', + b.add_signal_receiver( + self.signal_cb, sender_keyword='sender', destination_keyword='dest', interface_keyword='iface', - member_keyword='signal',path_keyword='path') + member_keyword='signal', path_keyword='path') def signal_cb(self, *args, **kargs): # print('*** SIGNAL RECEIVED ***') @@ -784,7 +810,8 @@ class SignalReceiver(Frame): pp.content = tb rect = Rectangle(pp.evas, size_hint_min=(200, 200), - size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) + size_hint_weight=EXPAND_BOTH, + size_hint_align=FILL_BOTH) tb.pack(rect, 0, 0, 1, 1) en = Entry(self, @@ -810,7 +837,7 @@ class SignalReceiver(Frame): pp.show() -### The main window +# The main window class EspionageWin(StandardWindow): def __init__(self): StandardWindow.__init__(self, "espionage", "Espionage D-Bus inspector") @@ -896,6 +923,7 @@ class EspionageWin(StandardWindow): options.show_introspect_stuff = chk.state self.detail_list.populate(self.detail_list.service_name) + def main(): elm.init() win = EspionageWin() @@ -906,4 +934,3 @@ def main(): if __name__ == "__main__": sys.exit(main()) - diff --git a/setup.py b/setup.py index 246ac54..89844c0 100755 --- a/setup.py +++ b/setup.py @@ -5,28 +5,27 @@ from efl.utils.setup import build_extra, build_fdo, uninstall setup( - name = 'espionage', - version = '1.0', - description = 'D-Bus inspector', - long_description = 'Espionage is a complete D-Bus inspector', - url = 'https://phab.enlightenment.org/w/projects/espionage/', - license = "GNU GPL", - author = 'Dave Andreoli', - author_email = 'd...@gurumeditation.it', - packages = ['espionage'], - requires = ['efl (>=1.13)', 'dbus', 'json', 'xml.etree'], - provides = ['espionage'], - scripts = ['bin/espionage'], - package_data = { + name='espionage', + version='1.0', + description='D-Bus inspector', + long_description='Espionage is a complete D-Bus inspector', + url='https://phab.enlightenment.org/w/projects/espionage/', + license="GNU GPL", + author='Dave Andreoli', + author_email='d...@gurumeditation.it', + packages=['espionage'], + requires=['efl (>=1.13)', 'dbus', 'json', 'xml.etree'], + provides=['espionage'], + scripts=['bin/espionage'], + package_data={ 'espionage': ['themes/*/*'], }, - cmdclass = { + cmdclass={ 'build': build_extra, 'build_fdo': build_fdo, 'uninstall': uninstall, }, - command_options = { + command_options={ 'install': {'record': ('setup.py', 'installed_files.txt')} }, ) - --