Move the default config setting to the entry points
Have this in the effective main() methods (or close to that anyway) instead of hidden away in the config implementations. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
be9b3c02cc
commit
9ef4002b39
|
@ -16,6 +16,8 @@ import enum
|
|||
import logging
|
||||
import sys
|
||||
import time
|
||||
import xdg.BaseDirectory
|
||||
from pathlib import Path
|
||||
try:
|
||||
from gi.repository import GObject, GLib
|
||||
except Exception as e:
|
||||
|
@ -26,12 +28,13 @@ except Exception as e:
|
|||
print(f'')
|
||||
raise e
|
||||
|
||||
|
||||
from tuhi.dbusserver import TuhiDBusServer
|
||||
from tuhi.ble import BlueZDeviceManager
|
||||
from tuhi.wacom import WacomDevice, DeviceMode
|
||||
from tuhi.config import TuhiConfig
|
||||
|
||||
DEFAULT_CONFIG_PATH = Path(xdg.BaseDirectory.xdg_data_home, 'tuhi')
|
||||
|
||||
logging.basicConfig(format='%(asctime)s %(levelname)s: %(name)s: %(message)s',
|
||||
level=logging.INFO,
|
||||
datefmt='%H:%M:%S')
|
||||
|
@ -433,7 +436,7 @@ def main(args=sys.argv):
|
|||
parser.add_argument('--config-dir',
|
||||
help='Base directory for configuration',
|
||||
type=str,
|
||||
default=None)
|
||||
default=DEFAULT_CONFIG_PATH)
|
||||
|
||||
ns = parser.parse_args(args[1:])
|
||||
if ns.verbose:
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
|
||||
from gi.repository import GObject
|
||||
|
||||
import xdg.BaseDirectory
|
||||
import configparser
|
||||
import re
|
||||
import logging
|
||||
|
@ -23,18 +22,14 @@ from .protocol import ProtocolVersion
|
|||
|
||||
logger = logging.getLogger('tuhi.config')
|
||||
|
||||
DEFAULT_CONFIG_PATH = Path(xdg.BaseDirectory.xdg_data_home, 'tuhi')
|
||||
|
||||
|
||||
def is_btaddr(addr):
|
||||
return re.match('^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$', addr) is not None
|
||||
|
||||
|
||||
class TuhiConfig(GObject.Object):
|
||||
def __init__(self, config_dir=None):
|
||||
def __init__(self, config_dir):
|
||||
super().__init__()
|
||||
if config_dir is None:
|
||||
config_dir = DEFAULT_CONFIG_PATH
|
||||
self.config_dir = config_dir
|
||||
logger.debug(f'Using config directory: {self.config_dir}')
|
||||
Path(config_dir).mkdir(parents=True, exist_ok=True)
|
||||
|
|
|
@ -16,16 +16,21 @@ import logging
|
|||
|
||||
from .window import MainWindow
|
||||
from .config import Config
|
||||
import xdg.BaseDirectory
|
||||
from pathlib import Path
|
||||
|
||||
import gi
|
||||
gi.require_version("Gio", "2.0")
|
||||
gi.require_version("Gtk", "3.0")
|
||||
|
||||
|
||||
logging.basicConfig(format='%(asctime)s %(levelname)s: %(name)s: %(message)s',
|
||||
level=logging.INFO,
|
||||
datefmt='%H:%M:%S')
|
||||
logger = logging.getLogger('tuhi.gui')
|
||||
|
||||
DEFAULT_CONFIG_PATH = Path(xdg.BaseDirectory.xdg_data_home, 'tuhi')
|
||||
|
||||
|
||||
class Application(Gtk.Application):
|
||||
def __init__(self):
|
||||
|
@ -59,7 +64,7 @@ class Application(Gtk.Application):
|
|||
try:
|
||||
Config.set_base_path(options['config-dir'])
|
||||
except KeyError:
|
||||
pass
|
||||
Config.set_base_path(DEFAULT_CONFIG_PATH)
|
||||
|
||||
if 'verbose' in options:
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
from gi.repository import GObject
|
||||
|
||||
import xdg.BaseDirectory
|
||||
import configparser
|
||||
import logging
|
||||
import json
|
||||
|
@ -22,12 +21,10 @@ from pathlib import Path
|
|||
|
||||
logger = logging.getLogger('tuhi.gui.config')
|
||||
|
||||
DEFAULT_CONFIG_PATH = Path(xdg.BaseDirectory.xdg_data_home, 'tuhi')
|
||||
|
||||
|
||||
class Config(GObject.Object):
|
||||
_config_obj = None
|
||||
_base_path = DEFAULT_CONFIG_PATH
|
||||
_base_path = None
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
|
Loading…
Reference in New Issue