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,7 +947,44 @@ class DemoZenDaemon(ZenDaemon): ...@@ -947,7 +947,44 @@ 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.
:param str name: Optional script name.
:param str description: Optional script description.
"""
name = 'demo-zendaemon.py' if not name else name
description = 'DemoZenDaemon - Demonstration daemon' if not description else description
super().__init__(
name = name,
description = description,
#
# Configure required application paths to harmless locations.
#
path_bin = '/tmp',
path_cfg = '/tmp',
path_log = '/tmp',
path_tmp = '/tmp',
path_run = '/tmp',
# Force dhe demonstration daemon to stay in foreground.
default_no_daemon = True,
# Define internal daemon components.
components = [
DemoDaemonComponent()
],
# Schedule initial daemon events.
schedule = [
('default',)
]
)
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
...@@ -957,30 +994,12 @@ class DemoZenDaemon(ZenDaemon): ...@@ -957,30 +994,12 @@ class DemoZenDaemon(ZenDaemon):
if __name__ == "__main__": if __name__ == "__main__":
# Prepare demonstration environment. # Prepare demonstration environment.
pyzenkit.baseapp.BaseApp.json_save('/tmp/demo-zendaemon.py.conf', {'test_a':1}) DMN_NAME = 'demo-zendaemon.py'
pyzenkit.baseapp.BaseApp.json_save('/tmp/{}.conf'.format(DMN_NAME), {'test_a':1})
try: try:
os.mkdir('/tmp/demo-zendaemon.py') os.mkdir('/tmp/{}'.format(DMN_NAME))
except FileExistsError: except FileExistsError:
pass pass
ZENDAEMON = DemoZenDaemon( ZENDAEMON = DemoZenDaemon(DMN_NAME)
name = 'demo-zenscript.py',
description = 'DemoZenDaemon - Demonstration daemon',
#
# Configure required application paths to harmless locations.
#
path_bin = '/tmp',
path_cfg = '/tmp',
path_log = '/tmp',
path_tmp = '/tmp',
path_run = '/tmp',
default_no_daemon = True,
schedule = [('default',)],
components = [
DemoDaemonComponent()
]
)
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