changeset 6aa48be81fc6 in /home/hg/repos/gajim
author: tmolitor thilo@eightysoft.de branches: details:http://hg.gajim.org/gajim?cmd=changeset;node=6aa48be81fc6 description: Honor profile given on commandline for plugin dir and history db and more. Also added new property 'additional_data' to message event objects. Changes to this attribute (a dict) are passed on from event to event and are also written to the history db as json string (reading of those values isn't implemented yet).
diffstat:
src/common/check_paths.py | 3 +- src/common/configpaths.py | 47 ++++++++++++------------------- src/common/connection_handlers_events.py | 15 ++++++++++ src/common/logger.py | 10 ++++-- src/common/optparser.py | 17 +++++++++++ src/common/resolver.py | 1 - src/gajim.py | 3 +- src/gui_interface.py | 7 ++-- src/history_manager.py | 1 - src/htmltextview.py | 1 - src/notify.py | 8 ++-- src/session.py | 4 +- test/lib/__init__.py | 1 - test/test_pluginmanager.py | 1 - 14 files changed, 69 insertions(+), 50 deletions(-)
diffs (truncated from 355 to 300 lines):
diff -r f5209cb10665 -r 6aa48be81fc6 src/common/check_paths.py --- a/src/common/check_paths.py Fri Sep 02 13:38:56 2016 -0700 +++ b/src/common/check_paths.py Mon Sep 05 00:01:29 2016 +0200 @@ -72,7 +72,8 @@ kind INTEGER, show INTEGER, message TEXT, - subject TEXT + subject TEXT, + additional_data TEXT DEFAULT '{}' );
CREATE INDEX idx_logs_jid_id_time ON logs (jid_id, time DESC); diff -r f5209cb10665 -r 6aa48be81fc6 src/common/configpaths.py --- a/src/common/configpaths.py Fri Sep 02 13:38:56 2016 -0700 +++ b/src/common/configpaths.py Mon Sep 05 00:01:29 2016 +0200 @@ -134,23 +134,36 @@ for key in self.paths.keys(): yield (key, self[key])
- def init(self, root=None): + def init(self, root=None, profile=''): if root is not None: self.config_root = self.cache_root = self.data_root = root
- d = {'MY_DATA': '', 'LOG_DB': 'logs.db', 'MY_CACERTS': 'cacerts.pem', + d = {'LOG_DB': 'logs.db', 'MY_CACERTS': 'cacerts.pem', 'MY_EMOTS': 'emoticons', 'MY_ICONSETS': 'iconsets', 'MY_MOOD_ICONSETS': 'moods', 'MY_ACTIVITY_ICONSETS': 'activities', 'PLUGINS_USER': 'plugins', - 'RNG_SEED': 'rng_seed'} + 'RNG_SEED': 'rng_seed', + 'SECRETS_FILE': 'secrets', 'MY_PEER_CERTS': 'certs'} for name in d: + if len(profile) > 0: + d[name] += u'.' + profile self.add(name, TYPE_DATA, windowsify(d[name])) + self.add('MY_DATA', TYPE_DATA, '')
- d = {'MY_CACHE': '', 'CACHE_DB': 'cache.db', 'VCARD': 'vcards', - 'AVATAR': 'avatars'} + d = {'CACHE_DB': 'cache.db', 'VCARD': 'vcards', + 'AVATAR': 'avatars', + 'PID_FILE': 'gajim.pid'} for name in d: + if len(profile) > 0: + d[name] += u'.' + profile self.add(name, TYPE_CACHE, windowsify(d[name])) + self.add('MY_CACHE', TYPE_CACHE, '')
+ d = {'CONFIG_FILE': 'config', 'PLUGINS_CONFIG_DIR': 'pluginsconfig', 'MY_CERT': 'localcerts'} + for name in d: + if len(profile) > 0: + d[name] += u'.' + profile + self.add(name, TYPE_CONFIG, windowsify(d[name])) self.add('MY_CONFIG', TYPE_CONFIG, '')
basedir = fse(os.environ.get('GAJIM_BASEDIR', defs.basedir)) @@ -172,28 +185,4 @@ except (ImportError, AttributeError): pass
- def init_profile(self, profile=''): - conffile = windowsify('config') - pidfile = windowsify('gajim') - secretsfile = windowsify('secrets') - pluginsconfdir = windowsify('pluginsconfig') - certsdir = windowsify(u'certs') - localcertsdir = windowsify(u'localcerts') - - if len(profile) > 0: - conffile += '.' + profile - pidfile += '.' + profile - secretsfile += '.' + profile - pluginsconfdir += '.' + profile - certsdir += u'.' + profile - localcertsdir += u'.' + profile - - pidfile += '.pid' - self.add('CONFIG_FILE', TYPE_CONFIG, conffile) - self.add('PID_FILE', TYPE_CACHE, pidfile) - self.add('SECRETS_FILE', TYPE_DATA, secretsfile) - self.add('PLUGINS_CONFIG_DIR', TYPE_CONFIG, pluginsconfdir) - self.add('MY_PEER_CERTS', TYPE_DATA, certsdir) - self.add('MY_CERT', TYPE_CONFIG, localcertsdir) - gajimpaths = ConfigPaths() diff -r f5209cb10665 -r 6aa48be81fc6 src/common/connection_handlers_events.py --- a/src/common/connection_handlers_events.py Fri Sep 02 13:38:56 2016 -0700 +++ b/src/common/connection_handlers_events.py Mon Sep 05 00:01:29 2016 +0200 @@ -1028,6 +1028,8 @@ def generate(self): if not self.stanza: return + if not hasattr(self, 'additional_data'): + self.additional_data = {} account = self.conn.name self.msg_ = self.stanza.getTag('message') # use timestamp of archived message, if available and archive timestamp otherwise @@ -1066,6 +1068,8 @@ def generate(self): self.nick = None msg_ = self.msg_obj.msg_ + if not hasattr(self, 'additional_data'): + self.additional_data = self.msg_obj.additional_data self.with_ = self.msg_obj.with_ self.direction = self.msg_obj.direction self.tim = self.msg_obj.tim @@ -1106,6 +1110,8 @@ self.get_id() self.forwarded = False self.sent = False + if not hasattr(self, 'additional_data'): + self.additional_data = {}
account = self.conn.name
@@ -1384,6 +1390,8 @@
def generate(self): self.stanza = self.msg_obj.stanza + if not hasattr(self, 'additional_data'): + self.additional_data = self.msg_obj.additional_data self.id_ = self.msg_obj.id_ self.jid = self.msg_obj.jid self.fjid = self.msg_obj.fjid @@ -1491,6 +1499,8 @@
def generate(self): self.stanza = self.msg_obj.stanza + if not hasattr(self, 'additional_data'): + self.additional_data = self.msg_obj.additional_data self.fjid = self.msg_obj.fjid self.msgtxt = self.msg_obj.msgtxt self.jid = self.msg_obj.jid @@ -1812,6 +1822,11 @@ class StanzaReceivedEvent(nec.NetworkIncomingEvent): name = 'stanza-received' base_network_events = [] + + def generate(self): + if not hasattr(self, 'additional_data'): + self.additional_data = {} + return True
class StanzaSentEvent(nec.NetworkIncomingEvent): name = 'stanza-sent' diff -r f5209cb10665 -r 6aa48be81fc6 src/common/logger.py --- a/src/common/logger.py Fri Sep 02 13:38:56 2016 -0700 +++ b/src/common/logger.py Mon Sep 05 00:01:29 2016 +0200 @@ -32,6 +32,7 @@ import sys import time import datetime +import json from gzip import GzipFile from io import BytesIO from gi.repository import GLib @@ -141,6 +142,8 @@ # if locked, wait up to 20 sec to unlock # before raise (hopefully should be enough)
+ print("*****") + print("%s/%s" % (LOG_DB_FOLDER, LOG_DB_FILE)) self.con = sqlite.connect(LOG_DB_FILE, timeout=20.0, isolation_level='IMMEDIATE') os.chdir(back) @@ -412,7 +415,7 @@
def commit_to_db(self, values, write_unread=False): sql = '''INSERT INTO logs (jid_id, contact_name, time, kind, show, - message, subject) VALUES (?, ?, ?, ?, ?, ?, ?)''' + message, subject, additional_data) VALUES (?, ?, ?, ?, ?, ?, ?, ?)''' try: self.cur.execute(sql, values) except sqlite.OperationalError as e: @@ -495,7 +498,7 @@ all_messages.append(results[0] + (shown,)) return all_messages
- def write(self, kind, jid, message=None, show=None, tim=None, subject=None): + def write(self, kind, jid, message=None, show=None, tim=None, subject=None, additional_data={}): """ Write a row (status, gcstatus, message etc) to logs database
@@ -517,6 +520,7 @@ # then it holds status message message_col = message subject_col = subject + additional_data_col = json.dumps(additional_data) if tim: time_col = int(float(time.mktime(tim))) else: @@ -576,7 +580,7 @@ return
values = (jid_id, contact_name_col, time_col, kind_col, show_col, - message_col, subject_col) + message_col, subject_col, additional_data_col) return self.commit_to_db(values, write_unread)
def get_last_conversation_lines(self, jid, restore_how_many_rows, diff -r f5209cb10665 -r 6aa48be81fc6 src/common/optparser.py --- a/src/common/optparser.py Fri Sep 02 13:38:56 2016 -0700 +++ b/src/common/optparser.py Mon Sep 05 00:01:29 2016 +0200 @@ -945,4 +945,21 @@ gajim.config.set('video_input_device', 'autovideosrc') if self.old_values['video_input_device'] == 'videotestsrc is-live=true ! video/x-raw-yuv,framerate=10/1': gajim.config.set('video_input_device', 'videotestsrc is-live=true ! video/x-raw,framerate=10/1') + + back = os.getcwd() + os.chdir(logger.LOG_DB_FOLDER) + con = sqlite.connect(logger.LOG_DB_FILE) + os.chdir(back) + cur = con.cursor() + try: + cur.executescript( + ''' + ALTER TABLE logs ADD COLUMN 'additional_data' TEXT DEFAULT '{}'; + ''' + ) + con.commit() + except sqlite.OperationalError: + pass + con.close() + gajim.config.set('version', '0.16.10.1') diff -r f5209cb10665 -r 6aa48be81fc6 src/common/resolver.py --- a/src/common/resolver.py Fri Sep 02 13:38:56 2016 -0700 +++ b/src/common/resolver.py Mon Sep 05 00:01:29 2016 +0200 @@ -28,7 +28,6 @@ from common import i18n import common.configpaths common.configpaths.gajimpaths.init(None) - common.configpaths.gajimpaths.init_profile()
from common import helpers from nbxmpp.idlequeue import IdleCommand diff -r f5209cb10665 -r 6aa48be81fc6 src/gajim.py --- a/src/gajim.py Fri Sep 02 13:38:56 2016 -0700 +++ b/src/gajim.py Mon Sep 05 00:01:29 2016 +0200 @@ -178,9 +178,8 @@ del parseOpts
import common.configpaths -common.configpaths.gajimpaths.init(config_path) +common.configpaths.gajimpaths.init(config_path, profile) del config_path -common.configpaths.gajimpaths.init_profile(profile) del profile
if os.name == 'nt': diff -r f5209cb10665 -r 6aa48be81fc6 src/gui_interface.py --- a/src/gui_interface.py Fri Sep 02 13:38:56 2016 -0700 +++ b/src/gui_interface.py Mon Sep 05 00:01:29 2016 +0200 @@ -2528,13 +2528,12 @@ want_type=True) if pixbuf is None: return - extension = '.' + typ if typ not in ('jpeg', 'png'): - gajim.log.debug('gtkpixbuf cannot save other than jpeg and '\ - 'png formats. saving %s'avatar as png file (originaly %s)'\ + gajim.log.info('gtkpixbuf cannot save other than jpeg and '\ + 'png formats. saving '%s' avatar as png file (originaly: %s)'\ % (jid, typ)) typ = 'png' - extension = '.png' + extension = '.' + typ path_to_original_file = path_to_file + extension try: pixbuf.savev(path_to_original_file, typ, [], []) diff -r f5209cb10665 -r 6aa48be81fc6 src/history_manager.py --- a/src/history_manager.py Fri Sep 02 13:38:56 2016 -0700 +++ b/src/history_manager.py Mon Sep 05 00:01:29 2016 +0200 @@ -91,7 +91,6 @@ import common.configpaths common.configpaths.gajimpaths.init(config_path) del config_path -common.configpaths.gajimpaths.init_profile() from common import exceptions from common import gajim import gtkgui_helpers diff -r f5209cb10665 -r 6aa48be81fc6 src/htmltextview.py --- a/src/htmltextview.py Fri Sep 02 13:38:56 2016 -0700 +++ b/src/htmltextview.py Mon Sep 05 00:01:29 2016 +0200 @@ -50,7 +50,6 @@ if __name__ == '__main__': from common import i18n import common.configpaths - common.configpaths.gajimpaths.init_profile() common.configpaths.gajimpaths.init(None) import gtkgui_helpers from common import gajim diff -r f5209cb10665 -r 6aa48be81fc6 src/notify.py --- a/src/notify.py Fri Sep 02 13:38:56 2016 -0700 +++ b/src/notify.py Mon Sep 05 00:01:29 2016 +0200 @@ -121,10 +121,10 @@
notification.set_category(event_type)