Skip to content
Permalink
Browse files

Standardize naming convention of plugin subscription topics.

Discontinue use of multi-word segments in favor of colon-separated
namespacing.
  • Loading branch information
lovett committed Jan 14, 2020
1 parent 61a653f commit 72eccfe5f160f4d28ff7b692b6fdeacd80073f4b
@@ -81,7 +81,7 @@ def GET(self, *args, **kwargs) -> bytes:
general_query = None
if query:
general_query = cherrypy.engine.publish(
"bookmarks:generalize_query",
"bookmarks:generalize",
query
).pop()

@@ -33,13 +33,13 @@ def GET(*_args, **kwargs) -> bytes:
]

total = cherrypy.engine.publish(
"cdr:call_count",
"cdr:count",
src_exclude=src_exclusions,
dst_exclude=dst_exclusions
).pop()

calls = cherrypy.engine.publish(
"cdr:call_log",
"cdr:timeline",
src_exclude=src_exclusions,
dst_exclude=dst_exclusions,
offset=offset,
@@ -49,7 +49,7 @@ def side_effect(*args, **_):
{"key": "dst", "value": "test2"}
]]

if args[0] == "cdr:call_count":
if args[0] == "cdr:count":
return [1]

if args[0] == "url:paginate:newer_older":
@@ -65,13 +65,13 @@ def side_effect(*args, **_):
self.request("/")

publish_mock.assert_any_call(
"cdr:call_count",
"cdr:count",
dst_exclude=["test2"],
src_exclude=["test"]
)

publish_mock.assert_any_call(
"cdr:call_log",
"cdr:timeline",
dst_exclude=["test2"],
limit=50,
offset=0,
@@ -38,7 +38,7 @@ def POST(action=None) -> None:
cherrypy.engine.publish(
"scheduler:add",
5,
"urlfetch:get_file",
"urlfetch:get:file",
download_url,
destination,
files_to_extract=('GeoLite2-City.mmdb',)
@@ -62,7 +62,7 @@ def POST(*_args, **kwargs) -> None:
failure_message = None
if request_failed:
failure_message = cherrypy.engine.publish(
"applog:get_newest",
"applog:newest",
source="urlfetch",
key="get"
).pop()
@@ -32,7 +32,7 @@ def GET(*_args, **kwargs) -> bytes:
).pop()

title = cherrypy.engine.publish(
"markup:reduce_title",
"markup:reduce:title",
title
).pop()

@@ -37,9 +37,9 @@ def POST(*_args, **_kwargs) -> None:
cherrypy.response.status = 400
return

can_speak = cherrypy.engine.publish("speak:can_speak").pop()
muted = cherrypy.engine.publish("speak:muted").pop()

if not can_speak:
if muted:
cherrypy.response.status = 202
return

@@ -117,8 +117,8 @@ def test_muted(self, publish_mock):

def side_effect(*args, **_):
"""Side effects local function"""
if args[0] == "speak:can_speak":
return [False]
if args[0] == "speak:muted":
return [True]
return mock.DEFAULT

publish_mock.side_effect = side_effect
@@ -142,8 +142,8 @@ def test_not_muted(self, publish_mock):

def side_effect(*args, **_):
"""Side effects local function"""
if args[0] == "speak:can_speak":
return [True]
if args[0] == "speak:muted":
return [False]
return mock.DEFAULT

publish_mock.side_effect = side_effect
@@ -72,7 +72,7 @@ def GET(*_args, **kwargs) -> bytes:
)

call_history = cherrypy.engine.publish(
"cdr:call_history",
"cdr:history",
sanitized_number
).pop()

@@ -89,7 +89,7 @@ def side_effect(*args, **_):
(None, "Unabbreviated State")
],
"formatting:phone_sanitize": ["1234567890"],
"cdr:call_history": [[]],
"cdr:history": [[]],
}
if args[0] == "jinja:render":
return [""]
@@ -118,7 +118,7 @@ def side_effect(*args, **_):
}]
if args[0] == "formatting:phone_sanitize":
return ["1234567890"]
if args[0] == "cdr:call_history":
if args[0] == "cdr:history":
return [[{"clid": "test"}]]
if args[0] == "jinja:render":
return [""]
@@ -14,10 +14,10 @@ class Controller:
def GET(*_args, **_kwargs) -> bytes:
"""Present an interface for on-demand muting of the speech service."""

can_speak = cherrypy.engine.publish("speak:can_speak").pop()
muted = cherrypy.engine.publish("speak:muted").pop()

muted_by_schedule = cherrypy.engine.publish(
"speak:muted_by_schedule"
"speak:muted:scheduled"
).pop()

schedules = cherrypy.engine.publish(
@@ -35,7 +35,7 @@ def GET(*_args, **_kwargs) -> bytes:
return cherrypy.engine.publish(
"jinja:render",
"speak.jinja.html",
can_speak=can_speak,
muted=muted,
muted_by_schedule=muted_by_schedule,
registry_url=registry_url,
schedules=schedules
@@ -57,12 +57,12 @@ def POST(*_args, **kwargs) -> None:
key_slice=2
).pop()

can_speak = cherrypy.engine.publish("speak:can_speak").pop()
muted = cherrypy.engine.publish("speak:muted").pop()

if action == "toggle":
action = "unmute"
if can_speak:
action = "mute"
action = "mute"
if muted:
action = "unmute"

if action == "mute":
cherrypy.engine.publish("speak:mute")
@@ -93,7 +93,7 @@ def POST(*_args, **kwargs) -> None:

raise cherrypy.HTTPRedirect(app_url)

if not can_speak:
if muted:
response_status = 202
else:
cherrypy.engine.publish("speak", statement, locale, gender)
@@ -45,8 +45,8 @@ def test_muted(self, publish_mock):
def side_effect(*args, **_):
"""Side effects local function"""

if args[0] == "speak:can_speak":
return [False]
if args[0] == "speak:muted":
return [True]
return mock.DEFAULT

publish_mock.side_effect = side_effect
@@ -66,8 +66,8 @@ def test_not_muted(self, publish_mock):
def side_effect(*args, **_):
"""Side effects local function"""

if args[0] == "speak:can_speak":
return [True]
if args[0] == "speak:muted":
return [False]
return mock.DEFAULT

publish_mock.side_effect = side_effect
@@ -10,7 +10,7 @@
{% endif %}

{% if not muted_by_schedule %}
{% if can_speak %}
{% if not muted %}
<form method="POST" action="{{ app_url }}">
<input type="hidden" name="action" value="mute" />
<button>Mute now</button>
@@ -40,12 +40,12 @@ def start(self) -> None:
This plugin owns the applog prefix.
"""
self.bus.subscribe("applog:add", self.add)
self.bus.subscribe("applog:process_queue", self.process_queue)
self.bus.subscribe("applog:get_newest", self.get_newest)
self.bus.subscribe("applog:pull", self.pull)
self.bus.subscribe("applog:newest", self.newest)
self.bus.subscribe("applog:prune", self.prune)
self.bus.subscribe("applog:search", self.search)

def get_newest(
def newest(
self,
source: str,
key: str
@@ -61,7 +61,7 @@ def get_newest(
)
)

def process_queue(self) -> None:
def pull(self) -> None:
"""Transfer messages from the queue to the database."""

messages = list(self.queue)
@@ -87,7 +87,7 @@ def add(self,

self.queue.append((caller, key, str(value)))

cherrypy.engine.publish("scheduler:add", 1, "applog:process_queue")
cherrypy.engine.publish("scheduler:add", 1, "applog:pull")

# Mirror the log message on the cherrypy log for convenience.
cherrypy.log(f"[{caller}] {key}: {value}")
@@ -102,7 +102,7 @@ def start(self) -> None:
self.bus.subscribe("bookmarks:add", self.add)
self.bus.subscribe("bookmarks:add:fulltext", self.add_full_text)
self.bus.subscribe("bookmarks:search", self.search)
self.bus.subscribe("bookmarks:generalize_query", self.generalize_query)
self.bus.subscribe("bookmarks:generalize", self.generalize)
self.bus.subscribe("bookmarks:prune", self.prune)
self.bus.subscribe("bookmarks:recent", self.recent)
self.bus.subscribe("bookmarks:tags:recent", self.recent_tags)
@@ -126,7 +126,7 @@ def domain_and_url(url: str) -> typing.Tuple[str, str]:
)

@staticmethod
def generalize_query(query: str) -> str:
def generalize(query: str) -> str:
"""Convert a search query to a more generic form suitable for use with
external search engines.
@@ -19,11 +19,11 @@ def start(self) -> None:
This plugin owns the cdr prefix.
"""
self.bus.subscribe("cdr:call_count", self.call_count)
self.bus.subscribe("cdr:call_log", self.call_log)
self.bus.subscribe("cdr:call_history", self.call_history)
self.bus.subscribe("cdr:count", self.count)
self.bus.subscribe("cdr:timeline", self.timeline)
self.bus.subscribe("cdr:history", self.history)

def call_count(
def count(
self,
src: str = None,
src_exclude: typing.Tuple[str, ...] = (),
@@ -60,7 +60,7 @@ def call_count(
return int(row["count"])
return None

def call_log(self,
def timeline(self,
src_exclude: typing.Tuple[str, ...] = (),
dst_exclude: typing.Tuple[str, ...] = (),
offset: int = 0,
@@ -101,11 +101,11 @@ def call_log(self,
tuple(reversed(reversed_values))
)

def call_history(
def history(
self,
number: str,
limit: int = 50) -> typing.List[sqlite3.Row]:
"""An abbreviated version of call_log() for a single number.
"""An abbreviated version of log() for a single number.
Puts more emphasis on whether a call was placed or received.
@@ -17,7 +17,7 @@ def start(self) -> None:
This plugin owns the markup prefix.
"""
self.bus.subscribe("markup:reduce_title", self.reduce_title)
self.bus.subscribe("markup:reduce:title", self.reduce_title)
self.bus.subscribe("markup:plaintext", self.plain_text)

def reduce_title(self, title: str) -> str:
@@ -86,8 +86,8 @@ def start(self) -> None:
This plugin owns the speak prefix.
"""
self.bus.subscribe("speak:can_speak", self.can_speak)
self.bus.subscribe("speak:muted_by_schedule", self.muted_by_schedule)
self.bus.subscribe("speak:muted", self.muted)
self.bus.subscribe("speak:muted:scheduled", self.muted_by_schedule)
self.bus.subscribe("speak:mute", self.mute)
self.bus.subscribe("speak:unmute", self.unmute)
self.bus.subscribe("speak", self.speak)
@@ -150,7 +150,7 @@ def ssml(self, statement: str, locale: str, gender: str) -> bytes:

return document.strip().encode("utf-8")

def can_speak(self) -> bool:
def muted(self) -> bool:
"""Determine whether the application has been muted."""

temporarily_muted = cherrypy.engine.publish(
@@ -159,7 +159,7 @@ def can_speak(self) -> bool:
).pop()

if temporarily_muted:
return False
return True

return not self.muted_by_schedule()

@@ -21,7 +21,7 @@ def start(self) -> None:
This plugin owns the urlfetch prefix.
"""
self.bus.subscribe("urlfetch:get", self.get)
self.bus.subscribe("urlfetch:get_file", self.get_file)
self.bus.subscribe("urlfetch:get:file", self.get_file)
self.bus.subscribe("urlfetch:post", self.post)

cherrypy.engine.publish("urlfetch:ready")

0 comments on commit 72eccfe

Please sign in to comment.
You can’t perform that action at this time.