~juliank/update-notifier/esm

« back to all changes in this revision

Viewing changes to data/apt_check.py

  • Committer: Julian Andres Klode
  • Date: 2019-04-02 13:17:02 UTC
  • Revision ID: juliank@ubuntu.com-20190402131702-1je27m5rfyruev17
apt-check: Tell people to enable ESM if ESM updates are available

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
 
72
72
 
73
73
def write_human_readable_summary(outstream, upgrades, security_updates,
74
 
                                 esm_updates, have_esm):
 
74
                                 esm_updates, have_esm, disabled_esm_updates):
75
75
    " write out human summary summary to outstream "
76
76
    if have_esm is not None:
77
77
        if have_esm:
109
109
                    security_updates)
110
110
    outstream.write("\n")
111
111
 
 
112
    if disabled_esm_updates > 0:
 
113
        outstream.write("\n")
 
114
        outstream.write(gettext.dngettext("update-notifier",
 
115
                                          "Enable ESM to receive %i additional "
 
116
                                          "security update.",
 
117
                                          "Enable ESM to receive %i additional "
 
118
                                          "security updates.",
 
119
                                          disabled_esm_updates) %
 
120
                        disabled_esm_updates)
 
121
        outstream.write("\n")
 
122
        outstream.write(gettext.dgettext("update-notifier",
 
123
                                         "See 'ua enable esm' or "
 
124
                                         "https://ubuntu.com/esm"))
 
125
        outstream.write("\n")
 
126
 
 
127
 
 
128
def has_disabled_esm_security_update(depcache, pkg):
 
129
    " check if we have a disabled ESM security update "
 
130
    inst_ver = pkg.current_ver
 
131
    if not inst_ver:
 
132
        return False
 
133
 
 
134
    for ver in pkg.version_list:
 
135
        if ver == inst_ver:
 
136
            break
 
137
 
 
138
        for (file, index) in ver.file_list:
 
139
            if (file.origin == "UbuntuESM" and file.archive.startswith(DISTRO)
 
140
                    and depcache.policy.get_priority(file) == -32768):
 
141
                return True
 
142
    return False
 
143
 
112
144
 
113
145
def init():
114
146
    " init the system, be nice "
166
198
    upgrades = 0
167
199
    security_updates = 0
168
200
    esm_updates = 0
 
201
    disabled_esm_updates = 0
169
202
 
170
203
    # we need another cache that has more pkg details
171
204
    with apt.Cache() as aptcache:
172
205
        for pkg in cache.packages:
 
206
            if has_disabled_esm_security_update(depcache, pkg):
 
207
                disabled_esm_updates += 1
 
208
 
173
209
            # skip packages that are not marked upgraded/installed
174
210
            if not (depcache.marked_install(pkg)
175
211
                    or depcache.marked_upgrade(pkg)):
220
256
        write_package_names(sys.stderr, cache, depcache)
221
257
    elif options and options.readable_output:
222
258
        write_human_readable_summary(sys.stdout, upgrades, security_updates,
223
 
                                     esm_updates, have_esm)
 
259
                                     esm_updates, have_esm,
 
260
                                     disabled_esm_updates)
224
261
    else:
225
262
        # print the number of regular upgrades and the number of
226
263
        # security upgrades