[Merge] ~lamoura/update-notifier:show-only-esm-infra-alerts-on-esm-machine into update-notifier:master
Chad Smith
chad.smith at canonical.com
Mon May 10 19:43:41 UTC 2021
Diff comments:
> diff --git a/data/apt_check.py b/data/apt_check.py
> index 2f2bb3d..3b9998c 100755
> --- a/data/apt_check.py
> +++ b/data/apt_check.py
> @@ -8,14 +8,45 @@ import apt_pkg
> import os
> import sys
> from optparse import OptionParser
> +import re
> import gettext
> -import subprocess
> import distro_info
>
> +
> SYNAPTIC_PINFILE = "/var/lib/synaptic/preferences"
> -DISTRO = subprocess.check_output(
> - ["lsb_release", "-c", "-s"],
> - universal_newlines=True).strip()
> +OS_RELEASE_PATH = "/etc/os-release"
> +
> +
> +def _get_info_from_os_release(key):
> + " get info directly from os-release file "
> + if os.path.exists(OS_RELEASE_PATH):
> + with open(OS_RELEASE_PATH) as f:
> + search_res = re.search(
> + r"{}=(?P<name>.*)".format(key),
> + f.read()
> + )
> + if search_res:
> + return search_res.group("name")
> + else:
> + raise Exception(
> + "Could not find {} in {}".format(
> + key, OS_RELEASE_PATH
> + )
> + )
> + else:
> + raise Exception(
> + "File {} was not found on the system".format(
> + OS_RELEASE_PATH
> + )
> + )
> +
> +
> +def get_distro():
> + " get distro name "
> + return _get_info_from_os_release(key="UBUNTU_CODENAME")
We know this won't work on Trusty because trusty doesn't ship with an UBUNTU_CODENAME key in /etc/os-release. Not a blocker for the MP since we aren't going to target trusty. But maybe worth a comment # Will not work on Trusty which lacks UBUNTU_CODENAME key.
> +
> +
> +DISTRO = get_distro()
>
> ESM_INFRA_ORIGIN = "UbuntuESM"
> ESM_APPS_ORIGIN = "UbuntuESMApps"
> @@ -122,27 +158,37 @@ def _output_esm_package_count(outstream, service_type, esm_pkg_count):
>
>
> def _output_esm_package_alert(
> - outstream, service_type, disabled_pkg_count
> + outstream, service_type, disabled_pkg_count, is_esm=False
> ):
> " output the number of upgradable packages if esm service was enabled "
> outstream.write("\n")
> if disabled_pkg_count > 0:
> outstream.write("\n")
> +
> + if is_esm:
> + distro_version = get_distro_version()
I think we should wrap this call in a try/except in case we can't process or find VERSION_ID in /etc/os-release. Worst case scenario here is that in the exception we set learn_msg_suffix = "at https://ubuntu.com/esm". I think fallback behavior is much better than not updating MOTD messages at all due to a Trace on this.
I realize that if generally /etc/os-release is not parseable we'd also fail getting DISTRO so it's probably not a likely failure scenario, so take with a grain of salt.
> + esm_info_url = "https://ubuntu.com/{}".format(
> + distro_version.replace(".", "-")
> + )
> + learn_msg_suffix = "for Ubuntu {} at\n{}".format(
> + distro_version, esm_info_url)
> + else:
> + learn_msg_suffix = "at https://ubuntu.com/esm"
> +
> outstream.write(gettext.dngettext("update-notifier",
> "%i additional security "
> "update can be applied "
> "with UA %s: ESM\nLearn "
> "more about enabling UA "
> - "%s: ESM service at "
> - "https://ubuntu.com/esm",
> + "%s: ESM service %s",
> "%i additional security "
> "updates can be applied "
> "with UA %s: ESM\nLearn "
> "more about enabling UA "
> - "%s: ESM service at "
> - "https://ubuntu.com/esm",
> + "%s: ESM service %s",
> disabled_pkg_count) %
> - (disabled_pkg_count, service_type, service_type))
> + (disabled_pkg_count, service_type, service_type,
> + learn_msg_suffix))
> else:
> outstream.write("\n")
> outstream.write(gettext.dgettext("update-notifier",
--
https://code.launchpad.net/~lamoura/update-notifier/+git/update-notifier/+merge/402163
Your team Ubuntu Core Development Team is subscribed to branch update-notifier:master.
More information about the Ubuntu-reviews
mailing list