Skip to content

Commit b5e03e1

Browse files
committed
[IMP] util.announce
Allow to specify the media where to announce messages. This is done via the `UPG_ANNOUNCE_MEDIA` environment variable. closes #158 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 7b59489 commit b5e03e1

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

src/util/report.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,25 @@ def html_escape(text):
6060
from openerp.addons.base.module.module import MyWriter
6161

6262
from .exceptions import MigrationError
63-
from .misc import has_enterprise, version_gte
63+
from .misc import has_enterprise, split_osenv, version_gte
6464
from .orm import env, get_admin_channel, guess_admin_id
6565

6666
migration_reports = {}
6767
_logger = logging.getLogger(__name__)
6868

69+
70+
_ENV_AM = set(split_osenv("UPG_ANNOUNCE_MEDIA", default="discuss"))
71+
ANNOUNCE_MEDIA = _ENV_AM & {"", "discuss", "logger"}
72+
if _ENV_AM - ANNOUNCE_MEDIA:
73+
raise ValueError(
74+
"Invalid value for the environment variable `UPG_ANNOUNCE_MEDIA`: {!r}. "
75+
"Authorized values are a combination of 'discuss', 'logger', or an empty string.".format(
76+
os.getenv("UPG_ANNOUNCE_MEDIA")
77+
)
78+
)
79+
ANNOUNCE_MEDIA -= {""}
80+
81+
6982
ODOO_SHOWCASE_VIDEOS = {
7083
"18.0": "gbE3azm_Io0",
7184
"saas~17.4": "8F4-uDwom8A",
@@ -193,6 +206,8 @@ def announce(
193206
footer=_DEFAULT_FOOTER,
194207
pluses_for_enterprise=None,
195208
):
209+
if not ANNOUNCE_MEDIA:
210+
return
196211
if pluses_for_enterprise is None:
197212
# default value depend on format and version
198213
major = version[0]
@@ -203,6 +218,18 @@ def announce(
203218
replacement = r"\1- \2\n" if has_enterprise() else ""
204219
msg = re.sub(plus_re, replacement, msg, flags=re.M)
205220

221+
if format == "rst":
222+
msg = rst2html(msg)
223+
elif format == "md":
224+
msg = md2html(msg)
225+
226+
message = ((header or "") + msg + (footer or "")).format(version=version)
227+
if "logger" in ANNOUNCE_MEDIA:
228+
_logger.info(message)
229+
230+
if "discuss" not in ANNOUNCE_MEDIA:
231+
return
232+
206233
# do not notify early, in case the migration fails halfway through
207234
ctx = {"mail_notify_force_send": False, "mail_notify_author": True}
208235

@@ -240,14 +267,6 @@ def ref(xid):
240267
# Cannot find record, post the message on the wall of the admin
241268
pass
242269

243-
if format == "rst":
244-
msg = rst2html(msg)
245-
elif format == "md":
246-
msg = md2html(msg)
247-
248-
message = ((header or "") + msg + (footer or "")).format(version=version)
249-
_logger.debug(message)
250-
251270
type_field = ["type", "message_type"][version_gte("9.0")]
252271
# From 12.0, system notificatications are sent by email,
253272
# and do not increment the upper right notification counter.

0 commit comments

Comments
 (0)