Merge lp:~mvo/ubuntu-release-upgrader/partial-upgrade-cleanup into lp:ubuntu-release-upgrader

Proposed by Michael Vogt
Status: Merged
Merge reported by: Iain Lane
Merged at revision: not available
Proposed branch: lp:~mvo/ubuntu-release-upgrader/partial-upgrade-cleanup
Merge into: lp:ubuntu-release-upgrader
Diff against target: 146 lines (+41/-20)
2 files modified
DistUpgrade/DistUpgradeViewText.py (+12/-4)
do-partial-upgrade (+29/-16)
To merge this branch: bzr merge lp:~mvo/ubuntu-release-upgrader/partial-upgrade-cleanup
Reviewer Review Type Date Requested Status
Brian Murray Approve
Ubuntu Core Development Team Pending
Review via email: mp+214685@code.launchpad.net

Description of the change

This branch fixes:
- a crash when the DistUpgradeViewText is used with py3
- fixes a bug with the logging setup (LP: #1302380) (thanks for the fix to Brian Murray and https://code.launchpad.net/~brian-murray/ubuntu-release-upgrader/bug-1302380/+merge/214349)
- fixes a crash when do-partial-upgrade is used without a DISPLAY

To post a comment you must log in.
Revision history for this message
Brian Murray (brian-murray) wrote :

It looks to me like the readline change with fix bug 1243619.

Revision history for this message
Brian Murray (brian-murray) wrote :

This looks good to me, but I reference bug 1243619 if it is in fact fixed by the readline changes.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'DistUpgrade/DistUpgradeViewText.py'
2--- DistUpgrade/DistUpgradeViewText.py 2012-12-13 16:42:43 +0000
3+++ DistUpgrade/DistUpgradeViewText.py 2014-04-08 08:32:01 +0000
4@@ -41,6 +41,14 @@
5 from .utils import twrap
6
7
8+def readline():
9+ """ py2/py3 compatible readline from stdin """
10+ s = sys.stdin.readline()
11+ if hasattr(s, "decode"):
12+ return s.decode(ENCODING, "backslashreplace")
13+ return s
14+
15+
16 class TextAcquireProgress(AcquireProgress, apt.progress.text.AcquireProgress):
17 def __init__(self):
18 apt.progress.text.AcquireProgress.__init__(self)
19@@ -135,7 +143,7 @@
20 if extended_msg:
21 print(twrap(extended_msg))
22 print(_("To continue please press [ENTER]"))
23- sys.stdin.readline().decode(ENCODING, "backslashreplace")
24+ readline()
25 def error(self, summary, msg, extended_msg=None):
26 print()
27 print(twrap(summary))
28@@ -169,7 +177,7 @@
29 print(" %s %s" % (_("Continue [yN] "), _("Details [d]")), end="")
30 sys.stdout.flush()
31 while True:
32- res = sys.stdin.readline().decode(ENCODING, "backslashreplace")
33+ res = readline()
34 # TRANSLATORS: the "y" is "yes"
35 if res.strip().lower().startswith(_("y")):
36 return True
37@@ -213,14 +221,14 @@
38 print(twrap(msg))
39 if default == 'No':
40 print(_("Continue [yN] "), end="")
41- res = sys.stdin.readline().decode(ENCODING, "backslashreplace")
42+ res = readline()
43 # TRANSLATORS: first letter of a positive (yes) answer
44 if res.strip().lower().startswith(_("y")):
45 return True
46 return False
47 else:
48 print(_("Continue [Yn] "), end="")
49- res = sys.stdin.readline().decode(ENCODING, "backslashreplace")
50+ res = readline()
51 # TRANSLATORS: first letter of a negative (no) answer
52 if res.strip().lower().startswith(_("n")):
53 return False
54
55=== modified file 'do-partial-upgrade'
56--- do-partial-upgrade 2012-06-28 19:22:04 +0000
57+++ do-partial-upgrade 2014-04-08 08:32:01 +0000
58@@ -25,15 +25,16 @@
59
60 from __future__ import print_function
61
62-from gi.repository import Gtk
63-import gi
64-gi.require_version("Gtk", "3.0")
65-
66 import os
67 import sys
68
69 from DistUpgrade.DistUpgradeVersion import VERSION
70 from DistUpgrade.DistUpgradeController import DistUpgradeController
71+from DistUpgrade.DistUpgradeConfigParser import DistUpgradeConfig
72+from DistUpgrade.DistUpgradeMain import (
73+ setup_logging,
74+ setup_view,
75+)
76 import locale
77 import gettext
78
79@@ -41,9 +42,6 @@
80
81 if __name__ == "__main__":
82
83- Gtk.init_check(sys.argv)
84- Gtk.Window.set_default_icon_name("system-software-update")
85-
86 #FIXME: Workaround a bug in optparser which doesn't handle unicode/str
87 # correctly, see http://bugs.python.org/issue4391
88 # Should be resolved by Python3
89@@ -60,33 +58,48 @@
90 except:
91 pass
92
93+ # gtk2 used to throw a exception when it failed to init the display,
94+ # so back then it was safe to try to import the frontend and fallback
95+ # to text if the import failed. this is no longer the case so we need
96+ # do figure it out here :/
97+ if "DISPLAY" in os.environ:
98+ default_frontend = "DistUpgradeViewGtk3"
99+ else:
100+ default_frontend = "DistUpgradeViewText"
101+
102 # Begin parsing of options
103 parser = OptionParser()
104 parser.add_option ("-V", "--version", action="store_true",
105 dest="show_version", default=False,
106 help=_("Show version and exit"))
107- parser.add_option ("--data-dir", "",
108+ parser.add_option ("--data-dir", "", dest="datadir",
109 default="/usr/share/ubuntu-release-upgrader/",
110 help=_("Directory that contains the data files"))
111- parser.add_option ("-f", "--frontend", default="DistUpgradeViewText",
112+ parser.add_option ("-f", "--frontend", default=default_frontend,
113 dest="frontend",
114 help=_("Run the specified frontend"))
115
116 (options, args) = parser.parse_args()
117
118- data_dir = os.path.normpath(options.data_dir)+"/"
119+ datadir = os.path.normpath(options.datadir)+"/"
120
121 if options.show_version:
122 print("%s: version %s" % (os.path.basename(sys.argv[0]), VERSION))
123 sys.exit(0)
124
125- module_name = "DistUpgrade." + options.frontend
126- module = __import__(module_name)
127- submodule = getattr(module, options.frontend)
128- view_class = getattr(submodule, options.frontend)
129- view = view_class(data_dir)
130+ # we are by definition in partial upgrade mode
131+ options.partial = True
132+ config = DistUpgradeConfig(options.datadir)
133+ logdir = setup_logging(options, config)
134+ view = setup_view(options, config, logdir)
135+
136 if options.frontend == "DistUpgradeViewGtk3":
137+ from gi.repository import Gtk
138+ import gi
139+ gi.require_version("Gtk", "3.0")
140+ Gtk.init_check(sys.argv)
141+ Gtk.Window.set_default_icon_name("system-software-update")
142 view.label_title.set_markup("<b><big>%s</big></b>" %
143 _("Running partial upgrade"))
144- controller = DistUpgradeController(view, datadir=data_dir)
145+ controller = DistUpgradeController(view, datadir=datadir)
146 controller.doPartialUpgrade()

Subscribers

People subscribed via source and target branches