Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Michiel Cottaar
fslpy
Commits
7fd8647b
Commit
7fd8647b
authored
8 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Fixes/simplications to Notifier.
parent
f840df49
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/utils/notifier.py
+30
-27
30 additions, 27 deletions
fsl/utils/notifier.py
with
30 additions
and
27 deletions
fsl/utils/notifier.py
+
30
−
27
View file @
7fd8647b
...
...
@@ -202,23 +202,25 @@ class Notifier(object):
if
topic
is
None
:
topic
=
DEFAULT_TOPIC
return
self
.
__listeners
[
topic
][
name
].
enabled
try
:
return
self
.
__listeners
[
topic
][
name
].
enabled
except
KeyError
:
return
False
def
enableAll
(
self
,
topic
=
None
,
state
=
True
):
"""
Enable/disable all listeners for the specified topic.
:arg topic: Topic to enable/disable listeners on. If ``None``,
all listeners are enabled/disabled.
all listeners are enabled/disabled.
:arg state: State to set listeners to.
"""
if
topic
is
None
:
topic
=
DEFAULT_TOPIC
if
topic
is
not
None
:
topics
=
[
topic
]
else
:
topic
s
=
list
(
self
.
__enabled
.
keys
())
if
topic
in
self
.
__enabled
:
self
.
__enabled
[
topic
]
=
state
for
topic
in
topics
:
if
topic
in
self
.
__enabled
:
self
.
__enabled
[
topic
]
=
state
def
disableAll
(
self
,
topic
=
None
):
...
...
@@ -231,14 +233,13 @@ class Notifier(object):
def
isAllEnabled
(
self
,
topic
=
None
):
"""
Returns ``True`` if all listeners for the specified topic (or all
listeners if ``topic=None``) are enabled, ``False`` otherwise.
"""
"""
if
topic
is
None
:
topic
=
DEFAULT_TOPIC
if
topic
in
self
.
__enabled
:
return
self
.
__enabled
[
topic
]
else
:
return
True
return
self
.
__enabled
.
get
(
topic
,
False
)
@contextlib.contextmanager
def
skipAll
(
self
,
topic
=
None
):
"""
Context manager which disables all listeners for the
...
...
@@ -247,15 +248,21 @@ class Notifier(object):
:arg topic: Topic to skip listeners on. If ``None``, notification
is disabled for all topics.
"""
state
=
self
.
isAllEnabled
(
topic
)
self
.
disableAll
(
topic
)
if
topic
is
not
None
:
topics
=
[
topic
]
else
:
topics
=
list
(
self
.
__enabled
.
keys
())
states
=
[
self
.
isAllEnabled
(
t
)
for
t
in
topics
]
for
t
in
topics
:
self
.
disableAll
(
t
)
try
:
yield
finally
:
self
.
enableAll
(
topic
,
state
)
for
t
,
s
in
zip
(
topics
,
states
):
self
.
enableAll
(
t
,
s
)
@contextlib.contextmanager
...
...
@@ -364,21 +371,17 @@ class Notifier(object):
notified for the specified ``topic``.
"""
isDefault
=
topic
is
None
allEnabled
=
self
.
__enabled
.
get
(
DEFAULT_TOPIC
,
True
)
topicEnabled
=
((
isDefault
and
allEnabled
)
or
self
.
__enabled
.
get
(
topic
),
True
)
if
isDefault
:
topic
=
DEFAULT_TOPIC
listeners
=
[]
if
not
allEnabled
:
return
[]
# Default listeners are called on all topics
# (unless the default topic is disabled)
if
self
.
__enabled
.
get
(
DEFAULT_TOPIC
,
False
):
listeners
.
extend
(
self
.
__listeners
.
get
(
DEFAULT_TOPIC
,
{}).
values
())
if
topic
Enabled
:
listeners
=
list
(
self
.
__listeners
.
get
(
topic
,
{}).
values
())
if
topic
is
None
or
topic
==
DEFAULT_TOPIC
:
return
listeners
if
not
isDefault
:
listeners
.
extend
(
self
.
__listeners
.
get
(
DEFAULT_TOPIC
,
{}).
values
())
if
self
.
__enabled
.
get
(
topic
,
False
)
:
listeners
.
extend
(
self
.
__listeners
.
get
(
topic
,
{}).
values
())
return
listeners
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