comparison sat/bridge/bridge_constructor/constructors/dbus/dbus_frontend_template.py @ 3028:ab2696e34d29

Python 3 port: /!\ this is a huge commit /!\ starting from this commit, SàT is needs Python 3.6+ /!\ SàT maybe be instable or some feature may not work anymore, this will improve with time This patch port backend, bridge and frontends to Python 3. Roughly this has been done this way: - 2to3 tools has been applied (with python 3.7) - all references to python2 have been replaced with python3 (notably shebangs) - fixed files not handled by 2to3 (notably the shell script) - several manual fixes - fixed issues reported by Python 3 that where not handled in Python 2 - replaced "async" with "async_" when needed (it's a reserved word from Python 3.7) - replaced zope's "implements" with @implementer decorator - temporary hack to handle data pickled in database, as str or bytes may be returned, to be checked later - fixed hash comparison for password - removed some code which is not needed anymore with Python 3 - deactivated some code which needs to be checked (notably certificate validation) - tested with jp, fixed reported issues until some basic commands worked - ported Primitivus (after porting dependencies like urwid satext) - more manual fixes
author Goffi <goffi@goffi.org>
date Tue, 13 Aug 2019 19:08:41 +0200
parents 003b8b4b56a7
children 964abd07dc03
comparison
equal deleted inserted replaced
3027:ff5bcb12ae60 3028:ab2696e34d29
1 #!/usr/bin/env python2 1 #!/usr/bin/env python3
2 #-*- coding: utf-8 -*- 2 #-*- coding: utf-8 -*-
3 3
4 # SAT communication bridge 4 # SAT communication bridge
5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) 5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org)
6 6
68 const_OBJ_PATH) 68 const_OBJ_PATH)
69 self.db_core_iface = dbus.Interface(self.db_object, 69 self.db_core_iface = dbus.Interface(self.db_object,
70 dbus_interface=const_INT_PREFIX + const_CORE_SUFFIX) 70 dbus_interface=const_INT_PREFIX + const_CORE_SUFFIX)
71 self.db_plugin_iface = dbus.Interface(self.db_object, 71 self.db_plugin_iface = dbus.Interface(self.db_object,
72 dbus_interface=const_INT_PREFIX + const_PLUGIN_SUFFIX) 72 dbus_interface=const_INT_PREFIX + const_PLUGIN_SUFFIX)
73 except dbus.exceptions.DBusException, e: 73 except dbus.exceptions.DBusException as e:
74 if e._dbus_error_name in ('org.freedesktop.DBus.Error.ServiceUnknown', 74 if e._dbus_error_name in ('org.freedesktop.DBus.Error.ServiceUnknown',
75 'org.freedesktop.DBus.Error.Spawn.ExecFailed'): 75 'org.freedesktop.DBus.Error.Spawn.ExecFailed'):
76 errback(BridgeExceptionNoService()) 76 errback(BridgeExceptionNoService())
77 elif e._dbus_error_name == 'org.freedesktop.DBus.Error.NotSupported': 77 elif e._dbus_error_name == 'org.freedesktop.DBus.Error.NotSupported':
78 log.error(_(u"D-Bus is not launched, please see README to see instructions on how to launch it")) 78 log.error(_("D-Bus is not launched, please see README to see instructions on how to launch it"))
79 errback(BridgeInitError) 79 errback(BridgeInitError)
80 else: 80 else:
81 errback(e) 81 errback(e)
82 callback() 82 callback()
83 #props = self.db_core_iface.getProperties() 83 #props = self.db_core_iface.getProperties()
100 def getPluginMethod(*args, **kwargs): 100 def getPluginMethod(*args, **kwargs):
101 # We first check if we have an async call. We detect this in two ways: 101 # We first check if we have an async call. We detect this in two ways:
102 # - if we have the 'callback' and 'errback' keyword arguments 102 # - if we have the 'callback' and 'errback' keyword arguments
103 # - or if the last two arguments are callable 103 # - or if the last two arguments are callable
104 104
105 async = False 105 async_ = False
106 args = list(args) 106 args = list(args)
107 107
108 if kwargs: 108 if kwargs:
109 if 'callback' in kwargs: 109 if 'callback' in kwargs:
110 async = True 110 async_ = True
111 _callback = kwargs.pop('callback') 111 _callback = kwargs.pop('callback')
112 _errback = kwargs.pop('errback', lambda failure: log.error(unicode(failure))) 112 _errback = kwargs.pop('errback', lambda failure: log.error(str(failure)))
113 try: 113 try:
114 args.append(kwargs.pop('profile')) 114 args.append(kwargs.pop('profile'))
115 except KeyError: 115 except KeyError:
116 try: 116 try:
117 args.append(kwargs.pop('profile_key')) 117 args.append(kwargs.pop('profile_key'))
118 except KeyError: 118 except KeyError:
119 pass 119 pass
120 # at this point, kwargs should be empty 120 # at this point, kwargs should be empty
121 if kwargs: 121 if kwargs:
122 log.warnings(u"unexpected keyword arguments, they will be ignored: {}".format(kwargs)) 122 log.warnings("unexpected keyword arguments, they will be ignored: {}".format(kwargs))
123 elif len(args) >= 2 and callable(args[-1]) and callable(args[-2]): 123 elif len(args) >= 2 and callable(args[-1]) and callable(args[-2]):
124 async = True 124 async_ = True
125 _errback = args.pop() 125 _errback = args.pop()
126 _callback = args.pop() 126 _callback = args.pop()
127 127
128 method = getattr(self.db_plugin_iface, name) 128 method = getattr(self.db_plugin_iface, name)
129 129
130 if async: 130 if async_:
131 kwargs['timeout'] = const_TIMEOUT 131 kwargs['timeout'] = const_TIMEOUT
132 kwargs['reply_handler'] = _callback 132 kwargs['reply_handler'] = _callback
133 kwargs['error_handler'] = lambda err: _errback(dbus_to_bridge_exception(err)) 133 kwargs['error_handler'] = lambda err: _errback(dbus_to_bridge_exception(err))
134 134
135 return method(*args, **kwargs) 135 return method(*args, **kwargs)