summaryrefslogtreecommitdiff
path: root/src/config.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.py')
-rw-r--r--src/config.py68
1 files changed, 52 insertions, 16 deletions
diff --git a/src/config.py b/src/config.py
index 1f0771ca..3ca53dd2 100644
--- a/src/config.py
+++ b/src/config.py
@@ -15,7 +15,7 @@ DEFSECTION = "Poezio"
import logging.config
import os
import sys
-from gettext import gettext as _
+import pkg_resources
from configparser import RawConfigParser, NoOptionError, NoSectionError
from os import environ, makedirs, path, remove
@@ -28,12 +28,13 @@ DEFAULT_CONFIG = {
'add_space_after_completion': True,
'after_completion': ',',
'alternative_nickname': '',
- 'auto_reconnect': False,
+ 'auto_reconnect': True,
'autorejoin_delay': '5',
'autorejoin': False,
'beep_on': 'highlight private invite',
'ca_cert_path': '',
'certificate': '',
+ 'certfile': '',
'ciphers': 'HIGH+kEDH:HIGH+kEECDH:HIGH:!PSK:!SRP:!3DES:!aNULL',
'connection_check_interval': 60,
'connection_timeout_delay': 10,
@@ -41,6 +42,8 @@ DEFAULT_CONFIG = {
'custom_host': '',
'custom_port': '',
'default_nick': '',
+ 'deterministic_nick_colors': True,
+ 'nick_color_aliases': True,
'display_activity_notifications': False,
'display_gaming_notifications': False,
'display_mood_notifications': False,
@@ -58,6 +61,8 @@ DEFAULT_CONFIG = {
'extract_inline_images': True,
'filter_info_messages': '',
'force_encryption': True,
+ 'force_remote_bookmarks': False,
+ 'go_to_previous_tab_on_alt_number': False,
'group_corrections': True,
'hide_exit_join': -1,
'hide_status_change': 120,
@@ -67,11 +72,11 @@ DEFAULT_CONFIG = {
'ignore_private': False,
'information_buffer_popup_on': 'error roster warning help info',
'jid': '',
+ 'keyfile': '',
'lang': 'en',
'lazy_resize': True,
'load_log': 10,
'log_dir': '',
- 'logfile': 'logs',
'log_errors': True,
'max_lines_in_memory': 2048,
'max_messages_in_memory': 2048,
@@ -131,6 +136,8 @@ DEFAULT_CONFIG = {
'var': {
'folded_roster_groups': '',
'info_win_height': 2
+ },
+ 'muc_colors': {
}
}
@@ -152,9 +159,11 @@ class Config(RawConfigParser):
except TypeError: # python < 3.2 sucks
RawConfigParser.read(self, self.file_name)
# Check config integrity and fix it if it’s wrong
- for section in ('bindings', 'var'):
- if not self.has_section(section):
- self.add_section(section)
+ # only when the object is the main config
+ if self.__class__ is Config:
+ for section in ('bindings', 'var'):
+ if not self.has_section(section):
+ self.add_section(section)
def get(self, option, default=None, section=DEFSECTION):
"""
@@ -400,9 +409,9 @@ class Config(RawConfigParser):
elif current.lower() == "true":
value = "false"
else:
- return (_('Could not toggle option: %s.'
- ' Current value is %s.') %
- (option, current or _("empty")),
+ return ('Could not toggle option: %s.'
+ ' Current value is %s.' %
+ (option, current or "empty"),
'Warning')
if self.has_section(section):
RawConfigParser.set(self, section, option, value)
@@ -410,7 +419,7 @@ class Config(RawConfigParser):
self.add_section(section)
RawConfigParser.set(self, section, option, value)
if not self.write_in_file(section, option, value):
- return (_('Unable to write in the config file'), 'Error')
+ return ('Unable to write in the config file', 'Error')
return ("%s=%s" % (option, value), 'Info')
def remove_and_save(self, option, section=DEFSECTION):
@@ -420,8 +429,8 @@ class Config(RawConfigParser):
if self.has_section(section):
RawConfigParser.remove_option(self, section, option)
if not self.remove_in_file(section, option):
- return (_('Unable to save the config file'), 'Error')
- return (_('Option %s deleted') % option, 'Info')
+ return ('Unable to save the config file', 'Error')
+ return ('Option %s deleted' % option, 'Info')
def silent_set(self, option, value, section=DEFSECTION):
"""
@@ -511,6 +520,34 @@ def check_create_cache_dir():
except OSError:
pass
+def check_config():
+ """
+ Check the config file and print results
+ """
+ result = {'missing': [], 'changed': []}
+ for option in DEFAULT_CONFIG['Poezio']:
+ value = config.get(option)
+ if value != DEFAULT_CONFIG['Poezio'][option]:
+ result['changed'].append((option, value, DEFAULT_CONFIG['Poezio'][option]))
+ else:
+ value = config.get(option, default='')
+ upper = value.upper()
+ default = str(DEFAULT_CONFIG['Poezio'][option]).upper()
+ if upper != default:
+ result['missing'].append(option)
+
+ result['changed'].sort(key=lambda x: x[0])
+ result['missing'].sort()
+ if result['changed']:
+ print('\033[1mOptions changed from the default configuration:\033[0m\n')
+ for option, new_value, default in result['changed']:
+ print(' \033[1m%s\033[0m = \033[33m%s\033[0m (default: \033[32m%s\033[0m)' % (option, new_value, default))
+
+ if result['missing']:
+ print('\n\033[1mMissing options:\033[0m (the defaults are used)\n')
+ for option in result['missing']:
+ print(' \033[31m%s\033[0m' % option)
+
def run_cmdline_args(CONFIG_PATH):
"Parse the command line arguments"
global options
@@ -518,9 +555,8 @@ def run_cmdline_args(CONFIG_PATH):
# Copy a default file if none exists
if not path.isfile(options.filename):
- default = path.join(path.dirname(__file__),
- '../data/default_config.cfg')
- other = path.join(path.dirname(__file__), 'default_config.cfg')
+ default = path.join(path.dirname(__file__), '../data/default_config.cfg')
+ other = pkg_resources.resource_filename('poezio', 'default_config.cfg')
if path.isfile(default):
copy2(default, options.filename)
elif path.isfile(other):
@@ -552,7 +588,7 @@ def check_create_log_dir():
home = environ.get('HOME')
data_dir = path.join(home, '.local', 'share')
- LOG_DIR = path.join(data_dir, 'poezio')
+ LOG_DIR = path.join(data_dir, 'poezio', 'logs')
LOG_DIR = path.expanduser(LOG_DIR)