Merge lp://qastaging/~frankban/juju-quickstart/check-locale into lp://qastaging/juju-quickstart
Status: | Merged |
---|---|
Merged at revision: | 67 |
Proposed branch: | lp://qastaging/~frankban/juju-quickstart/check-locale |
Merge into: | lp://qastaging/juju-quickstart |
Diff against target: |
98 lines (+55/-0) 2 files modified
quickstart/cli/base.py (+20/-0) quickstart/tests/cli/test_base.py (+35/-0) |
To merge this branch: | bzr merge lp://qastaging/~frankban/juju-quickstart/check-locale |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju GUI Hackers | Pending | ||
Review via email: mp+217067@code.qastaging.launchpad.net |
Description of the change
Check unicode support.
Ensure utf-8 is supported before starting
the Urwid interactive session.
This way we hope to avoid bad crashes
when the user has locale configuration problems.
Tests: `make check`.
QA:
If you have juju-quickstart installed, you should
be able to make it crash by overriding all the language
env vars, like the following:
`LC_ALL=C juju-quickstart -i`
You should see a UnicodeEncodeError:
'ascii' codec can't encode character u'\u2582' in position 0:
ordinal not in range(128)
With this branch, the following should instead work as usual:
`LC_ALL=C .venv/bin/python juju-quickstart -i`.
I am not sure how to make Urwid fail so that we can QA
the system exit in the code, but at least that code path
is tested.
Reviewers: mp+217067_ code.launchpad. net,
Message:
Please take a look.
Description:
Check unicode support.
Ensure utf-8 is supported before starting
the Urwid interactive session.
This way we hope to avoid bad crashes
when the user has locale configuration problems.
Tests: `make check`.
QA:
If you have juju-quickstart installed, you should
be able to make it crash by overriding all the language
env vars, like the following:
`LC_ALL=C juju-quickstart -i`
You should see a UnicodeEncodeError:
'ascii' codec can't encode character u'\u2582' in position 0:
ordinal not in range(128)
With this branch, the following should instead work as usual:
`LC_ALL=C .venv/bin/python juju-quickstart -i`.
I am not sure how to make Urwid fail so that we can QA
the system exit in the code, but at least that code path
is tested.
https:/ /code.launchpad .net/~frankban/ juju-quickstart /check- locale/ +merge/ 217067
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/90740043/
Affected files (+57, -0 lines): cli/base. py tests/cli/ test_base. py
A [revision details]
M quickstart/
M quickstart/
Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision:
<email address hidden>
Index: quickstart/ cli/base. py cli/base. py' cli/base. py 2014-01-03 10:22:24 +0000 cli/base. py 2014-04-24 14:47:18 +0000
=== modified file 'quickstart/
--- quickstart/
+++ quickstart/
@@ -26,6 +26,7 @@
from __future__ import unicode_literals
from collections import namedtuple
+import sys
import urwid
@@ -44,6 +45,24 @@
)
+def _check_encoding(): encoding( 'utf-8' ) unicode( ): msg.encode( 'ascii' )) urwid.MainLoop) :
+ """Set the Urwid global byte encoding to utf-8.
+
+ Exit the application if, for some reasons, the change does not have
effect.
+ """
+ urwid.set_
+ if not urwid.supports_
+ # Note: the following message must only include ASCII characters.
+ msg = (
+ 'Error: your terminal does not seem to support UTF-8
encoding.\n'
+ 'Please check your locale settings.\n'
+ 'On Ubuntu, running the following might fix the problem:\n'
+ ' sudo locale-gen en_US.UTF-8\n'
+ ' sudo dpkg-reconfigure locales'
+ )
+ sys.exit(
+
+
class _MainLoop(
"""A customized Urwid loop.
@@ -109,6 +128,7 @@ cli.views module '\npreparing. ..') '\N{LOWER ONE QUARTER BLOCK}')
with the exit shortcut. See the quickstart.
docstring
for more information about this functionality.
"""
+ _check_encoding()
# Set up the application header.
title = urwid.Text(
header_line = urwid.Divider(
Index: quickstart/ tests/cli/ test_base. py tests/cli/ test_base. py' tests/cli/ test_base. py 2014-01-03 10:22:24 +0000 tests/cli/ test_base. py 2014-04-24 14:49:16 +0000
=== modified file 'quickstart/
--- quickstart/
+++ quickstart/
@@ -18,14 +18,49 @@
from __future__ import unicode_literals
+from context...