HistoryManager: Init configpaths only in standalone mode

This commit is contained in:
Philipp Hörist 2018-04-21 13:48:08 +02:00
parent 4a26ecb12c
commit 0739eb9dec
2 changed files with 34 additions and 20 deletions

View File

@ -7,6 +7,7 @@
## Copyright (C) 2006-2014 Yann Leboulanger <asterix AT lagaule.org> ## Copyright (C) 2006-2014 Yann Leboulanger <asterix AT lagaule.org>
## Copyright (C) 2007 Stephan Erb <steve-e AT h3c.de> ## Copyright (C) 2007 Stephan Erb <steve-e AT h3c.de>
## Copyright (C) 2008 Jonathan Schleifer <js-gajim AT webkeks.org> ## Copyright (C) 2008 Jonathan Schleifer <js-gajim AT webkeks.org>
## Copyright (C) 2018 Philipp Hörist <philipp AT hoerist.com>
## ##
## This file is part of Gajim. ## This file is part of Gajim.
## ##
@ -30,18 +31,37 @@
import os import os
import sys import sys
import time
import getopt
import sqlite3
from enum import IntEnum, unique
import gi import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
gi.require_version('GLib', '2.0')
gi.require_version('Gdk', '3.0')
gi.require_version('Gio', '2.0')
from gi.repository import Gtk from gi.repository import Gtk
from gi.repository import Gdk from gi.repository import Gdk
from gi.repository import GLib from gi.repository import GLib
import time from gi.repository import Gio
import getopt
from gajim.common import i18n from gajim.common import i18n
def parseOpts():
config_path = None def is_standalone():
# Determine if we are in standalone mode
if Gio.Application.get_default() is None:
return True
if __name__ == '__main__':
return True
return False
if is_standalone():
# Standalone Mode
# Must be done before importing app
from gajim.common import configpaths
try: try:
shortargs = 'hvsc:l:p:' shortargs = 'hvsc:l:p:'
@ -61,23 +81,16 @@ def parseOpts():
'\n -c, --config-path ' + _('Choose folder for logfile') + '\n') '\n -c, --config-path ' + _('Choose folder for logfile') + '\n')
sys.exit() sys.exit()
elif o in ('-c', '--config-path'): elif o in ('-c', '--config-path'):
config_path = a configpaths.set_config_root(a)
return config_path
config_path = parseOpts()
del parseOpts
from gajim.common import configpaths
configpaths.set_config_root(config_path)
configpaths.init() configpaths.init()
del config_path
from gajim.common import app from gajim.common import app
from gajim import gtkgui_helpers from gajim import gtkgui_helpers
from gajim.common.logger import LOG_DB_PATH, JIDConstant, KindConstant from gajim.common.logger import LOG_DB_PATH, JIDConstant, KindConstant
from gajim.common import helpers from gajim.common import helpers
from gajim import dialogs from gajim import dialogs
from enum import IntEnum, unique
@unique @unique
class Column(IntEnum): class Column(IntEnum):
@ -87,9 +100,6 @@ class Column(IntEnum):
NICKNAME = 5 NICKNAME = 5
import sqlite3 as sqlite
class HistoryManager: class HistoryManager:
def __init__(self): def __init__(self):
pixs = [] pixs = []
@ -120,7 +130,7 @@ class HistoryManager:
self.jids_already_in = [] # holds jids that we already have in DB self.jids_already_in = [] # holds jids that we already have in DB
self.AT_LEAST_ONE_DELETION_DONE = False self.AT_LEAST_ONE_DELETION_DONE = False
self.con = sqlite.connect(LOG_DB_PATH, timeout=20.0, self.con = sqlite3.connect(LOG_DB_PATH, timeout=20.0,
isolation_level='IMMEDIATE') isolation_level='IMMEDIATE')
self.cur = self.con.cursor() self.cur = self.con.cursor()
@ -226,18 +236,18 @@ class HistoryManager:
def on_history_manager_window_delete_event(self, widget, event): def on_history_manager_window_delete_event(self, widget, event):
if not self.AT_LEAST_ONE_DELETION_DONE: if not self.AT_LEAST_ONE_DELETION_DONE:
if __name__ == '__main__': if is_standalone():
Gtk.main_quit() Gtk.main_quit()
return return
def on_yes(clicked): def on_yes(clicked):
self.cur.execute('VACUUM') self.cur.execute('VACUUM')
self.con.commit() self.con.commit()
if __name__ == '__main__': if is_standalone():
Gtk.main_quit() Gtk.main_quit()
def on_no(): def on_no():
if __name__ == '__main__': if is_standalone():
Gtk.main_quit() Gtk.main_quit()
dialog = dialogs.YesNoDialog( dialog = dialogs.YesNoDialog(

View File

@ -0,0 +1,4 @@
#!/usr/bin/env python3
from gajim import history_manager
history_manager.main()