mirror of
https://github.com/KevinMidboe/mktxp-no-cli.git
synced 2025-10-29 17:50:23 +00:00
cli options
This commit is contained in:
15
mktxp/cli/config/.mktxp.conf
Normal file
15
mktxp/cli/config/.mktxp.conf
Normal file
@@ -0,0 +1,15 @@
|
||||
## Copyright (c) 2020 Arseniy Kuznetsov
|
||||
##
|
||||
## This program is free software; you can redistribute it and/or
|
||||
## modify it under the terms of the GNU General Public License
|
||||
## as published by the Free Software Foundation; either version 2
|
||||
## of the License, or (at your option) any later version.
|
||||
##
|
||||
## This program is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU General Public License for more details.
|
||||
|
||||
|
||||
[MKTXP]
|
||||
port = 49090
|
||||
@@ -44,7 +44,6 @@ class MKTXPConfigKeys:
|
||||
FE_WIRELESS_KEY = 'wireless'
|
||||
FE_CAPSMAN_KEY = 'capsman'
|
||||
|
||||
|
||||
# UnRegistered entries placeholder
|
||||
NO_ENTRIES_REGISTERED = 'NoEntriesRegistered'
|
||||
|
||||
@@ -55,12 +54,16 @@ class MKTXPConfigKeys:
|
||||
# Default ports
|
||||
DEFAULT_API_PORT = 8728
|
||||
DEFAULT_API_SSL_PORT = 8729
|
||||
DEFAULT_MKTXP_PORT = 49090
|
||||
|
||||
BOOLEAN_KEYS = [ENABLED_KEY, SSL_KEY, SSL_CERTIFICATE,
|
||||
FE_DHCP_KEY, FE_DHCP_LEASE_KEY, FE_DHCP_POOL_KEY, FE_INTERFACE_KEY,
|
||||
FE_MONITOR_KEY, FE_ROUTE_KEY, FE_WIRELESS_KEY, FE_CAPSMAN_KEY]
|
||||
STR_KEYS = [HOST_KEY, USER_KEY, PASSWD_KEY]
|
||||
|
||||
# MKTXP config entry nane
|
||||
MKTXP_CONFIG_ENTRY_NAME = 'MKTXP'
|
||||
|
||||
|
||||
class ConfigEntry:
|
||||
MKTXPEntry = namedtuple('MKTXPEntry', [MKTXPConfigKeys.ENABLED_KEY, MKTXPConfigKeys.HOST_KEY, MKTXPConfigKeys.PORT_KEY,
|
||||
@@ -121,17 +124,24 @@ class MKTXPConfigHandler:
|
||||
|
||||
# if needed, stage the user config data
|
||||
self.usr_conf_data_path = os.path.join(self.os_config.mktxp_user_dir_path, 'mktxp.conf')
|
||||
if not os.path.exists(self.usr_conf_data_path):
|
||||
# stage from the mktxp conf template
|
||||
lookup_path = resource_filename(Requirement.parse("mktxp"), "mktxp/cli/config/mktxp.conf")
|
||||
shutil.copy(lookup_path, self.usr_conf_data_path)
|
||||
self.mktxp_conf_path = os.path.join(self.os_config.mktxp_user_dir_path, '.mktxp.conf')
|
||||
|
||||
self.read_from_disk()
|
||||
self._create_os_path(self.usr_conf_data_path, 'mktxp/cli/config/mktxp.conf')
|
||||
self._create_os_path(self.mktxp_conf_path, 'mktxp/cli/config/.mktxp.conf')
|
||||
|
||||
def read_from_disk(self):
|
||||
self._read_from_disk()
|
||||
|
||||
def _read_from_disk(self):
|
||||
''' (Force-)Read conf data from disk
|
||||
'''
|
||||
self.config = ConfigObj(self.usr_conf_data_path)
|
||||
self.mktxp_config = ConfigObj(self.mktxp_conf_path)
|
||||
|
||||
def _create_os_path(self, os_path, resource_path):
|
||||
if not os.path.exists(os_path):
|
||||
# stage from the conf templates
|
||||
lookup_path = resource_filename(Requirement.parse("mktxp"), resource_path)
|
||||
shutil.copy(lookup_path, os_path)
|
||||
|
||||
|
||||
# MKTXP entries
|
||||
@@ -179,6 +189,12 @@ class MKTXPConfigHandler:
|
||||
entry_reader = self._entry_reader(entry_name)
|
||||
return ConfigEntry.MKTXPEntry(**entry_reader)
|
||||
|
||||
def mktxp_port(self):
|
||||
if self.mktxp_config.get(MKTXPConfigKeys.MKTXP_CONFIG_ENTRY_NAME) and \
|
||||
self.mktxp_config[MKTXPConfigKeys.MKTXP_CONFIG_ENTRY_NAME].get(MKTXPConfigKeys.PORT_KEY):
|
||||
return self.mktxp_config[MKTXPConfigKeys.MKTXP_CONFIG_ENTRY_NAME].as_int(MKTXPConfigKeys.PORT_KEY)
|
||||
return MKTXPConfigKeys.DEFAULT_MKTXP_PORT
|
||||
|
||||
# Helpers
|
||||
def _entry_reader(self, entry_name):
|
||||
entry = {}
|
||||
@@ -206,3 +222,15 @@ class MKTXPConfigHandler:
|
||||
# Simplest possible Singleton impl
|
||||
config_handler = MKTXPConfigHandler()
|
||||
|
||||
|
||||
''' if not os.path.exists(self.usr_conf_data_path):
|
||||
# stage from the mktxp conf template
|
||||
lookup_path = resource_filename(Requirement.parse("mktxp"), "mktxp/cli/config/mktxp.conf")
|
||||
shutil.copy(lookup_path, self.usr_conf_data_path)
|
||||
|
||||
if not os.path.exists(self.mktxp_conf_path):
|
||||
# stage from the mktxp conf template
|
||||
lookup_path = resource_filename(Requirement.parse("mktxp"), "mktxp/cli/config/.mktxp.conf")
|
||||
shutil.copy(lookup_path, self.mktxp_conf_path)
|
||||
|
||||
'''
|
||||
|
||||
Reference in New Issue
Block a user