introduce a configuration module

This commit is contained in:
Sven Czarnian
2021-08-15 08:59:32 +02:00
vanhempi a3f4f8f41b
commit 7b26e27c9d
4 muutettua tiedostoa jossa 66 lisäystä ja 0 poistoa

Näytä tiedosto

@@ -0,0 +1,23 @@
#!/usr/bin/env python
import configparser
import sys
from aman.config.Server import Server
class Configuration:
def __init__(self, filepath : str):
config = configparser.ConfigParser()
config.read(filepath)
# search the required sections
serverSectionAvailable = False
for key in config:
if 'SERVER' == key:
serverSectionAvailable = True
if not serverSectionAvailable:
sys.stderr.write('No server-configuration section found!')
sys.exit(-1)
self.Server = Server(config['SERVER'])

41
aman/config/Server.py Normal file
Näytä tiedosto

@@ -0,0 +1,41 @@
#!/usr/bin/env python
import configparser;
import sys
class Server():
def __init__(self, config : configparser.ConfigParser):
self.Address = None
self.PortReceiver = None
self.PortNotification = None
self.ServerKeyPath = None
self.ClientKeyPath = None
# search the required sections
for key in config:
if 'address' == key:
self.Address = config['address']
elif 'portreceiver' == key:
self.PortReceiver = int(config['portreceiver'])
elif 'portnotification' == key:
self.PortNotification = int(config['portnotification'])
elif 'serverkeypath' == key:
self.ServerKeyPath = config['serverkeypath']
elif 'clientkeypath' == key:
self.ClientKeyPath = config['clientkeypath']
if self.Address is None:
sys.stderr.write('No server-address configuration found!')
sys.exit(-1)
if self.PortReceiver is None:
sys.stderr.write('No server-port-receiver configuration found!')
sys.exit(-1)
if self.PortNotification is None:
sys.stderr.write('No server-port-notification configuration found!')
sys.exit(-1)
if self.ServerKeyPath is None:
sys.stderr.write('No server-key-path configuration found!')
sys.exit(-1)
if self.ClientKeyPath is None:
sys.stderr.write('No client-key-path configuration found!')
sys.exit(-1)

0
aman/config/__init__.py Normal file
Näytä tiedosto

Näytä tiedosto

@@ -61,6 +61,7 @@ setup(
packages = [
'aman',
'aman.com',
'aman.config',
'aman.tools'
],
namespace_packages = [ 'aman' ],
@@ -73,6 +74,7 @@ setup(
install_requires=[
'argparse',
'setuptools',
'configparser',
'pyzmq',
'protobuf'
]