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
This commit is contained in:
parent
d21a6a660f
commit
fbfe96c505
173 changed files with 6336 additions and 6398 deletions
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SàT: a XMPP client
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SàT: a XMPP client
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
"""base constructor class"""
|
||||
|
||||
from sat.bridge.bridge_constructor.constants import Const as C
|
||||
from ConfigParser import NoOptionError
|
||||
from configparser import NoOptionError
|
||||
import sys
|
||||
import os
|
||||
import os.path
|
||||
|
|
@ -191,7 +191,7 @@ class Constructor(object):
|
|||
for arg in self.argumentsParser(signature):
|
||||
attr_string.append(
|
||||
(
|
||||
"unicode(%(name)s)%(default)s"
|
||||
"str(%(name)s)%(default)s"
|
||||
if (unicode_protect and arg == "s")
|
||||
else "%(name)s%(default)s"
|
||||
)
|
||||
|
|
@ -240,7 +240,7 @@ class Constructor(object):
|
|||
method = self.generateCoreSide
|
||||
elif side == "frontend":
|
||||
if not self.FRONTEND_ACTIVATE:
|
||||
print(u"This constructor only handle core, please use core side")
|
||||
print("This constructor only handle core, please use core side")
|
||||
sys.exit(1)
|
||||
method = self.generateFrontendSide
|
||||
except AttributeError:
|
||||
|
|
@ -271,7 +271,7 @@ class Constructor(object):
|
|||
sections.sort()
|
||||
for section in sections:
|
||||
function = self.getValues(section)
|
||||
print("Adding %s %s" % (section, function["type"]))
|
||||
print(("Adding %s %s" % (section, function["type"])))
|
||||
default = self.getDefault(section)
|
||||
arg_doc = self.getArgumentsDoc(section)
|
||||
async_ = "async" in self.getFlags(section)
|
||||
|
|
@ -291,7 +291,7 @@ class Constructor(object):
|
|||
)
|
||||
extend_method(completion, function, default, arg_doc, async_)
|
||||
|
||||
for part, fmt in FORMATS.iteritems():
|
||||
for part, fmt in FORMATS.items():
|
||||
if part.startswith(function["type"]):
|
||||
parts[part.upper()].append(fmt.format(**completion))
|
||||
|
||||
|
|
@ -300,7 +300,7 @@ class Constructor(object):
|
|||
bridge = []
|
||||
const_override = {
|
||||
env[len(C.ENV_OVERRIDE) :]: v
|
||||
for env, v in os.environ.iteritems()
|
||||
for env, v in os.environ.items()
|
||||
if env.startswith(C.ENV_OVERRIDE)
|
||||
}
|
||||
template_path = self.getTemplatePath(TEMPLATE)
|
||||
|
|
@ -308,7 +308,7 @@ class Constructor(object):
|
|||
with open(template_path) as template:
|
||||
for line in template:
|
||||
|
||||
for part, extend_list in parts.iteritems():
|
||||
for part, extend_list in parts.items():
|
||||
if line.startswith("##{}_PART##".format(part)):
|
||||
bridge.extend(extend_list)
|
||||
break
|
||||
|
|
@ -317,7 +317,7 @@ class Constructor(object):
|
|||
if line.startswith("const_"):
|
||||
const_name = line[len("const_") : line.find(" = ")].strip()
|
||||
if const_name in const_override:
|
||||
print("const {} overriden".format(const_name))
|
||||
print(("const {} overriden".format(const_name)))
|
||||
bridge.append(
|
||||
"const_{} = {}".format(
|
||||
const_name, const_override[const_name]
|
||||
|
|
@ -326,7 +326,7 @@ class Constructor(object):
|
|||
continue
|
||||
bridge.append(line.replace("\n", ""))
|
||||
except IOError:
|
||||
print("can't open template file [{}]".format(template_path))
|
||||
print(("can't open template file [{}]".format(template_path)))
|
||||
sys.exit(1)
|
||||
|
||||
# now we write to final file
|
||||
|
|
@ -348,15 +348,15 @@ class Constructor(object):
|
|||
os.mkdir(self.args.dest_dir)
|
||||
full_path = os.path.join(self.args.dest_dir, filename)
|
||||
if os.path.exists(full_path) and not self.args.force:
|
||||
print(
|
||||
print((
|
||||
"The destination file [%s] already exists ! Use --force to overwrite it"
|
||||
% full_path
|
||||
)
|
||||
))
|
||||
try:
|
||||
with open(full_path, "w") as dest_file:
|
||||
dest_file.write("\n".join(file_buf))
|
||||
except IOError:
|
||||
print("Can't open destination file [%s]" % full_path)
|
||||
print(("Can't open destination file [%s]" % full_path))
|
||||
except OSError:
|
||||
print("It's not possible to generate the file, check your permissions")
|
||||
exit(1)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SàT: a XMPP client
|
||||
|
|
@ -22,7 +22,7 @@ from sat.bridge import bridge_constructor
|
|||
from sat.bridge.bridge_constructor.constants import Const as C
|
||||
from sat.bridge.bridge_constructor import constructors, base_constructor
|
||||
import argparse
|
||||
from ConfigParser import SafeConfigParser as Parser
|
||||
from configparser import ConfigParser as Parser
|
||||
from importlib import import_module
|
||||
import os
|
||||
import os.path
|
||||
|
|
@ -87,7 +87,7 @@ class BridgeConstructor(object):
|
|||
parser.add_argument(
|
||||
"-t",
|
||||
"--template",
|
||||
type=file,
|
||||
type=argparse.FileType(),
|
||||
default=default_template,
|
||||
help="use TEMPLATE to generate bridge (default: %(default)s)",
|
||||
)
|
||||
|
|
|
|||
|
|
@ -507,7 +507,7 @@ sig_in=sss
|
|||
sig_out=s
|
||||
doc=Get XMLUI to manage trust for given encryption algorithm
|
||||
doc_param_0=to_jid: bare JID of entity to manage
|
||||
doc_param_0=namespace: namespace of the algorithm to manage
|
||||
doc_param_1=namespace: namespace of the algorithm to manage
|
||||
doc_param_2=%(doc_profile_key)s
|
||||
doc_return=(XMLUI) UI of the trust management
|
||||
|
||||
|
|
@ -811,7 +811,7 @@ sig_in=ssbs
|
|||
sig_out=(asa(sss)a{sa(a{ss}as)})
|
||||
param_1_default=u''
|
||||
param_2_default=True
|
||||
param_3_default=u"@DEFAULT@"
|
||||
param_3_default="@DEFAULT@"
|
||||
doc=Discover infos on an entity
|
||||
doc_param_0=entity_jid: JID to discover
|
||||
doc_param_1=node: node to use
|
||||
|
|
@ -837,7 +837,7 @@ sig_in=ssbs
|
|||
sig_out=a(sss)
|
||||
param_1_default=u''
|
||||
param_2_default=True
|
||||
param_3_default=u"@DEFAULT@"
|
||||
param_3_default="@DEFAULT@"
|
||||
doc=Discover items of an entity
|
||||
doc_param_0=entity_jid: JID to discover
|
||||
doc_param_1=node: node to use
|
||||
|
|
@ -856,7 +856,7 @@ param_3_default=True
|
|||
param_4_default=True
|
||||
param_5_default=True
|
||||
param_6_default=False
|
||||
param_7_default=u"@DEFAULT@"
|
||||
param_7_default="@DEFAULT@"
|
||||
doc=Discover items of an entity
|
||||
doc_param_0=namespaces: namespaces of the features to check
|
||||
doc_param_1=identities: identities to filter
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SàT: a XMPP client
|
||||
|
|
@ -22,9 +22,9 @@ from sat.core import constants
|
|||
|
||||
class Const(constants.Const):
|
||||
|
||||
NAME = u"bridge_constructor"
|
||||
NAME = "bridge_constructor"
|
||||
DEST_DIR_DEFAULT = "generated"
|
||||
DESCRIPTION = u"""{name} Copyright (C) 2009-2019 Jérôme Poisson (aka Goffi)
|
||||
DESCRIPTION = """{name} Copyright (C) 2009-2019 Jérôme Poisson (aka Goffi)
|
||||
|
||||
This script construct a SàT bridge using the given protocol
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SàT: a XMPP client
|
||||
|
|
@ -53,7 +53,7 @@ class DbusXmlConstructor(base_constructor.Constructor):
|
|||
sections.sort()
|
||||
for section in sections:
|
||||
function = self.getValues(section)
|
||||
print("Adding %s %s" % (section, function["type"]))
|
||||
print(("Adding %s %s" % (section, function["type"])))
|
||||
new_elt = doc.createElement(
|
||||
"method" if function["type"] == "method" else "signal"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SàT: a XMPP client
|
||||
|
|
@ -114,5 +114,5 @@ class DbusConstructor(base_constructor.Constructor):
|
|||
% completion
|
||||
)
|
||||
completion["result"] = (
|
||||
"unicode(%s)" if self.args.unicode and function["sig_out"] == "s" else "%s"
|
||||
"str(%s)" if self.args.unicode and function["sig_out"] == "s" else "%s"
|
||||
) % result
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SAT: a jabber client
|
||||
|
|
@ -101,11 +101,11 @@ class DbusObject(dbus.service.Object):
|
|||
raise InternalError
|
||||
callback = kwargs.pop("callback")
|
||||
errback = kwargs.pop("errback")
|
||||
async = True
|
||||
async_ = True
|
||||
else:
|
||||
async = False
|
||||
async_ = False
|
||||
result = self.cb[name](*args, **kwargs)
|
||||
if async:
|
||||
if async_:
|
||||
if not isinstance(result, Deferred):
|
||||
log.error("Asynchronous method [%s] does not return a Deferred." % name)
|
||||
raise AsyncNotDeferred
|
||||
|
|
@ -170,9 +170,9 @@ class DbusObject(dbus.service.Object):
|
|||
i += 1
|
||||
return attr
|
||||
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False):
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async_=False):
|
||||
"""Dynamically add a method to Dbus Bridge"""
|
||||
inspect_args = inspect.getargspec(method)
|
||||
inspect_args = inspect.getfullargspec(method)
|
||||
|
||||
_arguments = inspect_args.args
|
||||
_defaults = list(inspect_args.defaults or [])
|
||||
|
|
@ -186,12 +186,12 @@ class DbusObject(dbus.service.Object):
|
|||
[repr(name)]
|
||||
+ (
|
||||
(_arguments + ["callback=callback", "errback=errback"])
|
||||
if async
|
||||
if async_
|
||||
else _arguments
|
||||
)
|
||||
)
|
||||
|
||||
if async:
|
||||
if async_:
|
||||
_arguments.extend(["callback", "errback"])
|
||||
_defaults.extend([None, None])
|
||||
|
||||
|
|
@ -213,7 +213,7 @@ class DbusObject(dbus.service.Object):
|
|||
)
|
||||
exec(code) # FIXME: to the same thing in a cleaner way, without compile/exec
|
||||
method = locals()[name]
|
||||
async_callbacks = ("callback", "errback") if async else None
|
||||
async_callbacks = ("callback", "errback") if async_ else None
|
||||
setattr(
|
||||
DbusObject,
|
||||
name,
|
||||
|
|
@ -265,7 +265,7 @@ class Bridge(object):
|
|||
if e._dbus_error_name == "org.freedesktop.DBus.Error.NotSupported":
|
||||
log.error(
|
||||
_(
|
||||
u"D-Bus is not launched, please see README to see instructions on how to launch it"
|
||||
"D-Bus is not launched, please see README to see instructions on how to launch it"
|
||||
)
|
||||
)
|
||||
raise BridgeInitError
|
||||
|
|
@ -277,11 +277,11 @@ class Bridge(object):
|
|||
log.debug("registering DBus bridge method [%s]" % name)
|
||||
self.dbus_bridge.register_method(name, callback)
|
||||
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False, doc={}):
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async_=False, doc={}):
|
||||
"""Dynamically add a method to Dbus Bridge"""
|
||||
# FIXME: doc parameter is kept only temporary, the time to remove it from calls
|
||||
log.debug("Adding method [%s] to DBus bridge" % name)
|
||||
self.dbus_bridge.addMethod(name, int_suffix, in_sign, out_sign, method, async)
|
||||
self.dbus_bridge.addMethod(name, int_suffix, in_sign, out_sign, method, async_)
|
||||
self.register_method(name, method)
|
||||
|
||||
def addSignal(self, name, int_suffix, signature, doc={}):
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
#-*- coding: utf-8 -*-
|
||||
|
||||
# SAT communication bridge
|
||||
|
|
@ -70,12 +70,12 @@ class Bridge(object):
|
|||
dbus_interface=const_INT_PREFIX + const_CORE_SUFFIX)
|
||||
self.db_plugin_iface = dbus.Interface(self.db_object,
|
||||
dbus_interface=const_INT_PREFIX + const_PLUGIN_SUFFIX)
|
||||
except dbus.exceptions.DBusException, e:
|
||||
except dbus.exceptions.DBusException as e:
|
||||
if e._dbus_error_name in ('org.freedesktop.DBus.Error.ServiceUnknown',
|
||||
'org.freedesktop.DBus.Error.Spawn.ExecFailed'):
|
||||
errback(BridgeExceptionNoService())
|
||||
elif e._dbus_error_name == 'org.freedesktop.DBus.Error.NotSupported':
|
||||
log.error(_(u"D-Bus is not launched, please see README to see instructions on how to launch it"))
|
||||
log.error(_("D-Bus is not launched, please see README to see instructions on how to launch it"))
|
||||
errback(BridgeInitError)
|
||||
else:
|
||||
errback(e)
|
||||
|
|
@ -102,14 +102,14 @@ class Bridge(object):
|
|||
# - if we have the 'callback' and 'errback' keyword arguments
|
||||
# - or if the last two arguments are callable
|
||||
|
||||
async = False
|
||||
async_ = False
|
||||
args = list(args)
|
||||
|
||||
if kwargs:
|
||||
if 'callback' in kwargs:
|
||||
async = True
|
||||
async_ = True
|
||||
_callback = kwargs.pop('callback')
|
||||
_errback = kwargs.pop('errback', lambda failure: log.error(unicode(failure)))
|
||||
_errback = kwargs.pop('errback', lambda failure: log.error(str(failure)))
|
||||
try:
|
||||
args.append(kwargs.pop('profile'))
|
||||
except KeyError:
|
||||
|
|
@ -119,15 +119,15 @@ class Bridge(object):
|
|||
pass
|
||||
# at this point, kwargs should be empty
|
||||
if kwargs:
|
||||
log.warnings(u"unexpected keyword arguments, they will be ignored: {}".format(kwargs))
|
||||
log.warnings("unexpected keyword arguments, they will be ignored: {}".format(kwargs))
|
||||
elif len(args) >= 2 and callable(args[-1]) and callable(args[-2]):
|
||||
async = True
|
||||
async_ = True
|
||||
_errback = args.pop()
|
||||
_callback = args.pop()
|
||||
|
||||
method = getattr(self.db_plugin_iface, name)
|
||||
|
||||
if async:
|
||||
if async_:
|
||||
kwargs['timeout'] = const_TIMEOUT
|
||||
kwargs['reply_handler'] = _callback
|
||||
kwargs['error_handler'] = lambda err: _errback(dbus_to_bridge_exception(err))
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SàT: a XMPP client
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SàT: a XMPP client
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SàT: a XMPP client
|
||||
|
|
@ -25,7 +25,7 @@ from sat.core import exceptions
|
|||
|
||||
class _Bridge(object):
|
||||
def __init__(self):
|
||||
log.debug(u"Init embedded bridge...")
|
||||
log.debug("Init embedded bridge...")
|
||||
self._methods_cbs = {}
|
||||
self._signals_cbs = {"core": {}, "plugin": {}}
|
||||
|
||||
|
|
@ -33,16 +33,16 @@ class _Bridge(object):
|
|||
callback()
|
||||
|
||||
def register_method(self, name, callback):
|
||||
log.debug(u"registering embedded bridge method [{}]".format(name))
|
||||
log.debug("registering embedded bridge method [{}]".format(name))
|
||||
if name in self._methods_cbs:
|
||||
raise exceptions.ConflictError(u"method {} is already regitered".format(name))
|
||||
raise exceptions.ConflictError("method {} is already regitered".format(name))
|
||||
self._methods_cbs[name] = callback
|
||||
|
||||
def register_signal(self, functionName, handler, iface="core"):
|
||||
iface_dict = self._signals_cbs[iface]
|
||||
if functionName in iface_dict:
|
||||
raise exceptions.ConflictError(
|
||||
u"signal {name} is already regitered for interface {iface}".format(
|
||||
"signal {name} is already regitered for interface {iface}".format(
|
||||
name=functionName, iface=iface
|
||||
)
|
||||
)
|
||||
|
|
@ -81,11 +81,11 @@ class _Bridge(object):
|
|||
try:
|
||||
cb = self._signals_cbs["plugin"][name]
|
||||
except KeyError:
|
||||
log.debug(u"ignoring signal {}: no callback registered".format(name))
|
||||
log.debug("ignoring signal {}: no callback registered".format(name))
|
||||
else:
|
||||
cb(*args, **kwargs)
|
||||
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False, doc={}):
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async_=False, doc={}):
|
||||
# FIXME: doc parameter is kept only temporary, the time to remove it from calls
|
||||
log.debug("Adding method [{}] to embedded bridge".format(name))
|
||||
self.register_method(name, method)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SàT: a XMPP client
|
||||
|
|
@ -85,7 +85,7 @@ class MediawikiConstructor(base_constructor.Constructor):
|
|||
sections.sort()
|
||||
for section in sections:
|
||||
function = self.getValues(section)
|
||||
print("Adding %s %s" % (section, function["type"]))
|
||||
print(("Adding %s %s" % (section, function["type"])))
|
||||
async_msg = """<br />'''This method is asynchronous'''"""
|
||||
deprecated_msg = """<br />'''<font color="#FF0000">/!\ WARNING /!\ : This method is deprecated, please don't use it !</font>'''"""
|
||||
signature_signal = (
|
||||
|
|
@ -161,7 +161,7 @@ class MediawikiConstructor(base_constructor.Constructor):
|
|||
else:
|
||||
core_bridge.append(line.replace("\n", ""))
|
||||
except IOError:
|
||||
print("Can't open template file [%s]" % template_path)
|
||||
print(("Can't open template file [%s]" % template_path))
|
||||
sys.exit(1)
|
||||
|
||||
# now we write to final file
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SàT: a XMPP client
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SAT: a jabber client
|
||||
|
|
@ -46,11 +46,11 @@ class PBRoot(pb.Root):
|
|||
|
||||
def remote_initBridge(self, signals_handler):
|
||||
self.signals_handlers.append(signals_handler)
|
||||
log.info(u"registered signal handler")
|
||||
log.info("registered signal handler")
|
||||
|
||||
def sendSignalEb(self, failure, signal_name):
|
||||
log.error(
|
||||
u"Error while sending signal {name}: {msg}".format(
|
||||
"Error while sending signal {name}: {msg}".format(
|
||||
name=signal_name, msg=failure
|
||||
)
|
||||
)
|
||||
|
|
@ -66,27 +66,27 @@ class PBRoot(pb.Root):
|
|||
d.addErrback(self.sendSignalEb, name)
|
||||
if to_remove:
|
||||
for handler in to_remove:
|
||||
log.debug(u"Removing signal handler for dead frontend")
|
||||
log.debug("Removing signal handler for dead frontend")
|
||||
self.signals_handlers.remove(handler)
|
||||
|
||||
def _bridgeDeactivateSignals(self):
|
||||
if hasattr(self, "signals_paused"):
|
||||
log.warning(u"bridge signals already deactivated")
|
||||
log.warning("bridge signals already deactivated")
|
||||
if self.signals_handler:
|
||||
self.signals_paused.extend(self.signals_handler)
|
||||
else:
|
||||
self.signals_paused = self.signals_handlers
|
||||
self.signals_handlers = []
|
||||
log.debug(u"bridge signals have been deactivated")
|
||||
log.debug("bridge signals have been deactivated")
|
||||
|
||||
def _bridgeReactivateSignals(self):
|
||||
try:
|
||||
self.signals_handlers = self.signals_paused
|
||||
except AttributeError:
|
||||
log.debug(u"signals were already activated")
|
||||
log.debug("signals were already activated")
|
||||
else:
|
||||
del self.signals_paused
|
||||
log.debug(u"bridge signals have been reactivated")
|
||||
log.debug("bridge signals have been reactivated")
|
||||
|
||||
##METHODS_PART##
|
||||
|
||||
|
|
@ -102,14 +102,14 @@ class Bridge(object):
|
|||
|
||||
def remote_initBridge(self, signals_handler):
|
||||
self.signals_handlers.append(signals_handler)
|
||||
log.info(u"registered signal handler")
|
||||
log.info("registered signal handler")
|
||||
|
||||
def register_method(self, name, callback):
|
||||
log.debug("registering PB bridge method [%s]" % name)
|
||||
setattr(self.root, "remote_" + name, callback)
|
||||
# self.root.register_method(name, callback)
|
||||
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False, doc={}):
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async_=False, doc={}):
|
||||
"""Dynamically add a method to PB Bridge"""
|
||||
# FIXME: doc parameter is kept only temporary, the time to remove it from calls
|
||||
log.debug("Adding method {name} to PB bridge".format(name=name))
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SAT communication bridge
|
||||
|
|
@ -28,7 +28,7 @@ from twisted.internet import reactor
|
|||
class SignalsHandler(pb.Referenceable):
|
||||
def __getattr__(self, name):
|
||||
if name.startswith("remote_"):
|
||||
log.debug(u"calling an unregistered signal: {name}".format(name=name[7:]))
|
||||
log.debug("calling an unregistered signal: {name}".format(name=name[7:]))
|
||||
return lambda *args, **kwargs: None
|
||||
|
||||
else:
|
||||
|
|
@ -43,7 +43,7 @@ class SignalsHandler(pb.Referenceable):
|
|||
pass
|
||||
else:
|
||||
raise exceptions.InternalError(
|
||||
u"{name} signal handler has been registered twice".format(
|
||||
"{name} signal handler has been registered twice".format(
|
||||
name=method_name
|
||||
)
|
||||
)
|
||||
|
|
@ -99,7 +99,7 @@ class Bridge(object):
|
|||
d.addErrback(errback)
|
||||
|
||||
def _initBridgeEb(self, failure):
|
||||
log.error(u"Can't init bridge: {msg}".format(msg=failure))
|
||||
log.error("Can't init bridge: {msg}".format(msg=failure))
|
||||
|
||||
def _set_root(self, root):
|
||||
"""set remote root object
|
||||
|
|
@ -112,7 +112,7 @@ class Bridge(object):
|
|||
return d
|
||||
|
||||
def _generic_errback(self, failure):
|
||||
log.error(u"bridge failure: {}".format(failure))
|
||||
log.error("bridge failure: {}".format(failure))
|
||||
|
||||
def bridgeConnect(self, callback, errback):
|
||||
factory = pb.PBClientFactory()
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SAT: a jabber client
|
||||
|
|
@ -101,11 +101,11 @@ class DbusObject(dbus.service.Object):
|
|||
raise InternalError
|
||||
callback = kwargs.pop("callback")
|
||||
errback = kwargs.pop("errback")
|
||||
async = True
|
||||
async_ = True
|
||||
else:
|
||||
async = False
|
||||
async_ = False
|
||||
result = self.cb[name](*args, **kwargs)
|
||||
if async:
|
||||
if async_:
|
||||
if not isinstance(result, Deferred):
|
||||
log.error("Asynchronous method [%s] does not return a Deferred." % name)
|
||||
raise AsyncNotDeferred
|
||||
|
|
@ -214,73 +214,73 @@ class DbusObject(dbus.service.Object):
|
|||
in_signature='s', out_signature='a(a{ss}si)',
|
||||
async_callbacks=None)
|
||||
def actionsGet(self, profile_key="@DEFAULT@"):
|
||||
return self._callback("actionsGet", unicode(profile_key))
|
||||
return self._callback("actionsGet", str(profile_key))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='ss', out_signature='',
|
||||
async_callbacks=None)
|
||||
def addContact(self, entity_jid, profile_key="@DEFAULT@"):
|
||||
return self._callback("addContact", unicode(entity_jid), unicode(profile_key))
|
||||
return self._callback("addContact", str(entity_jid), str(profile_key))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='s', out_signature='',
|
||||
async_callbacks=('callback', 'errback'))
|
||||
def asyncDeleteProfile(self, profile, callback=None, errback=None):
|
||||
return self._callback("asyncDeleteProfile", unicode(profile), callback=callback, errback=errback)
|
||||
return self._callback("asyncDeleteProfile", str(profile), callback=callback, errback=errback)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='sssis', out_signature='s',
|
||||
async_callbacks=('callback', 'errback'))
|
||||
def asyncGetParamA(self, name, category, attribute="value", security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None):
|
||||
return self._callback("asyncGetParamA", unicode(name), unicode(category), unicode(attribute), security_limit, unicode(profile_key), callback=callback, errback=errback)
|
||||
return self._callback("asyncGetParamA", str(name), str(category), str(attribute), security_limit, str(profile_key), callback=callback, errback=errback)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='sis', out_signature='a{ss}',
|
||||
async_callbacks=('callback', 'errback'))
|
||||
def asyncGetParamsValuesFromCategory(self, category, security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None):
|
||||
return self._callback("asyncGetParamsValuesFromCategory", unicode(category), security_limit, unicode(profile_key), callback=callback, errback=errback)
|
||||
return self._callback("asyncGetParamsValuesFromCategory", str(category), security_limit, str(profile_key), callback=callback, errback=errback)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='ssa{ss}', out_signature='b',
|
||||
async_callbacks=('callback', 'errback'))
|
||||
def connect(self, profile_key="@DEFAULT@", password='', options={}, callback=None, errback=None):
|
||||
return self._callback("connect", unicode(profile_key), unicode(password), options, callback=callback, errback=errback)
|
||||
return self._callback("connect", str(profile_key), str(password), options, callback=callback, errback=errback)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='ss', out_signature='',
|
||||
async_callbacks=('callback', 'errback'))
|
||||
def delContact(self, entity_jid, profile_key="@DEFAULT@", callback=None, errback=None):
|
||||
return self._callback("delContact", unicode(entity_jid), unicode(profile_key), callback=callback, errback=errback)
|
||||
return self._callback("delContact", str(entity_jid), str(profile_key), callback=callback, errback=errback)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='asa(ss)bbbbbs', out_signature='(a{sa(sss)}a{sa(sss)}a{sa(sss)})',
|
||||
async_callbacks=('callback', 'errback'))
|
||||
def discoFindByFeatures(self, namespaces, identities, bare_jid=False, service=True, roster=True, own_jid=True, local_device=False, profile_key=u"@DEFAULT@", callback=None, errback=None):
|
||||
return self._callback("discoFindByFeatures", namespaces, identities, bare_jid, service, roster, own_jid, local_device, unicode(profile_key), callback=callback, errback=errback)
|
||||
def discoFindByFeatures(self, namespaces, identities, bare_jid=False, service=True, roster=True, own_jid=True, local_device=False, profile_key="@DEFAULT@", callback=None, errback=None):
|
||||
return self._callback("discoFindByFeatures", namespaces, identities, bare_jid, service, roster, own_jid, local_device, str(profile_key), callback=callback, errback=errback)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='ssbs', out_signature='(asa(sss)a{sa(a{ss}as)})',
|
||||
async_callbacks=('callback', 'errback'))
|
||||
def discoInfos(self, entity_jid, node=u'', use_cache=True, profile_key=u"@DEFAULT@", callback=None, errback=None):
|
||||
return self._callback("discoInfos", unicode(entity_jid), unicode(node), use_cache, unicode(profile_key), callback=callback, errback=errback)
|
||||
def discoInfos(self, entity_jid, node=u'', use_cache=True, profile_key="@DEFAULT@", callback=None, errback=None):
|
||||
return self._callback("discoInfos", str(entity_jid), str(node), use_cache, str(profile_key), callback=callback, errback=errback)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='ssbs', out_signature='a(sss)',
|
||||
async_callbacks=('callback', 'errback'))
|
||||
def discoItems(self, entity_jid, node=u'', use_cache=True, profile_key=u"@DEFAULT@", callback=None, errback=None):
|
||||
return self._callback("discoItems", unicode(entity_jid), unicode(node), use_cache, unicode(profile_key), callback=callback, errback=errback)
|
||||
def discoItems(self, entity_jid, node=u'', use_cache=True, profile_key="@DEFAULT@", callback=None, errback=None):
|
||||
return self._callback("discoItems", str(entity_jid), str(node), use_cache, str(profile_key), callback=callback, errback=errback)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='s', out_signature='',
|
||||
async_callbacks=('callback', 'errback'))
|
||||
def disconnect(self, profile_key="@DEFAULT@", callback=None, errback=None):
|
||||
return self._callback("disconnect", unicode(profile_key), callback=callback, errback=errback)
|
||||
return self._callback("disconnect", str(profile_key), callback=callback, errback=errback)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='s', out_signature='s',
|
||||
async_callbacks=None)
|
||||
def encryptionNamespaceGet(self, arg_0):
|
||||
return self._callback("encryptionNamespaceGet", unicode(arg_0))
|
||||
return self._callback("encryptionNamespaceGet", str(arg_0))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='', out_signature='aa{ss}',
|
||||
|
|
@ -291,56 +291,56 @@ class DbusObject(dbus.service.Object):
|
|||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='sss', out_signature='s',
|
||||
async_callbacks=('callback', 'errback'))
|
||||
def encryptionTrustUIGet(self, namespace, arg_1, profile_key, callback=None, errback=None):
|
||||
return self._callback("encryptionTrustUIGet", unicode(namespace), unicode(arg_1), unicode(profile_key), callback=callback, errback=errback)
|
||||
def encryptionTrustUIGet(self, to_jid, namespace, profile_key, callback=None, errback=None):
|
||||
return self._callback("encryptionTrustUIGet", str(to_jid), str(namespace), str(profile_key), callback=callback, errback=errback)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='ss', out_signature='s',
|
||||
async_callbacks=None)
|
||||
def getConfig(self, section, name):
|
||||
return self._callback("getConfig", unicode(section), unicode(name))
|
||||
return self._callback("getConfig", str(section), str(name))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='s', out_signature='a(sa{ss}as)',
|
||||
async_callbacks=('callback', 'errback'))
|
||||
def getContacts(self, profile_key="@DEFAULT@", callback=None, errback=None):
|
||||
return self._callback("getContacts", unicode(profile_key), callback=callback, errback=errback)
|
||||
return self._callback("getContacts", str(profile_key), callback=callback, errback=errback)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='ss', out_signature='as',
|
||||
async_callbacks=None)
|
||||
def getContactsFromGroup(self, group, profile_key="@DEFAULT@"):
|
||||
return self._callback("getContactsFromGroup", unicode(group), unicode(profile_key))
|
||||
return self._callback("getContactsFromGroup", str(group), str(profile_key))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='asass', out_signature='a{sa{ss}}',
|
||||
async_callbacks=None)
|
||||
def getEntitiesData(self, jids, keys, profile):
|
||||
return self._callback("getEntitiesData", jids, keys, unicode(profile))
|
||||
return self._callback("getEntitiesData", jids, keys, str(profile))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='sass', out_signature='a{ss}',
|
||||
async_callbacks=None)
|
||||
def getEntityData(self, jid, keys, profile):
|
||||
return self._callback("getEntityData", unicode(jid), keys, unicode(profile))
|
||||
return self._callback("getEntityData", str(jid), keys, str(profile))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='s', out_signature='a{sa{ss}}',
|
||||
async_callbacks=('callback', 'errback'))
|
||||
def getFeatures(self, profile_key, callback=None, errback=None):
|
||||
return self._callback("getFeatures", unicode(profile_key), callback=callback, errback=errback)
|
||||
return self._callback("getFeatures", str(profile_key), callback=callback, errback=errback)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='ss', out_signature='s',
|
||||
async_callbacks=None)
|
||||
def getMainResource(self, contact_jid, profile_key="@DEFAULT@"):
|
||||
return self._callback("getMainResource", unicode(contact_jid), unicode(profile_key))
|
||||
return self._callback("getMainResource", str(contact_jid), str(profile_key))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='ssss', out_signature='s',
|
||||
async_callbacks=None)
|
||||
def getParamA(self, name, category, attribute="value", profile_key="@DEFAULT@"):
|
||||
return self._callback("getParamA", unicode(name), unicode(category), unicode(attribute), unicode(profile_key))
|
||||
return self._callback("getParamA", str(name), str(category), str(attribute), str(profile_key))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='', out_signature='as',
|
||||
|
|
@ -352,13 +352,13 @@ class DbusObject(dbus.service.Object):
|
|||
in_signature='iss', out_signature='s',
|
||||
async_callbacks=('callback', 'errback'))
|
||||
def getParamsUI(self, security_limit=-1, app='', profile_key="@DEFAULT@", callback=None, errback=None):
|
||||
return self._callback("getParamsUI", security_limit, unicode(app), unicode(profile_key), callback=callback, errback=errback)
|
||||
return self._callback("getParamsUI", security_limit, str(app), str(profile_key), callback=callback, errback=errback)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='s', out_signature='a{sa{s(sia{ss})}}',
|
||||
async_callbacks=None)
|
||||
def getPresenceStatuses(self, profile_key="@DEFAULT@"):
|
||||
return self._callback("getPresenceStatuses", unicode(profile_key))
|
||||
return self._callback("getPresenceStatuses", str(profile_key))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='', out_signature='',
|
||||
|
|
@ -376,73 +376,73 @@ class DbusObject(dbus.service.Object):
|
|||
in_signature='s', out_signature='a{ss}',
|
||||
async_callbacks=None)
|
||||
def getWaitingSub(self, profile_key="@DEFAULT@"):
|
||||
return self._callback("getWaitingSub", unicode(profile_key))
|
||||
return self._callback("getWaitingSub", str(profile_key))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='ssiba{ss}s', out_signature='a(sdssa{ss}a{ss}sa{ss})',
|
||||
async_callbacks=('callback', 'errback'))
|
||||
def historyGet(self, from_jid, to_jid, limit, between=True, filters='', profile="@NONE@", callback=None, errback=None):
|
||||
return self._callback("historyGet", unicode(from_jid), unicode(to_jid), limit, between, filters, unicode(profile), callback=callback, errback=errback)
|
||||
return self._callback("historyGet", str(from_jid), str(to_jid), limit, between, filters, str(profile), callback=callback, errback=errback)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='s', out_signature='b',
|
||||
async_callbacks=None)
|
||||
def isConnected(self, profile_key="@DEFAULT@"):
|
||||
return self._callback("isConnected", unicode(profile_key))
|
||||
return self._callback("isConnected", str(profile_key))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='sa{ss}s', out_signature='a{ss}',
|
||||
async_callbacks=('callback', 'errback'))
|
||||
def launchAction(self, callback_id, data, profile_key="@DEFAULT@", callback=None, errback=None):
|
||||
return self._callback("launchAction", unicode(callback_id), data, unicode(profile_key), callback=callback, errback=errback)
|
||||
return self._callback("launchAction", str(callback_id), data, str(profile_key), callback=callback, errback=errback)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='s', out_signature='b',
|
||||
async_callbacks=None)
|
||||
def loadParamsTemplate(self, filename):
|
||||
return self._callback("loadParamsTemplate", unicode(filename))
|
||||
return self._callback("loadParamsTemplate", str(filename))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='ss', out_signature='s',
|
||||
async_callbacks=None)
|
||||
def menuHelpGet(self, menu_id, language):
|
||||
return self._callback("menuHelpGet", unicode(menu_id), unicode(language))
|
||||
return self._callback("menuHelpGet", str(menu_id), str(language))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='sasa{ss}is', out_signature='a{ss}',
|
||||
async_callbacks=('callback', 'errback'))
|
||||
def menuLaunch(self, menu_type, path, data, security_limit, profile_key, callback=None, errback=None):
|
||||
return self._callback("menuLaunch", unicode(menu_type), path, data, security_limit, unicode(profile_key), callback=callback, errback=errback)
|
||||
return self._callback("menuLaunch", str(menu_type), path, data, security_limit, str(profile_key), callback=callback, errback=errback)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='si', out_signature='a(ssasasa{ss})',
|
||||
async_callbacks=None)
|
||||
def menusGet(self, language, security_limit):
|
||||
return self._callback("menusGet", unicode(language), security_limit)
|
||||
return self._callback("menusGet", str(language), security_limit)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='ss', out_signature='s',
|
||||
async_callbacks=None)
|
||||
def messageEncryptionGet(self, to_jid, profile_key):
|
||||
return self._callback("messageEncryptionGet", unicode(to_jid), unicode(profile_key))
|
||||
return self._callback("messageEncryptionGet", str(to_jid), str(profile_key))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='ssbs', out_signature='',
|
||||
async_callbacks=('callback', 'errback'))
|
||||
def messageEncryptionStart(self, to_jid, namespace='', replace=False, profile_key="@NONE@", callback=None, errback=None):
|
||||
return self._callback("messageEncryptionStart", unicode(to_jid), unicode(namespace), replace, unicode(profile_key), callback=callback, errback=errback)
|
||||
return self._callback("messageEncryptionStart", str(to_jid), str(namespace), replace, str(profile_key), callback=callback, errback=errback)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='ss', out_signature='',
|
||||
async_callbacks=('callback', 'errback'))
|
||||
def messageEncryptionStop(self, to_jid, profile_key, callback=None, errback=None):
|
||||
return self._callback("messageEncryptionStop", unicode(to_jid), unicode(profile_key), callback=callback, errback=errback)
|
||||
return self._callback("messageEncryptionStop", str(to_jid), str(profile_key), callback=callback, errback=errback)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='sa{ss}a{ss}sa{ss}s', out_signature='',
|
||||
async_callbacks=('callback', 'errback'))
|
||||
def messageSend(self, to_jid, message, subject={}, mess_type="auto", extra={}, profile_key="@NONE@", callback=None, errback=None):
|
||||
return self._callback("messageSend", unicode(to_jid), message, subject, unicode(mess_type), extra, unicode(profile_key), callback=callback, errback=errback)
|
||||
return self._callback("messageSend", str(to_jid), message, subject, str(mess_type), extra, str(profile_key), callback=callback, errback=errback)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='', out_signature='a{ss}',
|
||||
|
|
@ -454,37 +454,37 @@ class DbusObject(dbus.service.Object):
|
|||
in_signature='sis', out_signature='',
|
||||
async_callbacks=None)
|
||||
def paramsRegisterApp(self, xml, security_limit=-1, app=''):
|
||||
return self._callback("paramsRegisterApp", unicode(xml), security_limit, unicode(app))
|
||||
return self._callback("paramsRegisterApp", str(xml), security_limit, str(app))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='sss', out_signature='',
|
||||
async_callbacks=('callback', 'errback'))
|
||||
def profileCreate(self, profile, password='', component='', callback=None, errback=None):
|
||||
return self._callback("profileCreate", unicode(profile), unicode(password), unicode(component), callback=callback, errback=errback)
|
||||
return self._callback("profileCreate", str(profile), str(password), str(component), callback=callback, errback=errback)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='s', out_signature='b',
|
||||
async_callbacks=None)
|
||||
def profileIsSessionStarted(self, profile_key="@DEFAULT@"):
|
||||
return self._callback("profileIsSessionStarted", unicode(profile_key))
|
||||
return self._callback("profileIsSessionStarted", str(profile_key))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='s', out_signature='s',
|
||||
async_callbacks=None)
|
||||
def profileNameGet(self, profile_key="@DEFAULT@"):
|
||||
return self._callback("profileNameGet", unicode(profile_key))
|
||||
return self._callback("profileNameGet", str(profile_key))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='s', out_signature='',
|
||||
async_callbacks=None)
|
||||
def profileSetDefault(self, profile):
|
||||
return self._callback("profileSetDefault", unicode(profile))
|
||||
return self._callback("profileSetDefault", str(profile))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='ss', out_signature='b',
|
||||
async_callbacks=('callback', 'errback'))
|
||||
def profileStartSession(self, password='', profile_key="@DEFAULT@", callback=None, errback=None):
|
||||
return self._callback("profileStartSession", unicode(password), unicode(profile_key), callback=callback, errback=errback)
|
||||
return self._callback("profileStartSession", str(password), str(profile_key), callback=callback, errback=errback)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='bb', out_signature='as',
|
||||
|
|
@ -496,61 +496,61 @@ class DbusObject(dbus.service.Object):
|
|||
in_signature='ss', out_signature='a{ss}',
|
||||
async_callbacks=None)
|
||||
def progressGet(self, id, profile):
|
||||
return self._callback("progressGet", unicode(id), unicode(profile))
|
||||
return self._callback("progressGet", str(id), str(profile))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='s', out_signature='a{sa{sa{ss}}}',
|
||||
async_callbacks=None)
|
||||
def progressGetAll(self, profile):
|
||||
return self._callback("progressGetAll", unicode(profile))
|
||||
return self._callback("progressGetAll", str(profile))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='s', out_signature='a{sa{sa{ss}}}',
|
||||
async_callbacks=None)
|
||||
def progressGetAllMetadata(self, profile):
|
||||
return self._callback("progressGetAllMetadata", unicode(profile))
|
||||
return self._callback("progressGetAllMetadata", str(profile))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='s', out_signature='',
|
||||
async_callbacks=('callback', 'errback'))
|
||||
def rosterResync(self, profile_key="@DEFAULT@", callback=None, errback=None):
|
||||
return self._callback("rosterResync", unicode(profile_key), callback=callback, errback=errback)
|
||||
return self._callback("rosterResync", str(profile_key), callback=callback, errback=errback)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='s', out_signature='b',
|
||||
async_callbacks=None)
|
||||
def saveParamsTemplate(self, filename):
|
||||
return self._callback("saveParamsTemplate", unicode(filename))
|
||||
return self._callback("saveParamsTemplate", str(filename))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='s', out_signature='a{ss}',
|
||||
async_callbacks=('callback', 'errback'))
|
||||
def sessionInfosGet(self, profile_key, callback=None, errback=None):
|
||||
return self._callback("sessionInfosGet", unicode(profile_key), callback=callback, errback=errback)
|
||||
return self._callback("sessionInfosGet", str(profile_key), callback=callback, errback=errback)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='sssis', out_signature='',
|
||||
async_callbacks=None)
|
||||
def setParam(self, name, value, category, security_limit=-1, profile_key="@DEFAULT@"):
|
||||
return self._callback("setParam", unicode(name), unicode(value), unicode(category), security_limit, unicode(profile_key))
|
||||
return self._callback("setParam", str(name), str(value), str(category), security_limit, str(profile_key))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='ssa{ss}s', out_signature='',
|
||||
async_callbacks=None)
|
||||
def setPresence(self, to_jid='', show='', statuses={}, profile_key="@DEFAULT@"):
|
||||
return self._callback("setPresence", unicode(to_jid), unicode(show), statuses, unicode(profile_key))
|
||||
return self._callback("setPresence", str(to_jid), str(show), statuses, str(profile_key))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='sss', out_signature='',
|
||||
async_callbacks=None)
|
||||
def subscription(self, sub_type, entity, profile_key="@DEFAULT@"):
|
||||
return self._callback("subscription", unicode(sub_type), unicode(entity), unicode(profile_key))
|
||||
return self._callback("subscription", str(sub_type), str(entity), str(profile_key))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='ssass', out_signature='',
|
||||
async_callbacks=('callback', 'errback'))
|
||||
def updateContact(self, entity_jid, name, groups, profile_key="@DEFAULT@", callback=None, errback=None):
|
||||
return self._callback("updateContact", unicode(entity_jid), unicode(name), groups, unicode(profile_key), callback=callback, errback=errback)
|
||||
return self._callback("updateContact", str(entity_jid), str(name), groups, str(profile_key), callback=callback, errback=errback)
|
||||
|
||||
def __attributes(self, in_sign):
|
||||
"""Return arguments to user given a in_sign
|
||||
|
|
@ -590,9 +590,9 @@ class DbusObject(dbus.service.Object):
|
|||
i += 1
|
||||
return attr
|
||||
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False):
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async_=False):
|
||||
"""Dynamically add a method to Dbus Bridge"""
|
||||
inspect_args = inspect.getargspec(method)
|
||||
inspect_args = inspect.getfullargspec(method)
|
||||
|
||||
_arguments = inspect_args.args
|
||||
_defaults = list(inspect_args.defaults or [])
|
||||
|
|
@ -606,12 +606,12 @@ class DbusObject(dbus.service.Object):
|
|||
[repr(name)]
|
||||
+ (
|
||||
(_arguments + ["callback=callback", "errback=errback"])
|
||||
if async
|
||||
if async_
|
||||
else _arguments
|
||||
)
|
||||
)
|
||||
|
||||
if async:
|
||||
if async_:
|
||||
_arguments.extend(["callback", "errback"])
|
||||
_defaults.extend([None, None])
|
||||
|
||||
|
|
@ -633,7 +633,7 @@ class DbusObject(dbus.service.Object):
|
|||
)
|
||||
exec(code) # FIXME: to the same thing in a cleaner way, without compile/exec
|
||||
method = locals()[name]
|
||||
async_callbacks = ("callback", "errback") if async else None
|
||||
async_callbacks = ("callback", "errback") if async_ else None
|
||||
setattr(
|
||||
DbusObject,
|
||||
name,
|
||||
|
|
@ -685,7 +685,7 @@ class Bridge(object):
|
|||
if e._dbus_error_name == "org.freedesktop.DBus.Error.NotSupported":
|
||||
log.error(
|
||||
_(
|
||||
u"D-Bus is not launched, please see README to see instructions on how to launch it"
|
||||
"D-Bus is not launched, please see README to see instructions on how to launch it"
|
||||
)
|
||||
)
|
||||
raise BridgeInitError
|
||||
|
|
@ -744,11 +744,11 @@ class Bridge(object):
|
|||
log.debug("registering DBus bridge method [%s]" % name)
|
||||
self.dbus_bridge.register_method(name, callback)
|
||||
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False, doc={}):
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async_=False, doc={}):
|
||||
"""Dynamically add a method to Dbus Bridge"""
|
||||
# FIXME: doc parameter is kept only temporary, the time to remove it from calls
|
||||
log.debug("Adding method [%s] to DBus bridge" % name)
|
||||
self.dbus_bridge.addMethod(name, int_suffix, in_sign, out_sign, method, async)
|
||||
self.dbus_bridge.addMethod(name, int_suffix, in_sign, out_sign, method, async_)
|
||||
self.register_method(name, method)
|
||||
|
||||
def addSignal(self, name, int_suffix, signature, doc={}):
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SAT: a jabber client
|
||||
|
|
@ -46,11 +46,11 @@ class PBRoot(pb.Root):
|
|||
|
||||
def remote_initBridge(self, signals_handler):
|
||||
self.signals_handlers.append(signals_handler)
|
||||
log.info(u"registered signal handler")
|
||||
log.info("registered signal handler")
|
||||
|
||||
def sendSignalEb(self, failure, signal_name):
|
||||
log.error(
|
||||
u"Error while sending signal {name}: {msg}".format(
|
||||
"Error while sending signal {name}: {msg}".format(
|
||||
name=signal_name, msg=failure
|
||||
)
|
||||
)
|
||||
|
|
@ -66,27 +66,27 @@ class PBRoot(pb.Root):
|
|||
d.addErrback(self.sendSignalEb, name)
|
||||
if to_remove:
|
||||
for handler in to_remove:
|
||||
log.debug(u"Removing signal handler for dead frontend")
|
||||
log.debug("Removing signal handler for dead frontend")
|
||||
self.signals_handlers.remove(handler)
|
||||
|
||||
def _bridgeDeactivateSignals(self):
|
||||
if hasattr(self, "signals_paused"):
|
||||
log.warning(u"bridge signals already deactivated")
|
||||
log.warning("bridge signals already deactivated")
|
||||
if self.signals_handler:
|
||||
self.signals_paused.extend(self.signals_handler)
|
||||
else:
|
||||
self.signals_paused = self.signals_handlers
|
||||
self.signals_handlers = []
|
||||
log.debug(u"bridge signals have been deactivated")
|
||||
log.debug("bridge signals have been deactivated")
|
||||
|
||||
def _bridgeReactivateSignals(self):
|
||||
try:
|
||||
self.signals_handlers = self.signals_paused
|
||||
except AttributeError:
|
||||
log.debug(u"signals were already activated")
|
||||
log.debug("signals were already activated")
|
||||
else:
|
||||
del self.signals_paused
|
||||
log.debug(u"bridge signals have been reactivated")
|
||||
log.debug("bridge signals have been reactivated")
|
||||
|
||||
##METHODS_PART##
|
||||
|
||||
|
|
@ -102,14 +102,14 @@ class Bridge(object):
|
|||
|
||||
def remote_initBridge(self, signals_handler):
|
||||
self.signals_handlers.append(signals_handler)
|
||||
log.info(u"registered signal handler")
|
||||
log.info("registered signal handler")
|
||||
|
||||
def register_method(self, name, callback):
|
||||
log.debug("registering PB bridge method [%s]" % name)
|
||||
setattr(self.root, "remote_" + name, callback)
|
||||
# self.root.register_method(name, callback)
|
||||
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False, doc={}):
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async_=False, doc={}):
|
||||
"""Dynamically add a method to PB Bridge"""
|
||||
# FIXME: doc parameter is kept only temporary, the time to remove it from calls
|
||||
log.debug("Adding method {name} to PB bridge".format(name=name))
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SàT: a XMPP client
|
||||
|
|
@ -28,21 +28,21 @@ import sat
|
|||
class Const(object):
|
||||
|
||||
## Application ##
|
||||
APP_NAME = u"Salut à Toi"
|
||||
APP_NAME_SHORT = u"SàT"
|
||||
APP_NAME_FILE = u"sat"
|
||||
APP_NAME_FULL = u"{name_short} ({name})".format(
|
||||
APP_NAME = "Salut à Toi"
|
||||
APP_NAME_SHORT = "SàT"
|
||||
APP_NAME_FILE = "sat"
|
||||
APP_NAME_FULL = "{name_short} ({name})".format(
|
||||
name_short=APP_NAME_SHORT, name=APP_NAME
|
||||
)
|
||||
APP_VERSION = (
|
||||
sat.__version__
|
||||
) # Please add 'D' at the end of version in sat/VERSION for dev versions
|
||||
APP_RELEASE_NAME = u"La Cecília"
|
||||
APP_URL = u"https://salut-a-toi.org"
|
||||
APP_RELEASE_NAME = "La Cecília"
|
||||
APP_URL = "https://salut-a-toi.org"
|
||||
|
||||
## Runtime ##
|
||||
PLUGIN_EXT = "py"
|
||||
HISTORY_SKIP = u"skip"
|
||||
HISTORY_SKIP = "skip"
|
||||
|
||||
## Main config ##
|
||||
DEFAULT_BRIDGE = "dbus"
|
||||
|
|
@ -122,15 +122,15 @@ class Const(object):
|
|||
)
|
||||
MESS_TYPE_ALL = MESS_TYPE_STANDARD + (MESS_TYPE_INFO, MESS_TYPE_AUTO)
|
||||
|
||||
MESS_EXTRA_INFO = u"info_type"
|
||||
EXTRA_INFO_DECR_ERR = u"DECRYPTION_ERROR"
|
||||
EXTRA_INFO_ENCR_ERR = u"ENCRYPTION_ERROR"
|
||||
MESS_EXTRA_INFO = "info_type"
|
||||
EXTRA_INFO_DECR_ERR = "DECRYPTION_ERROR"
|
||||
EXTRA_INFO_ENCR_ERR = "ENCRYPTION_ERROR"
|
||||
|
||||
# encryption is a key for plugins
|
||||
MESS_KEY_ENCRYPTION = u"ENCRYPTION"
|
||||
MESS_KEY_ENCRYPTION = "ENCRYPTION"
|
||||
# encrypted is a key for frontends
|
||||
MESS_KEY_ENCRYPTED = u"encrypted"
|
||||
MESS_KEY_TRUSTED = u"trusted"
|
||||
MESS_KEY_ENCRYPTED = "encrypted"
|
||||
MESS_KEY_TRUSTED = "trusted"
|
||||
|
||||
## Chat ##
|
||||
CHAT_ONE2ONE = "one2one"
|
||||
|
|
@ -162,110 +162,44 @@ class Const(object):
|
|||
## Directories ##
|
||||
|
||||
# directory for components specific data
|
||||
COMPONENTS_DIR = u"components"
|
||||
CACHE_DIR = u"cache"
|
||||
COMPONENTS_DIR = "components"
|
||||
CACHE_DIR = "cache"
|
||||
# files in file dir are stored for long term
|
||||
# files dir is global, i.e. for all profiles
|
||||
FILES_DIR = u"files"
|
||||
FILES_DIR = "files"
|
||||
# FILES_LINKS_DIR is a directory where files owned by a specific profile
|
||||
# are linked to the global files directory. This way the directory can be
|
||||
# shared per profiles while keeping global directory where identical files
|
||||
# shared between different profiles are not duplicated.
|
||||
FILES_LINKS_DIR = u"files_links"
|
||||
FILES_LINKS_DIR = "files_links"
|
||||
# FILES_TMP_DIR is where profile's partially transfered files are put.
|
||||
# Once transfer is completed, they are moved to FILES_DIR
|
||||
FILES_TMP_DIR = u"files_tmp"
|
||||
|
||||
## Configuration ##
|
||||
if (
|
||||
BaseDirectory
|
||||
): # skipped when xdg module is not available (should not happen in backend)
|
||||
if "org.salutatoi.cagou" in BaseDirectory.__file__:
|
||||
# FIXME: hack to make config read from the right location on Android
|
||||
# TODO: fix it in a more proper way
|
||||
|
||||
# we need to use Android API to get downloads directory
|
||||
import os.path
|
||||
from jnius import autoclass
|
||||
|
||||
Environment = autoclass("android.os.Environment")
|
||||
|
||||
BaseDirectory = None
|
||||
DEFAULT_CONFIG = {
|
||||
"local_dir": "/data/data/org.salutatoi.cagou/app",
|
||||
"media_dir": "/data/data/org.salutatoi.cagou/files/app/media",
|
||||
# FIXME: temporary location for downloads, need to call API properly
|
||||
"downloads_dir": os.path.join(
|
||||
Environment.getExternalStoragePublicDirectory(
|
||||
Environment.DIRECTORY_DOWNLOADS
|
||||
).getAbsolutePath(),
|
||||
APP_NAME_FILE,
|
||||
),
|
||||
"pid_dir": "%(local_dir)s",
|
||||
"log_dir": "%(local_dir)s",
|
||||
}
|
||||
CONFIG_FILES = [
|
||||
"/data/data/org.salutatoi.cagou/files/app/android/"
|
||||
+ APP_NAME_FILE
|
||||
+ ".conf"
|
||||
]
|
||||
else:
|
||||
import os
|
||||
CONFIG_PATHS = (
|
||||
["/etc/", "~/", "~/.", "", "."]
|
||||
+ [
|
||||
"%s/" % path
|
||||
for path in list(BaseDirectory.load_config_paths(APP_NAME_FILE))
|
||||
]
|
||||
)
|
||||
|
||||
# on recent versions of Flatpak, FLATPAK_ID is set at run time
|
||||
# it seems that this is not the case on older versions,
|
||||
# but FLATPAK_SANDBOX_DIR seems set then
|
||||
if os.getenv('FLATPAK_ID') or os.getenv('FLATPAK_SANDBOX_DIR'):
|
||||
# for Flatpak, the conf can't be set in /etc or $HOME, so we have
|
||||
# to add /app
|
||||
CONFIG_PATHS.append('/app/')
|
||||
|
||||
## Configuration ##
|
||||
DEFAULT_CONFIG = {
|
||||
"media_dir": "/usr/share/" + APP_NAME_FILE + "/media",
|
||||
"local_dir": BaseDirectory.save_data_path(APP_NAME_FILE),
|
||||
"downloads_dir": "~/Downloads/" + APP_NAME_FILE,
|
||||
"pid_dir": "%(local_dir)s",
|
||||
"log_dir": "%(local_dir)s",
|
||||
}
|
||||
|
||||
# List of the configuration filenames sorted by ascending priority
|
||||
CONFIG_FILES = [
|
||||
realpath(expanduser(path) + APP_NAME_FILE + ".conf")
|
||||
for path in CONFIG_PATHS
|
||||
]
|
||||
FILES_TMP_DIR = "files_tmp"
|
||||
|
||||
## Templates ##
|
||||
TEMPLATE_TPL_DIR = u"templates"
|
||||
TEMPLATE_THEME_DEFAULT = u"default"
|
||||
TEMPLATE_STATIC_DIR = u"static"
|
||||
KEY_LANG = u"lang" # templates i18n
|
||||
TEMPLATE_TPL_DIR = "templates"
|
||||
TEMPLATE_THEME_DEFAULT = "default"
|
||||
TEMPLATE_STATIC_DIR = "static"
|
||||
KEY_LANG = "lang" # templates i18n
|
||||
|
||||
## Plugins ##
|
||||
|
||||
# PLUGIN_INFO keys
|
||||
# XXX: we use PI instead of PLUG_INFO which would normally be used
|
||||
# to make the header more readable
|
||||
PI_NAME = u"name"
|
||||
PI_IMPORT_NAME = u"import_name"
|
||||
PI_MAIN = u"main"
|
||||
PI_HANDLER = u"handler"
|
||||
PI_NAME = "name"
|
||||
PI_IMPORT_NAME = "import_name"
|
||||
PI_MAIN = "main"
|
||||
PI_HANDLER = "handler"
|
||||
PI_TYPE = (
|
||||
u"type"
|
||||
"type"
|
||||
) # FIXME: should be types, and should handle single unicode type or tuple of types (e.g. "blog" and "import")
|
||||
PI_MODES = u"modes"
|
||||
PI_PROTOCOLS = u"protocols"
|
||||
PI_DEPENDENCIES = u"dependencies"
|
||||
PI_RECOMMENDATIONS = u"recommendations"
|
||||
PI_DESCRIPTION = u"description"
|
||||
PI_USAGE = u"usage"
|
||||
PI_MODES = "modes"
|
||||
PI_PROTOCOLS = "protocols"
|
||||
PI_DEPENDENCIES = "dependencies"
|
||||
PI_RECOMMENDATIONS = "recommendations"
|
||||
PI_DESCRIPTION = "description"
|
||||
PI_USAGE = "usage"
|
||||
|
||||
# Types
|
||||
PLUG_TYPE_XEP = "XEP"
|
||||
|
|
@ -387,8 +321,8 @@ class Const(object):
|
|||
META_TYPE_OVERWRITE = "overwrite"
|
||||
|
||||
## HARD-CODED ACTIONS IDS (generated with uuid.uuid4) ##
|
||||
AUTHENTICATE_PROFILE_ID = u"b03bbfa8-a4ae-4734-a248-06ce6c7cf562"
|
||||
CHANGE_XMPP_PASSWD_ID = u"878b9387-de2b-413b-950f-e424a147bcd0"
|
||||
AUTHENTICATE_PROFILE_ID = "b03bbfa8-a4ae-4734-a248-06ce6c7cf562"
|
||||
CHANGE_XMPP_PASSWD_ID = "878b9387-de2b-413b-950f-e424a147bcd0"
|
||||
|
||||
## Text values ##
|
||||
BOOL_TRUE = "true"
|
||||
|
|
@ -399,32 +333,32 @@ class Const(object):
|
|||
HISTORY_LIMIT_NONE = -2
|
||||
|
||||
## Progress error special values ##
|
||||
PROGRESS_ERROR_DECLINED = u"declined" # session has been declined by peer user
|
||||
PROGRESS_ERROR_DECLINED = "declined" # session has been declined by peer user
|
||||
|
||||
## Files ##
|
||||
FILE_TYPE_DIRECTORY = "directory"
|
||||
FILE_TYPE_FILE = "file"
|
||||
|
||||
## Permissions management ##
|
||||
ACCESS_PERM_READ = u"read"
|
||||
ACCESS_PERM_WRITE = u"write"
|
||||
ACCESS_PERM_READ = "read"
|
||||
ACCESS_PERM_WRITE = "write"
|
||||
ACCESS_PERMS = {ACCESS_PERM_READ, ACCESS_PERM_WRITE}
|
||||
ACCESS_TYPE_PUBLIC = u"public"
|
||||
ACCESS_TYPE_WHITELIST = u"whitelist"
|
||||
ACCESS_TYPE_PUBLIC = "public"
|
||||
ACCESS_TYPE_WHITELIST = "whitelist"
|
||||
ACCESS_TYPES = (ACCESS_TYPE_PUBLIC, ACCESS_TYPE_WHITELIST)
|
||||
|
||||
## Common data keys ##
|
||||
KEY_THUMBNAILS = u"thumbnails"
|
||||
KEY_PROGRESS_ID = u"progress_id"
|
||||
KEY_THUMBNAILS = "thumbnails"
|
||||
KEY_PROGRESS_ID = "progress_id"
|
||||
|
||||
## Common extra keys/values ##
|
||||
KEY_ORDER_BY = u"order_by"
|
||||
KEY_ORDER_BY = "order_by"
|
||||
|
||||
ORDER_BY_CREATION = u'creation'
|
||||
ORDER_BY_MODIFICATION = u'modification'
|
||||
ORDER_BY_CREATION = 'creation'
|
||||
ORDER_BY_MODIFICATION = 'modification'
|
||||
|
||||
# internationalisation
|
||||
DEFAULT_LOCALE = u"en_GB"
|
||||
DEFAULT_LOCALE = "en_GB"
|
||||
|
||||
## Misc ##
|
||||
SAVEFILE_DATABASE = APP_NAME_FILE + ".db"
|
||||
|
|
@ -434,11 +368,11 @@ class Const(object):
|
|||
NO_LIMIT = -1 # used in bridge when a integer value is expected
|
||||
DEFAULT_MAX_AGE = 1209600 # default max age of cached files, in seconds
|
||||
HASH_SHA1_EMPTY = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
|
||||
STANZA_NAMES = (u"iq", u"message", u"presence")
|
||||
STANZA_NAMES = ("iq", "message", "presence")
|
||||
|
||||
# Stream Hooks
|
||||
STREAM_HOOK_SEND = u"send"
|
||||
STREAM_HOOK_RECEIVE = u"receive"
|
||||
STREAM_HOOK_SEND = "send"
|
||||
STREAM_HOOK_RECEIVE = "receive"
|
||||
|
||||
@classmethod
|
||||
def LOG_OPTIONS(cls):
|
||||
|
|
@ -456,7 +390,7 @@ class Const(object):
|
|||
@classmethod
|
||||
def bool(cls, value):
|
||||
"""@return (bool): bool value for associated constant"""
|
||||
assert isinstance(value, basestring)
|
||||
assert isinstance(value, str)
|
||||
return value.lower() in (cls.BOOL_TRUE, "1", "yes", "on")
|
||||
|
||||
@classmethod
|
||||
|
|
@ -464,3 +398,72 @@ class Const(object):
|
|||
"""@return (str): constant associated to bool value"""
|
||||
assert isinstance(value, bool)
|
||||
return cls.BOOL_TRUE if value else cls.BOOL_FALSE
|
||||
|
||||
|
||||
|
||||
## Configuration ##
|
||||
if (
|
||||
BaseDirectory
|
||||
): # skipped when xdg module is not available (should not happen in backend)
|
||||
if "org.salutatoi.cagou" in BaseDirectory.__file__:
|
||||
# FIXME: hack to make config read from the right location on Android
|
||||
# TODO: fix it in a more proper way
|
||||
|
||||
# we need to use Android API to get downloads directory
|
||||
import os.path
|
||||
from jnius import autoclass
|
||||
|
||||
Environment = autoclass("android.os.Environment")
|
||||
|
||||
BaseDirectory = None
|
||||
Const.DEFAULT_CONFIG = {
|
||||
"local_dir": "/data/data/org.salutatoi.cagou/app",
|
||||
"media_dir": "/data/data/org.salutatoi.cagou/files/app/media",
|
||||
# FIXME: temporary location for downloads, need to call API properly
|
||||
"downloads_dir": os.path.join(
|
||||
Environment.getExternalStoragePublicDirectory(
|
||||
Environment.DIRECTORY_DOWNLOADS
|
||||
).getAbsolutePath(),
|
||||
Const.APP_NAME_FILE,
|
||||
),
|
||||
"pid_dir": "%(local_dir)s",
|
||||
"log_dir": "%(local_dir)s",
|
||||
}
|
||||
Const.CONFIG_FILES = [
|
||||
"/data/data/org.salutatoi.cagou/files/app/android/"
|
||||
+ Const.APP_NAME_FILE
|
||||
+ ".conf"
|
||||
]
|
||||
else:
|
||||
import os
|
||||
Const.CONFIG_PATHS = (
|
||||
["/etc/", "~/", "~/.", "", "."]
|
||||
+ [
|
||||
"%s/" % path
|
||||
for path in list(BaseDirectory.load_config_paths(Const.APP_NAME_FILE))
|
||||
]
|
||||
)
|
||||
|
||||
# on recent versions of Flatpak, FLATPAK_ID is set at run time
|
||||
# it seems that this is not the case on older versions,
|
||||
# but FLATPAK_SANDBOX_DIR seems set then
|
||||
if os.getenv('FLATPAK_ID') or os.getenv('FLATPAK_SANDBOX_DIR'):
|
||||
# for Flatpak, the conf can't be set in /etc or $HOME, so we have
|
||||
# to add /app
|
||||
Const.CONFIG_PATHS.append('/app/')
|
||||
|
||||
## Configuration ##
|
||||
Const.DEFAULT_CONFIG = {
|
||||
"media_dir": "/usr/share/" + Const.APP_NAME_FILE + "/media",
|
||||
"local_dir": BaseDirectory.save_data_path(Const.APP_NAME_FILE),
|
||||
"downloads_dir": "~/Downloads/" + Const.APP_NAME_FILE,
|
||||
"pid_dir": "%(local_dir)s",
|
||||
"log_dir": "%(local_dir)s",
|
||||
}
|
||||
|
||||
# List of the configuration filenames sorted by ascending priority
|
||||
Const.CONFIG_FILES = [
|
||||
realpath(expanduser(path) + Const.APP_NAME_FILE + ".conf")
|
||||
for path in Const.CONFIG_PATHS
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SàT Exceptions
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue