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
=== modified file 'DistUpgrade/DistUpgradeViewText.py'
--- DistUpgrade/DistUpgradeViewText.py 2012-12-13 16:42:43 +0000
+++ DistUpgrade/DistUpgradeViewText.py 2014-04-08 08:32:01 +0000
@@ -41,6 +41,14 @@
41from .utils import twrap41from .utils import twrap
4242
4343
44def readline():
45 """ py2/py3 compatible readline from stdin """
46 s = sys.stdin.readline()
47 if hasattr(s, "decode"):
48 return s.decode(ENCODING, "backslashreplace")
49 return s
50
51
44class TextAcquireProgress(AcquireProgress, apt.progress.text.AcquireProgress):52class TextAcquireProgress(AcquireProgress, apt.progress.text.AcquireProgress):
45 def __init__(self):53 def __init__(self):
46 apt.progress.text.AcquireProgress.__init__(self)54 apt.progress.text.AcquireProgress.__init__(self)
@@ -135,7 +143,7 @@
135 if extended_msg:143 if extended_msg:
136 print(twrap(extended_msg))144 print(twrap(extended_msg))
137 print(_("To continue please press [ENTER]"))145 print(_("To continue please press [ENTER]"))
138 sys.stdin.readline().decode(ENCODING, "backslashreplace")146 readline()
139 def error(self, summary, msg, extended_msg=None):147 def error(self, summary, msg, extended_msg=None):
140 print()148 print()
141 print(twrap(summary))149 print(twrap(summary))
@@ -169,7 +177,7 @@
169 print(" %s %s" % (_("Continue [yN] "), _("Details [d]")), end="")177 print(" %s %s" % (_("Continue [yN] "), _("Details [d]")), end="")
170 sys.stdout.flush()178 sys.stdout.flush()
171 while True:179 while True:
172 res = sys.stdin.readline().decode(ENCODING, "backslashreplace")180 res = readline()
173 # TRANSLATORS: the "y" is "yes"181 # TRANSLATORS: the "y" is "yes"
174 if res.strip().lower().startswith(_("y")):182 if res.strip().lower().startswith(_("y")):
175 return True183 return True
@@ -213,14 +221,14 @@
213 print(twrap(msg))221 print(twrap(msg))
214 if default == 'No':222 if default == 'No':
215 print(_("Continue [yN] "), end="")223 print(_("Continue [yN] "), end="")
216 res = sys.stdin.readline().decode(ENCODING, "backslashreplace")224 res = readline()
217 # TRANSLATORS: first letter of a positive (yes) answer225 # TRANSLATORS: first letter of a positive (yes) answer
218 if res.strip().lower().startswith(_("y")):226 if res.strip().lower().startswith(_("y")):
219 return True227 return True
220 return False228 return False
221 else:229 else:
222 print(_("Continue [Yn] "), end="")230 print(_("Continue [Yn] "), end="")
223 res = sys.stdin.readline().decode(ENCODING, "backslashreplace")231 res = readline()
224 # TRANSLATORS: first letter of a negative (no) answer232 # TRANSLATORS: first letter of a negative (no) answer
225 if res.strip().lower().startswith(_("n")):233 if res.strip().lower().startswith(_("n")):
226 return False234 return False
227235
=== modified file 'do-partial-upgrade'
--- do-partial-upgrade 2012-06-28 19:22:04 +0000
+++ do-partial-upgrade 2014-04-08 08:32:01 +0000
@@ -25,15 +25,16 @@
2525
26from __future__ import print_function26from __future__ import print_function
2727
28from gi.repository import Gtk
29import gi
30gi.require_version("Gtk", "3.0")
31
32import os28import os
33import sys29import sys
3430
35from DistUpgrade.DistUpgradeVersion import VERSION31from DistUpgrade.DistUpgradeVersion import VERSION
36from DistUpgrade.DistUpgradeController import DistUpgradeController32from DistUpgrade.DistUpgradeController import DistUpgradeController
33from DistUpgrade.DistUpgradeConfigParser import DistUpgradeConfig
34from DistUpgrade.DistUpgradeMain import (
35 setup_logging,
36 setup_view,
37)
37import locale38import locale
38import gettext39import gettext
3940
@@ -41,9 +42,6 @@
4142
42if __name__ == "__main__":43if __name__ == "__main__":
4344
44 Gtk.init_check(sys.argv)
45 Gtk.Window.set_default_icon_name("system-software-update")
46
47 #FIXME: Workaround a bug in optparser which doesn't handle unicode/str45 #FIXME: Workaround a bug in optparser which doesn't handle unicode/str
48 # correctly, see http://bugs.python.org/issue439146 # correctly, see http://bugs.python.org/issue4391
49 # Should be resolved by Python347 # Should be resolved by Python3
@@ -60,33 +58,48 @@
60 except:58 except:
61 pass59 pass
6260
61 # gtk2 used to throw a exception when it failed to init the display,
62 # so back then it was safe to try to import the frontend and fallback
63 # to text if the import failed. this is no longer the case so we need
64 # do figure it out here :/
65 if "DISPLAY" in os.environ:
66 default_frontend = "DistUpgradeViewGtk3"
67 else:
68 default_frontend = "DistUpgradeViewText"
69
63 # Begin parsing of options70 # Begin parsing of options
64 parser = OptionParser()71 parser = OptionParser()
65 parser.add_option ("-V", "--version", action="store_true",72 parser.add_option ("-V", "--version", action="store_true",
66 dest="show_version", default=False,73 dest="show_version", default=False,
67 help=_("Show version and exit"))74 help=_("Show version and exit"))
68 parser.add_option ("--data-dir", "", 75 parser.add_option ("--data-dir", "", dest="datadir",
69 default="/usr/share/ubuntu-release-upgrader/",76 default="/usr/share/ubuntu-release-upgrader/",
70 help=_("Directory that contains the data files"))77 help=_("Directory that contains the data files"))
71 parser.add_option ("-f", "--frontend", default="DistUpgradeViewText",78 parser.add_option ("-f", "--frontend", default=default_frontend,
72 dest="frontend", 79 dest="frontend",
73 help=_("Run the specified frontend"))80 help=_("Run the specified frontend"))
7481
75 (options, args) = parser.parse_args()82 (options, args) = parser.parse_args()
7683
77 data_dir = os.path.normpath(options.data_dir)+"/"84 datadir = os.path.normpath(options.datadir)+"/"
7885
79 if options.show_version:86 if options.show_version:
80 print("%s: version %s" % (os.path.basename(sys.argv[0]), VERSION))87 print("%s: version %s" % (os.path.basename(sys.argv[0]), VERSION))
81 sys.exit(0)88 sys.exit(0)
8289
83 module_name = "DistUpgrade." + options.frontend90 # we are by definition in partial upgrade mode
84 module = __import__(module_name)91 options.partial = True
85 submodule = getattr(module, options.frontend)92 config = DistUpgradeConfig(options.datadir)
86 view_class = getattr(submodule, options.frontend)93 logdir = setup_logging(options, config)
87 view = view_class(data_dir)94 view = setup_view(options, config, logdir)
95
88 if options.frontend == "DistUpgradeViewGtk3":96 if options.frontend == "DistUpgradeViewGtk3":
97 from gi.repository import Gtk
98 import gi
99 gi.require_version("Gtk", "3.0")
100 Gtk.init_check(sys.argv)
101 Gtk.Window.set_default_icon_name("system-software-update")
89 view.label_title.set_markup("<b><big>%s</big></b>" %102 view.label_title.set_markup("<b><big>%s</big></b>" %
90 _("Running partial upgrade"))103 _("Running partial upgrade"))
91 controller = DistUpgradeController(view, datadir=data_dir)104 controller = DistUpgradeController(view, datadir=datadir)
92 controller.doPartialUpgrade()105 controller.doPartialUpgrade()

Subscribers

People subscribed via source and target branches