Merge lp:~vorlon/update-manager/ubuntu-support-optimize into lp:update-manager

Proposed by Steve Langasek on 2017-04-28
Status: Merged
Merged at revision: 2762
Proposed branch: lp:~vorlon/update-manager/ubuntu-support-optimize
Merge into: lp:update-manager
Diff against target: 135 lines (+45/-24)
3 files modified
debian/changelog (+9/-0)
debian/control (+1/-0)
ubuntu-support-status (+35/-24)
To merge this branch: bzr merge lp:~vorlon/update-manager/ubuntu-support-optimize
Reviewer Review Type Date Requested Status
Brian Murray 2017-04-28 Approve on 2017-04-28
Review via email: mp+323363@code.launchpad.net
To post a comment you must log in.
Brian Murray (brian-murray) wrote :

I'd guess this is going into artful in which case you'd want the version number to be 1:17.10.1. I've added some comments in-line.

Is there something that calls ubuntu-support-staus? If it used regularly then maybe the release_date should be cached somewhere.

review: Needs Fixing
Steve Langasek (vorlon) wrote :

> Is there something that calls ubuntu-support-status? If it used regularly then
> maybe the release_date should be cached somewhere.

It is not, this is an admin-facing tool. I don't think we need to cache anything beyond just leveraging distro-data; reading the csv file once per invocation is cheap (especially when compared to looking up a releases file once per package!).

Brian Murray (brian-murray) wrote :

Okay, I was thinking about hwe-support-status which is used by update-notifier.

2764. By Steve Langasek on 2017-04-28

sort(ish) the imports

2765. By Steve Langasek on 2017-04-28

in all cases where we can't find a valid Ubuntu release date, throw an error

2766. By Steve Langasek on 2017-04-28

fix changelog version

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2017-03-14 21:51:43 +0000
3+++ debian/changelog 2017-04-28 18:30:36 +0000
4@@ -1,3 +1,12 @@
5+update-manager (1:17.10.1) UNRELEASED; urgency=medium
6+
7+ * ubuntu-support-status: instead of checking the Release timestamp in
8+ the releases file for every single package on the system, get the
9+ release date from distro-info-data because it will always be the same.
10+ This speeds up the script by > 50% in testing.
11+
12+ -- Steve Langasek <steve.langasek@ubuntu.com> Thu, 27 Apr 2017 23:38:05 -0700
13+
14 update-manager (1:17.04.3) zesty; urgency=medium
15
16 * Use a 64 bit integer for launch-time instead of a 32 bit one which won't
17
18=== modified file 'debian/control'
19--- debian/control 2017-03-14 20:46:06 +0000
20+++ debian/control 2017-04-28 18:30:36 +0000
21@@ -24,6 +24,7 @@
22 ${misc:Depends},
23 python3-update-manager (= ${source:Version}),
24 python3-distro-info,
25+ distro-info-data,
26 lsb-release,
27 ubuntu-release-upgrader-core
28 Recommends: libpam-modules (>= 1.0.1-9ubuntu3)
29
30=== modified file 'ubuntu-support-status'
31--- ubuntu-support-status 2016-07-21 20:30:51 +0000
32+++ ubuntu-support-status 2017-04-28 18:30:36 +0000
33@@ -3,25 +3,46 @@
34 from __future__ import print_function
35
36 import apt
37+import csv
38 import locale
39 import datetime
40 import operator
41 import os
42 import subprocess
43+import time
44 import gettext
45 import sys
46
47 from apt.utils import (
48 get_maintenance_end_date,
49- get_release_date_from_release_file,
50- get_release_filename_for_pkg,
51 )
52 from optparse import OptionParser
53 from UpdateManager.Core.utils import twrap, get_dist
54
55 CODENAME = get_dist()
56
57-def get_maintenance_status(cache, pkgname, supported_tag):
58+def get_release_date(dist):
59+ distro_data = '/usr/share/distro-info/ubuntu.csv'
60+ release_date = None
61+ try:
62+ with open(distro_data) as csvfile:
63+ csv_reader = csv.DictReader(csvfile)
64+ for row in csv_reader:
65+ if row['series'] == CODENAME:
66+ release_date = row['release']
67+ break
68+ except FileNotFoundError:
69+ return None
70+
71+ if not release_date:
72+ return None
73+
74+ time_t = time.mktime(time.strptime(release_date, '%Y-%m-%d'))
75+ release_date = datetime.datetime.fromtimestamp(time_t)
76+ return release_date
77+
78+
79+def get_maintenance_status(supported_tag, release_date):
80 if supported_tag.endswith("y"):
81 supported_for_n_month = 12*int(supported_tag.rstrip("y"))
82 elif supported_tag.endswith("m"):
83@@ -29,25 +50,6 @@
84 else:
85 raise Exception("Unsupported tag '%s'" % supported_tag)
86
87- # try to figure out the support dates of the release and make
88- # sure to look only for stuff in "Ubuntu" and "distro_codename"
89- # (to exclude stuff in ubuntu-updates for the support time
90- # calculation because the "Release" file time for that gets
91- # updated regularly)
92- for suite in ["", "-updates", "-proposed", "-security"]:
93- releasef = get_release_filename_for_pkg(cache, pkgname,
94- "Ubuntu", CODENAME+suite)
95- if releasef:
96- break
97- else:
98- raise Exception("No Release file found for %s" % pkgname)
99-
100- time_t = get_release_date_from_release_file(releasef)
101- # check the release date and show support information
102- # based on this
103- if not time_t:
104- raise Exception("No date tag found")
105- release_date = datetime.datetime.fromtimestamp(time_t)
106 now = datetime.datetime.now()
107
108 # mvo: we do not define the end date very precisely
109@@ -116,6 +118,15 @@
110 # total count, for statistics
111 total = 0
112
113+ release_date = None
114+
115+ if CODENAME != 'unknown distribution':
116+ release_date = get_release_date(CODENAME)
117+
118+ if not release_date:
119+ print ("No valid Ubuntu release found, support status unknown")
120+ sys.exit(1)
121+
122 # analyze
123 with apt.Cache() as cache:
124 for pkg in cache:
125@@ -129,8 +140,8 @@
126 continue
127 # get support time
128 support_tag = pkg.candidate.record["Supported"]
129- (still_supported, support_str) = get_maintenance_status(cache,
130- pkg.name, support_tag)
131+ (still_supported, support_str) = get_maintenance_status(
132+ support_tag, release_date)
133 if not still_supported:
134 unsupported.add(pkg.name)
135 continue

Subscribers

People subscribed via source and target branches

to status/vote changes: