From: Mike Bayer Date: Thu, 21 Nov 2013 22:47:24 +0000 (-0500) Subject: Fixed the output wrapping for Alembic message output, so that X-Git-Tag: rel_0_6_1~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=66e957e45361a6f66622e067a3023a6ac41a321f;p=thirdparty%2Fsqlalchemy%2Falembic.git Fixed the output wrapping for Alembic message output, so that we either get the terminal width for "pretty printing" with indentation, or if not we just output the text as is; in any case the text won't be wrapped too short. #135 --- diff --git a/alembic/util.py b/alembic/util.py index a8750a2c..b9565480 100644 --- a/alembic/util.py +++ b/alembic/util.py @@ -30,10 +30,17 @@ if not sqla_07: from sqlalchemy.util import format_argspec_plus, update_wrapper from sqlalchemy.util.compat import inspect_getfullargspec + try: - width = int(os.environ['COLUMNS']) -except (KeyError, ValueError): - width = 80 + import fcntl + import termios + import struct + ioctl = fcntl.ioctl(0, termios.TIOCGWINSZ, + struct.pack('HHHH', 0, 0, 0, 0)) + _h, TERMWIDTH, _hp, _wp = struct.unpack('HHHH', ioctl) +except (ImportError, IOError): + TERMWIDTH = None + def template_to_file(template_file, dest, **kw): with open(dest, 'w') as f: @@ -171,11 +178,17 @@ def warn(msg): warnings.warn(msg) def msg(msg, newline=True): - lines = textwrap.wrap(msg, width) - if len(lines) > 1: - for line in lines[0:-1]: - write_outstream(sys.stdout, " ", line, "\n") - write_outstream(sys.stdout, " ", lines[-1], ("\n" if newline else "")) + if TERMWIDTH is None: + write_outstream(sys.stdout, msg) + if newline: + write_outstream(sys.stdout, "\n") + else: + # left indent output lines + lines = textwrap.wrap(msg, TERMWIDTH) + if len(lines) > 1: + for line in lines[0:-1]: + write_outstream(sys.stdout, " ", line, "\n") + write_outstream(sys.stdout, " ", lines[-1], ("\n" if newline else "")) def load_python_file(dir_, filename): """Load a file from the given path as a Python module.""" diff --git a/docs/build/changelog.rst b/docs/build/changelog.rst index 364bc840..96ed7830 100644 --- a/docs/build/changelog.rst +++ b/docs/build/changelog.rst @@ -7,6 +7,15 @@ Changelog :version: 0.6.1 :released: no release date + .. change:: + :tags: bug + :tickets: 135 + + Fixed the output wrapping for Alembic message output, so that + we either get the terminal width for "pretty printing" with + indentation, or if not we just output the text as is; in any + case the text won't be wrapped too short. + .. change:: :tags: bug :tickets: 145