introduce a configuration module
This commit is contained in:
23
aman/config/Configuration.py
Normal file
23
aman/config/Configuration.py
Normal file
@@ -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
41
aman/config/Server.py
Normal file
@@ -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
0
aman/config/__init__.py
Normal file
2
setup.py
2
setup.py
@@ -61,6 +61,7 @@ setup(
|
|||||||
packages = [
|
packages = [
|
||||||
'aman',
|
'aman',
|
||||||
'aman.com',
|
'aman.com',
|
||||||
|
'aman.config',
|
||||||
'aman.tools'
|
'aman.tools'
|
||||||
],
|
],
|
||||||
namespace_packages = [ 'aman' ],
|
namespace_packages = [ 'aman' ],
|
||||||
@@ -73,6 +74,7 @@ setup(
|
|||||||
install_requires=[
|
install_requires=[
|
||||||
'argparse',
|
'argparse',
|
||||||
'setuptools',
|
'setuptools',
|
||||||
|
'configparser',
|
||||||
'pyzmq',
|
'pyzmq',
|
||||||
'protobuf'
|
'protobuf'
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user