Fix #2126 (per-server configuration sections)
(also move replace_key_with_bound() to core.py, to prevent having common.py depending of config.py)
This commit is contained in:
parent
4be111b63e
commit
1e9e2112f7
4 changed files with 34 additions and 10 deletions
|
@ -483,6 +483,13 @@ after a JID. These option will apply only for the given JID. For example
|
||||||
if an option appears in a section named [user@example.com], it will
|
if an option appears in a section named [user@example.com], it will
|
||||||
apply only for the conversations with user@example.com.
|
apply only for the conversations with user@example.com.
|
||||||
|
|
||||||
|
If an option appears in a section named [@example.com], it will apply
|
||||||
|
for all the conversations with people @example.com, except when the option
|
||||||
|
is already defined in a [user@example.com] section.
|
||||||
|
|
||||||
|
The priority of settings is thus like this:
|
||||||
|
user@example.com > @example.com > Poezio (more specific to less specific)
|
||||||
|
|
||||||
Note that some of these options can also appear in the global section,
|
Note that some of these options can also appear in the global section,
|
||||||
they will be used as a fallback value when no JID-specific option is
|
they will be used as a fallback value when no JID-specific option is
|
||||||
found.
|
found.
|
||||||
|
@ -495,6 +502,8 @@ found.
|
||||||
foo = false
|
foo = false
|
||||||
[user@example.com]
|
[user@example.com]
|
||||||
foo = true
|
foo = true
|
||||||
|
[@example.com]
|
||||||
|
bar = false
|
||||||
-------------
|
-------------
|
||||||
============================================
|
============================================
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,6 @@ import time
|
||||||
import string
|
import string
|
||||||
import shlex
|
import shlex
|
||||||
|
|
||||||
from config import config
|
|
||||||
|
|
||||||
ROOM_STATE_NONE = 11
|
ROOM_STATE_NONE = 11
|
||||||
ROOM_STATE_CURRENT = 10
|
ROOM_STATE_CURRENT = 10
|
||||||
ROOM_STATE_PRIVATE = 15
|
ROOM_STATE_PRIVATE = 15
|
||||||
|
@ -188,12 +186,6 @@ def shell_split(st):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return st.split(" ")
|
return st.split(" ")
|
||||||
|
|
||||||
def replace_key_with_bound(key):
|
|
||||||
bind = config.get(key, key, 'bindings')
|
|
||||||
if not bind:
|
|
||||||
bind = key
|
|
||||||
return bind
|
|
||||||
|
|
||||||
def parse_str_to_secs(duration=''):
|
def parse_str_to_secs(duration=''):
|
||||||
"""
|
"""
|
||||||
Parse a string of with a number of d, h, m, s
|
Parse a string of with a number of d, h, m, s
|
||||||
|
|
|
@ -16,6 +16,7 @@ from configparser import RawConfigParser, NoOptionError, NoSectionError
|
||||||
from os import environ, makedirs, path
|
from os import environ, makedirs, path
|
||||||
from shutil import copy2
|
from shutil import copy2
|
||||||
from args import parse_args
|
from args import parse_args
|
||||||
|
from common import safeJID
|
||||||
|
|
||||||
|
|
||||||
class Config(RawConfigParser):
|
class Config(RawConfigParser):
|
||||||
|
@ -62,7 +63,7 @@ class Config(RawConfigParser):
|
||||||
"""
|
"""
|
||||||
return self.get(option, default, section).lower()
|
return self.get(option, default, section).lower()
|
||||||
|
|
||||||
def get_by_tabname(self, option, default, tabname, fallback=True):
|
def get_by_tabname(self, option, default, tabname, fallback=True, fallback_server=True):
|
||||||
"""
|
"""
|
||||||
Try to get the value for the option. First we look in
|
Try to get the value for the option. First we look in
|
||||||
a section named `tabname`, if the option is not present
|
a section named `tabname`, if the option is not present
|
||||||
|
@ -73,11 +74,27 @@ class Config(RawConfigParser):
|
||||||
if option in self.options(tabname):
|
if option in self.options(tabname):
|
||||||
# We go the tab-specific option
|
# We go the tab-specific option
|
||||||
return self.get(option, default, tabname)
|
return self.get(option, default, tabname)
|
||||||
|
if fallback_server:
|
||||||
|
return self.get_by_servname(tabname, option, default, fallback)
|
||||||
if fallback:
|
if fallback:
|
||||||
# We fallback to the global option
|
# We fallback to the global option
|
||||||
return self.get(option, default)
|
return self.get(option, default)
|
||||||
return default
|
return default
|
||||||
|
|
||||||
|
def get_by_servname(self, jid, option, default, fallback=True):
|
||||||
|
"""
|
||||||
|
Try to get the value of an option for a server
|
||||||
|
"""
|
||||||
|
server = safeJID(jid).server
|
||||||
|
if server:
|
||||||
|
server = '@' + server
|
||||||
|
if server in self.sections() and option in self.options(server):
|
||||||
|
return self.get(option, default, server)
|
||||||
|
if fallback:
|
||||||
|
return self.get(option, default)
|
||||||
|
return default
|
||||||
|
|
||||||
|
|
||||||
def __get(self, option, section=DEFSECTION):
|
def __get(self, option, section=DEFSECTION):
|
||||||
"""
|
"""
|
||||||
facility for RawConfigParser.get
|
facility for RawConfigParser.get
|
||||||
|
|
|
@ -381,7 +381,7 @@ class Core(object):
|
||||||
res.append(current)
|
res.append(current)
|
||||||
return res
|
return res
|
||||||
while self.running:
|
while self.running:
|
||||||
big_char_list = [common.replace_key_with_bound(key)\
|
big_char_list = [replace_key_with_bound(key)\
|
||||||
for key in self.read_keyboard()]
|
for key in self.read_keyboard()]
|
||||||
# whether to refresh after ALL keys have been handled
|
# whether to refresh after ALL keys have been handled
|
||||||
for char_list in separate_chars_from_bindings(big_char_list):
|
for char_list in separate_chars_from_bindings(big_char_list):
|
||||||
|
@ -3175,4 +3175,10 @@ class KeyDict(dict):
|
||||||
return lambda: dict.get(self, '_exc_')(k[5:])
|
return lambda: dict.get(self, '_exc_')(k[5:])
|
||||||
return dict.get(self, k, d)
|
return dict.get(self, k, d)
|
||||||
|
|
||||||
|
def replace_key_with_bound(key):
|
||||||
|
bind = config.get(key, key, 'bindings')
|
||||||
|
if not bind:
|
||||||
|
bind = key
|
||||||
|
return bind
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue