Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Pyzenkit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
713
Mentat
Pyzenkit
Commits
a345adf6
Commit
a345adf6
authored
7 years ago
by
Honza Mach
Browse files
Options
Downloads
Patches
Plain Diff
Added more convenient __init__ method for DemoZenDaemon.
parent
73d9c6b3
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pyzenkit/tests/test_zendaemon.py
+3
-13
3 additions, 13 deletions
pyzenkit/tests/test_zendaemon.py
pyzenkit/zendaemon.py
+42
-23
42 additions, 23 deletions
pyzenkit/zendaemon.py
with
45 additions
and
36 deletions
pyzenkit/tests/test_zendaemon.py
+
3
−
13
View file @
a345adf6
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
pyzenkit/zendaemon.py
+
42
−
23
View file @
a345adf6
...
@@ -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
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment