No need to have one sleepy instance per connection object

This commit is contained in:
Yann Leboulanger 2017-08-22 21:53:32 +02:00
parent 7de4aa1a06
commit ce719a8317
4 changed files with 15 additions and 36 deletions

View File

@ -244,6 +244,14 @@ try:
except ImportError: except ImportError:
HAVE_PYCURL = False HAVE_PYCURL = False
try:
from gajim.common import sleepy
if sleepy.SUPPORTED:
HAVE_IDLE = True
except Exception:
log.debug(_('Unable to load idle module'))
HAVE_IDLE = False
gajim_identity = {'type': 'pc', 'category': 'client', 'name': 'Gajim'} gajim_identity = {'type': 'pc', 'category': 'client', 'name': 'Gajim'}
gajim_common_features = [nbxmpp.NS_BYTESTREAM, nbxmpp.NS_SI, nbxmpp.NS_FILE, gajim_common_features = [nbxmpp.NS_BYTESTREAM, nbxmpp.NS_SI, nbxmpp.NS_FILE,

View File

@ -630,9 +630,8 @@ class CommonConnection:
self.connected = app.SHOW_LIST.index(show) self.connected = app.SHOW_LIST.index(show)
idle_time = None idle_time = None
if auto: if auto:
global HAS_IDLE if app.HAVE_IDLE and app.config.get('autoaway'):
if HAS_IDLE and app.config.get('autoaway'): idle_sec = int(app.interface.sleeper.getIdleSec())
idle_sec = int(self.sleeper.getIdleSec())
idle_time = time.strftime('%Y-%m-%dT%H:%M:%SZ', idle_time = time.strftime('%Y-%m-%dT%H:%M:%SZ',
time.gmtime(time.time() - idle_sec)) time.gmtime(time.time() - idle_sec))
app.nec.push_incoming_event(BeforeChangeShowEvent(None, app.nec.push_incoming_event(BeforeChangeShowEvent(None,
@ -2705,9 +2704,8 @@ class Connection(CommonConnection, ConnectionHandlers):
p = self.add_sha(p, ptype != 'unavailable') p = self.add_sha(p, ptype != 'unavailable')
self.add_lang(p) self.add_lang(p)
if auto: if auto:
global HAS_IDLE if app.HAVE_IDLE and app.config.get('autoaway'):
if HAS_IDLE and app.config.get('autoaway'): idle_sec = int(app.interface.sleeper.getIdleSec())
idle_sec = int(self.sleeper.getIdleSec())
idle_time = time.strftime('%Y-%m-%dT%H:%M:%SZ', idle_time = time.strftime('%Y-%m-%dT%H:%M:%SZ',
time.gmtime(time.time() - idle_sec)) time.gmtime(time.time() - idle_sec))
idle = p.setTag('idle', namespace=nbxmpp.NS_IDLE) idle = p.setTag('idle', namespace=nbxmpp.NS_IDLE)

View File

@ -47,6 +47,7 @@ from gajim.common import app
from gajim.common import exceptions from gajim.common import exceptions
from gajim.common import dataforms from gajim.common import dataforms
from gajim.common import jingle_xtls from gajim.common import jingle_xtls
from gajim.common import sleepy
from gajim.common.commands import ConnectionCommands from gajim.common.commands import ConnectionCommands
from gajim.common.pubsub import ConnectionPubSub from gajim.common.pubsub import ConnectionPubSub
from gajim.common.protocol.caps import ConnectionCaps from gajim.common.protocol.caps import ConnectionCaps
@ -74,13 +75,6 @@ DELIMITER_ARRIVED = 'delimiter_arrived'
PRIVACY_ARRIVED = 'privacy_arrived' PRIVACY_ARRIVED = 'privacy_arrived'
BLOCKING_ARRIVED = 'blocking_arrived' BLOCKING_ARRIVED = 'blocking_arrived'
PEP_CONFIG = 'pep_config' PEP_CONFIG = 'pep_config'
HAS_IDLE = True
try:
# import idle
from gajim.common import sleepy
except Exception:
log.debug(_('Unable to load idle module'))
HAS_IDLE = False
class ConnectionDisco: class ConnectionDisco:
@ -1345,7 +1339,6 @@ ConnectionVcard, ConnectionSocks5Bytestream, ConnectionDisco,
ConnectionCommands, ConnectionPubSub, ConnectionPEP, ConnectionCaps, ConnectionCommands, ConnectionPubSub, ConnectionPEP, ConnectionCaps,
ConnectionHandlersBase, ConnectionJingle, ConnectionIBBytestream): ConnectionHandlersBase, ConnectionJingle, ConnectionIBBytestream):
def __init__(self): def __init__(self):
global HAS_IDLE
ConnectionArchive313.__init__(self) ConnectionArchive313.__init__(self)
ConnectionVcard.__init__(self) ConnectionVcard.__init__(self)
ConnectionSocks5Bytestream.__init__(self) ConnectionSocks5Bytestream.__init__(self)
@ -1382,13 +1375,6 @@ ConnectionHandlersBase, ConnectionJingle, ConnectionIBBytestream):
self.privacy_default_list = None self.privacy_default_list = None
try:
self.sleeper = sleepy.Sleepy()
HAS_IDLE = True
except Exception:
log.warning('Error while calling Sleepy()', exc_info=True)
HAS_IDLE = False
self.gmail_last_tid = None self.gmail_last_tid = None
self.gmail_last_time = None self.gmail_last_time = None
@ -1659,14 +1645,13 @@ ConnectionHandlersBase, ConnectionJingle, ConnectionIBBytestream):
raise nbxmpp.NodeProcessed raise nbxmpp.NodeProcessed
def _nec_last_request_received(self, obj): def _nec_last_request_received(self, obj):
global HAS_IDLE
if obj.conn.name != self.name: if obj.conn.name != self.name:
return return
if HAS_IDLE and app.config.get_per('accounts', self.name, if app.HAVE_IDLE and app.config.get_per('accounts', self.name,
'send_idle_time'): 'send_idle_time'):
iq_obj = obj.stanza.buildReply('result') iq_obj = obj.stanza.buildReply('result')
qp = iq_obj.setQuery() qp = iq_obj.setQuery()
qp.attrs['seconds'] = int(self.sleeper.getIdleSec()) qp.attrs['seconds'] = int(app.interface.sleeper.getIdleSec())
else: else:
iq_obj = obj.stanza.buildReply('error') iq_obj = obj.stanza.buildReply('error')
err = nbxmpp.ErrorNode(name=nbxmpp.NS_STANZAS + \ err = nbxmpp.ErrorNode(name=nbxmpp.NS_STANZAS + \

View File

@ -39,12 +39,6 @@ STATUS_LIST = ['offline', 'connecting', 'online', 'chat', 'away', 'xa', 'dnd',
VCARD_PUBLISHED = 'vcard_published' VCARD_PUBLISHED = 'vcard_published'
VCARD_ARRIVED = 'vcard_arrived' VCARD_ARRIVED = 'vcard_arrived'
AGENT_REMOVED = 'agent_removed' AGENT_REMOVED = 'agent_removed'
HAS_IDLE = True
try:
import idle
except Exception:
log.debug(_('Unable to load idle module'))
HAS_IDLE = False
from gajim.common import connection_handlers from gajim.common import connection_handlers
@ -73,12 +67,6 @@ connection_handlers.ConnectionJingle):
connection_handlers.ConnectionJingle.__init__(self) connection_handlers.ConnectionJingle.__init__(self)
connection_handlers.ConnectionHandlersBase.__init__(self) connection_handlers.ConnectionHandlersBase.__init__(self)
try:
idle.init()
except Exception:
global HAS_IDLE
HAS_IDLE = False
def _messageCB(self, ip, con, msg): def _messageCB(self, ip, con, msg):
""" """
Called when we receive a message Called when we receive a message