Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FSL
fslpy
Commits
93db5c85
There was a problem fetching the pipeline summary.
Commit
93db5c85
authored
8 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Notifier has listener enable/disable/skip methods
parent
e6831b51
No related branches found
No related tags found
No related merge requests found
Pipeline
#
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/utils/notifier.py
+44
-0
44 additions, 0 deletions
fsl/utils/notifier.py
with
44 additions
and
0 deletions
fsl/utils/notifier.py
+
44
−
0
View file @
93db5c85
...
...
@@ -11,6 +11,7 @@ as a mixin for providing a simple notification API.
import
logging
import
inspect
import
contextlib
import
collections
import
props
...
...
@@ -156,6 +157,49 @@ class Notifier(object):
log
.
debug
(
'
{}: De-registered listener {}
'
.
format
(
type
(
self
).
__name__
,
listener
))
def
enable
(
self
,
name
,
topic
=
None
):
"""
Enables the specified listener.
"""
if
topic
is
None
:
topic
=
DEFAULT_TOPIC
self
.
__listeners
[
topic
][
name
].
enabled
=
True
def
disable
(
self
,
name
,
topic
=
None
):
"""
Disables the specified listener.
"""
if
topic
is
None
:
topic
=
DEFAULT_TOPIC
self
.
__listeners
[
topic
][
name
].
enabled
=
False
def
isEnabled
(
self
,
name
,
topic
=
None
):
"""
Returns ``True`` if the specified listener is enabled, ``False``
otherwise.
"""
if
topic
is
None
:
topic
=
DEFAULT_TOPIC
return
self
.
__listeners
[
topic
][
name
].
enabled
@contextlib.contextmanager
def
skip
(
self
,
name
,
topic
=
None
):
"""
Context manager which disables the speciifed listener, and
restores its state before returning.
"""
state
=
self
.
isEnabled
(
name
,
topic
)
self
.
disable
(
name
,
topic
)
try
:
yield
finally
:
if
state
:
self
.
enable
(
name
,
topic
)
else
:
self
.
disable
(
name
,
topic
)
def
notify
(
self
,
*
args
,
**
kwargs
):
...
...
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