Rev 4754: Introduce BZR_COLUMNS since COLUMNS behaviour is too obscure. in file:///home/vila/src/bzr/bugs/353370-notty-no-term-width/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Wed Dec 2 16:15:28 GMT 2009
At file:///home/vila/src/bzr/bugs/353370-notty-no-term-width/
------------------------------------------------------------
revno: 4754
revision-id: v.ladeuil+lp at free.fr-20091202161528-aj805lahqb994qmr
parent: v.ladeuil+lp at free.fr-20091202152434-mvopr2s1p1j8nm93
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 353370-notty-no-term-width
timestamp: Wed 2009-12-02 17:15:28 +0100
message:
Introduce BZR_COLUMNS since COLUMNS behaviour is too obscure.
* bzrlib/tests/test_osutils.py:
(TestTerminalWidth): Update tests.
* bzrlib/tests/__init__.py:
(TestCase._cleanEnvironment): Add BZR_COLUMNS.
* bzrlib/osutils.py:
(terminal_width): BZR_COLUMNS is the official way to override.
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS 2009-12-02 15:24:34 +0000
+++ b/NEWS 2009-12-02 16:15:28 +0000
@@ -19,14 +19,20 @@
New Features
************
+* The ``BZR_COLUMNS`` envrionment variable can be set to force bzr to
+ respect a given terminal width. This can be useful when output is
+ redirected or in obscure cases where the default value is not
+ appropriate.
+ (Vincent Ladeuil)
+
Bug Fixes
*********
-* ``osutils.terminal_width()`` obeys the COLUMNS envrionment variable
- but returns None if the terminal is not a tty (when output is
+* ``osutils.terminal_width()`` obeys the BZR_COLUMNS envrionment
+ variable but returns None if the terminal is not a tty (when output is
redirected for example). Also fixes its usage under OSes that doesn't
- provide termios.TIOCGWINSZ.
- (Joke de Buhr, Vincent Ladeuil, #353370, #62539)
+ provide termios.TIOCGWINSZ.
+ (Joke de Buhr, Vincent Ladeuil, #353370, #62539)
Improvements
************
=== modified file 'bzrlib/help_topics/__init__.py'
--- a/bzrlib/help_topics/__init__.py 2009-10-13 20:15:45 +0000
+++ b/bzrlib/help_topics/__init__.py 2009-12-02 16:15:28 +0000
@@ -558,6 +558,7 @@
BZR_SSH SSH client: paramiko (default), openssh, ssh, plink.
BZR_LOG Location of .bzr.log (use '/dev/null' to suppress log).
BZR_LOG (Win32) Location of .bzr.log (use 'NUL' to suppress log).
+BZR_COLUMNS Override implicit terminal width.
================ =================================================================
"""
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py 2009-12-02 15:24:34 +0000
+++ b/bzrlib/osutils.py 2009-12-02 16:15:28 +0000
@@ -1308,7 +1308,13 @@
None is returned if the width can't established precisely.
"""
- # If the env var is set, take it, user is always right
+ # If BZR_COLUMNS is set, take it, user is always right
+ try:
+ return int(os.environ['BZR_COLUMNS'])
+ except (KeyError, ValueError):
+ pass
+
+ # If COLUMNS is set, take it, the terminal knows better
try:
return int(os.environ['COLUMNS'])
except (KeyError, ValueError):
@@ -1316,7 +1322,7 @@
isatty = getattr(sys.stdout, 'isatty', None)
if isatty is None or not isatty():
- # Don't guess, setting COLUMNS is the recommended way to override.
+ # Don't guess, setting BZR_COLUMNS is the recommended way to override.
return None
if sys.platform == 'win32':
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2009-12-02 15:24:34 +0000
+++ b/bzrlib/tests/__init__.py 2009-12-02 16:15:28 +0000
@@ -1552,6 +1552,7 @@
'TERM': 'dumb',
'LINES': '25',
'COLUMNS': '80',
+ 'BZR_COLUMNS': '80',
# SSH Agent
'SSH_AUTH_SOCK': None,
# Proxies
=== modified file 'bzrlib/tests/test_osutils.py'
--- a/bzrlib/tests/test_osutils.py 2009-12-02 15:24:34 +0000
+++ b/bzrlib/tests/test_osutils.py 2009-12-02 16:15:28 +0000
@@ -1888,13 +1888,19 @@
def test_default_values(self):
self.assertEquals(80, osutils.default_terminal_width)
- def test_defaults_to_COLUMNS(self):
- # COLUMNS is set by the test framework
- self.assertEquals('80', os.environ['COLUMNS'])
- os.environ['COLUMNS'] = '12'
+ def test_defaults_to_BZR_COLUMNS(self):
+ # BZR_COLUMNS is set by the test framework
+ self.assertEquals('80', os.environ['BZR_COLUMNS'])
+ os.environ['BZR_COLUMNS'] = '12'
self.assertEquals(12, osutils.terminal_width())
+ def test_falls_back_to_COLUMNS(self):
+ del os.environ['BZR_COLUMNS']
+ os.environ['COLUMNS'] = '42'
+ self.assertEquals(42, osutils.terminal_width())
+
def test_tty_default_without_columns(self):
+ del os.environ['BZR_COLUMNS']
del os.environ['COLUMNS']
orig_stdout = sys.stdout
def restore():
@@ -1909,6 +1915,7 @@
self.assertEquals(None, osutils.terminal_width())
def test_non_tty_default_without_columns(self):
+ del os.environ['BZR_COLUMNS']
del os.environ['COLUMNS']
orig_stdout = sys.stdout
def restore():
@@ -1931,5 +1938,6 @@
self.addCleanup(restore)
del termios.TIOCGWINSZ
+ del os.environ['BZR_COLUMNS']
del os.environ['COLUMNS']
self.assertEquals(None, osutils.terminal_width())
More information about the bazaar-commits
mailing list