mirror of https://github.com/tuhiproject/tuhi.git
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>pull/169/head
parent
be9b3c02cc
commit
9ef4002b39
|
@ -16,6 +16,8 @@ import enum
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import xdg.BaseDirectory
|
||||||
|
from pathlib import Path
|
||||||
try:
|
try:
|
||||||
from gi.repository import GObject, GLib
|
from gi.repository import GObject, GLib
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -26,12 +28,13 @@ except Exception as e:
|
||||||
print(f'')
|
print(f'')
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
from tuhi.dbusserver import TuhiDBusServer
|
from tuhi.dbusserver import TuhiDBusServer
|
||||||
from tuhi.ble import BlueZDeviceManager
|
from tuhi.ble import BlueZDeviceManager
|
||||||
from tuhi.wacom import WacomDevice, DeviceMode
|
from tuhi.wacom import WacomDevice, DeviceMode
|
||||||
from tuhi.config import TuhiConfig
|
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',
|
logging.basicConfig(format='%(asctime)s %(levelname)s: %(name)s: %(message)s',
|
||||||
level=logging.INFO,
|
level=logging.INFO,
|
||||||
datefmt='%H:%M:%S')
|
datefmt='%H:%M:%S')
|
||||||
|
@ -433,7 +436,7 @@ def main(args=sys.argv):
|
||||||
parser.add_argument('--config-dir',
|
parser.add_argument('--config-dir',
|
||||||
help='Base directory for configuration',
|
help='Base directory for configuration',
|
||||||
type=str,
|
type=str,
|
||||||
default=None)
|
default=DEFAULT_CONFIG_PATH)
|
||||||
|
|
||||||
ns = parser.parse_args(args[1:])
|
ns = parser.parse_args(args[1:])
|
||||||
if ns.verbose:
|
if ns.verbose:
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
|
|
||||||
from gi.repository import GObject
|
from gi.repository import GObject
|
||||||
|
|
||||||
import xdg.BaseDirectory
|
|
||||||
import configparser
|
import configparser
|
||||||
import re
|
import re
|
||||||
import logging
|
import logging
|
||||||
|
@ -23,18 +22,14 @@ from .protocol import ProtocolVersion
|
||||||
|
|
||||||
logger = logging.getLogger('tuhi.config')
|
logger = logging.getLogger('tuhi.config')
|
||||||
|
|
||||||
DEFAULT_CONFIG_PATH = Path(xdg.BaseDirectory.xdg_data_home, 'tuhi')
|
|
||||||
|
|
||||||
|
|
||||||
def is_btaddr(addr):
|
def is_btaddr(addr):
|
||||||
return re.match('^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$', addr) is not None
|
return re.match('^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$', addr) is not None
|
||||||
|
|
||||||
|
|
||||||
class TuhiConfig(GObject.Object):
|
class TuhiConfig(GObject.Object):
|
||||||
def __init__(self, config_dir=None):
|
def __init__(self, config_dir):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
if config_dir is None:
|
|
||||||
config_dir = DEFAULT_CONFIG_PATH
|
|
||||||
self.config_dir = config_dir
|
self.config_dir = config_dir
|
||||||
logger.debug(f'Using config directory: {self.config_dir}')
|
logger.debug(f'Using config directory: {self.config_dir}')
|
||||||
Path(config_dir).mkdir(parents=True, exist_ok=True)
|
Path(config_dir).mkdir(parents=True, exist_ok=True)
|
||||||
|
|
|
@ -16,16 +16,21 @@ import logging
|
||||||
|
|
||||||
from .window import MainWindow
|
from .window import MainWindow
|
||||||
from .config import Config
|
from .config import Config
|
||||||
|
import xdg.BaseDirectory
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import gi
|
import gi
|
||||||
gi.require_version("Gio", "2.0")
|
gi.require_version("Gio", "2.0")
|
||||||
gi.require_version("Gtk", "3.0")
|
gi.require_version("Gtk", "3.0")
|
||||||
|
|
||||||
|
|
||||||
logging.basicConfig(format='%(asctime)s %(levelname)s: %(name)s: %(message)s',
|
logging.basicConfig(format='%(asctime)s %(levelname)s: %(name)s: %(message)s',
|
||||||
level=logging.INFO,
|
level=logging.INFO,
|
||||||
datefmt='%H:%M:%S')
|
datefmt='%H:%M:%S')
|
||||||
logger = logging.getLogger('tuhi.gui')
|
logger = logging.getLogger('tuhi.gui')
|
||||||
|
|
||||||
|
DEFAULT_CONFIG_PATH = Path(xdg.BaseDirectory.xdg_data_home, 'tuhi')
|
||||||
|
|
||||||
|
|
||||||
class Application(Gtk.Application):
|
class Application(Gtk.Application):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -59,7 +64,7 @@ class Application(Gtk.Application):
|
||||||
try:
|
try:
|
||||||
Config.set_base_path(options['config-dir'])
|
Config.set_base_path(options['config-dir'])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
Config.set_base_path(DEFAULT_CONFIG_PATH)
|
||||||
|
|
||||||
if 'verbose' in options:
|
if 'verbose' in options:
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
|
|
||||||
from gi.repository import GObject
|
from gi.repository import GObject
|
||||||
|
|
||||||
import xdg.BaseDirectory
|
|
||||||
import configparser
|
import configparser
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
|
@ -22,12 +21,10 @@ from pathlib import Path
|
||||||
|
|
||||||
logger = logging.getLogger('tuhi.gui.config')
|
logger = logging.getLogger('tuhi.gui.config')
|
||||||
|
|
||||||
DEFAULT_CONFIG_PATH = Path(xdg.BaseDirectory.xdg_data_home, 'tuhi')
|
|
||||||
|
|
||||||
|
|
||||||
class Config(GObject.Object):
|
class Config(GObject.Object):
|
||||||
_config_obj = None
|
_config_obj = None
|
||||||
_base_path = DEFAULT_CONFIG_PATH
|
_base_path = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
Loading…
Reference in New Issue