Skip to content
Snippets Groups Projects
Commit a345adf6 authored by Honza Mach's avatar Honza Mach
Browse files

Added more convenient __init__ method for DemoZenDaemon.

parent 73d9c6b3
No related branches found
No related tags found
No related merge requests found
...@@ -29,7 +29,7 @@ import pyzenkit.zendaemon ...@@ -29,7 +29,7 @@ import pyzenkit.zendaemon
# #
# Global variables # Global variables
# #
DMN_NAME = 'test_zendaemon.py' # Name of the daemon process DMN_NAME = 'test-zendaemon.py' # Name of the daemon process
JSON_FILE_NAME = '/tmp/daemon-state.json' # Name of the test JSON file JSON_FILE_NAME = '/tmp/daemon-state.json' # Name of the test JSON file
CFG_FILE_NAME = '/tmp/{}.conf'.format(DMN_NAME) # Name of the daemon configuration file CFG_FILE_NAME = '/tmp/{}.conf'.format(DMN_NAME) # Name of the daemon configuration file
CFG_DIR_NAME = '/tmp/{}'.format(DMN_NAME) # Name of the daemon configuration directory CFG_DIR_NAME = '/tmp/{}'.format(DMN_NAME) # Name of the daemon configuration directory
...@@ -43,18 +43,8 @@ class TestPyzenkitZenDaemon(unittest.TestCase): ...@@ -43,18 +43,8 @@ class TestPyzenkitZenDaemon(unittest.TestCase):
except FileExistsError: except FileExistsError:
pass pass
self.obj = pyzenkit.zendaemon._DemoZenDaemon( self.obj = pyzenkit.zendaemon.DemoZenDaemon(name = DMN_NAME)
name = DMN_NAME,
path_cfg = '/tmp',
path_log = '/tmp',
path_tmp = '/tmp',
path_run = '/tmp',
description = 'DemoZenDaemon - generic daemon (DEMO)',
schedule = [('default',)],
components = [
pyzenkit.zendaemon._DemoDaemonComponent()
]
)
def tearDown(self): def tearDown(self):
os.remove(CFG_FILE_NAME) os.remove(CFG_FILE_NAME)
shutil.rmtree(CFG_DIR_NAME) shutil.rmtree(CFG_DIR_NAME)
......
...@@ -947,25 +947,21 @@ class DemoZenDaemon(ZenDaemon): ...@@ -947,25 +947,21 @@ class DemoZenDaemon(ZenDaemon):
""" """
Minimalistic class for demonstration purposes. Minimalistic class for demonstration purposes.
""" """
pass def __init__(self, name = None, description = None):
"""
#------------------------------------------------------------------------------- Initialize demonstration script. This method overrides the base
implementation in :py:func:`baseapp.BaseApp.__init__` and it aims to
# even more simplify the script object creation.
# Perform the demonstration.
#
if __name__ == "__main__":
# Prepare demonstration environment. :param str name: Optional script name.
pyzenkit.baseapp.BaseApp.json_save('/tmp/demo-zendaemon.py.conf', {'test_a':1}) :param str description: Optional script description.
try: """
os.mkdir('/tmp/demo-zendaemon.py') name = 'demo-zendaemon.py' if not name else name
except FileExistsError: description = 'DemoZenDaemon - Demonstration daemon' if not description else description
pass
ZENDAEMON = DemoZenDaemon( super().__init__(
name = 'demo-zenscript.py', name = name,
description = 'DemoZenDaemon - Demonstration daemon', description = description,
# #
# Configure required application paths to harmless locations. # Configure required application paths to harmless locations.
...@@ -976,11 +972,34 @@ if __name__ == "__main__": ...@@ -976,11 +972,34 @@ if __name__ == "__main__":
path_tmp = '/tmp', path_tmp = '/tmp',
path_run = '/tmp', path_run = '/tmp',
# Force dhe demonstration daemon to stay in foreground.
default_no_daemon = True, default_no_daemon = True,
schedule = [('default',)], # Define internal daemon components.
components = [ components = [
DemoDaemonComponent() DemoDaemonComponent()
],
# Schedule initial daemon events.
schedule = [
('default',)
] ]
) )
#-------------------------------------------------------------------------------
#
# Perform the demonstration.
#
if __name__ == "__main__":
# Prepare demonstration environment.
DMN_NAME = 'demo-zendaemon.py'
pyzenkit.baseapp.BaseApp.json_save('/tmp/{}.conf'.format(DMN_NAME), {'test_a':1})
try:
os.mkdir('/tmp/{}'.format(DMN_NAME))
except FileExistsError:
pass
ZENDAEMON = DemoZenDaemon(DMN_NAME)
ZENDAEMON.run() ZENDAEMON.run()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment