diff options
author | nkozlovskiy <nmk@ydb.tech> | 2023-10-02 18:57:38 +0300 |
---|---|---|
committer | nkozlovskiy <nmk@ydb.tech> | 2023-10-02 19:39:06 +0300 |
commit | 6295ef4d23465c11296e898b9dc4524ad9592b5d (patch) | |
tree | fc0c852877b2c52f365a1f6ed0710955844338c2 /contrib/deprecated/python/backports.shutil-get-terminal-size | |
parent | de63c80b75948ecc13894854514d147840ff8430 (diff) | |
download | ydb-6295ef4d23465c11296e898b9dc4524ad9592b5d.tar.gz |
oss ydb: fix dstool building and test run
Diffstat (limited to 'contrib/deprecated/python/backports.shutil-get-terminal-size')
7 files changed, 220 insertions, 0 deletions
diff --git a/contrib/deprecated/python/backports.shutil-get-terminal-size/.dist-info/METADATA b/contrib/deprecated/python/backports.shutil-get-terminal-size/.dist-info/METADATA new file mode 100644 index 0000000000..6a1a0e9375 --- /dev/null +++ b/contrib/deprecated/python/backports.shutil-get-terminal-size/.dist-info/METADATA @@ -0,0 +1,44 @@ +Metadata-Version: 2.0 +Name: backports.shutil-get-terminal-size +Version: 1.0.0 +Summary: A backport of the get_terminal_size function from Python 3.3's shutil. +Home-page: https://github.com/chrippa/backports.shutil_get_terminal_size +Author: Christopher Rosell +Author-email: chrippa@tanuki.se +License: MIT +Platform: UNKNOWN +Classifier: Development Status :: 5 - Production/Stable +Classifier: License :: OSI Approved :: MIT License +Classifier: Programming Language :: Python :: 2.6 +Classifier: Programming Language :: Python :: 2.7 +Classifier: Programming Language :: Python :: 3.2 + +backports.shutil_get_terminal_size +================================== + +A backport of the `get_terminal_size`_ function from Python 3.3's shutil. + +Unlike the original version it is written in pure Python rather than C, +so it might be a tiny bit slower. + +.. _get_terminal_size: https://docs.python.org/3/library/shutil.html#shutil.get_terminal_size + + +Example usage +------------- + + >>> from backports.shutil_get_terminal_size import get_terminal_size + >>> get_terminal_size() + terminal_size(columns=105, lines=33) + + + +History +======= + +1.0.0 (2014-08-19) +------------------ + +First release. + + diff --git a/contrib/deprecated/python/backports.shutil-get-terminal-size/.dist-info/top_level.txt b/contrib/deprecated/python/backports.shutil-get-terminal-size/.dist-info/top_level.txt new file mode 100644 index 0000000000..99d2be5b64 --- /dev/null +++ b/contrib/deprecated/python/backports.shutil-get-terminal-size/.dist-info/top_level.txt @@ -0,0 +1 @@ +backports diff --git a/contrib/deprecated/python/backports.shutil-get-terminal-size/LICENSE b/contrib/deprecated/python/backports.shutil-get-terminal-size/LICENSE new file mode 100644 index 0000000000..d62803cf99 --- /dev/null +++ b/contrib/deprecated/python/backports.shutil-get-terminal-size/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2014 Christopher Rosell + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/contrib/deprecated/python/backports.shutil-get-terminal-size/README.rst b/contrib/deprecated/python/backports.shutil-get-terminal-size/README.rst new file mode 100644 index 0000000000..385127b52e --- /dev/null +++ b/contrib/deprecated/python/backports.shutil-get-terminal-size/README.rst @@ -0,0 +1,18 @@ +backports.shutil_get_terminal_size +================================== + +A backport of the `get_terminal_size`_ function from Python 3.3's shutil. + +Unlike the original version it is written in pure Python rather than C, +so it might be a tiny bit slower. + +.. _get_terminal_size: https://docs.python.org/3/library/shutil.html#shutil.get_terminal_size + + +Example usage +------------- + + >>> from backports.shutil_get_terminal_size import get_terminal_size + >>> get_terminal_size() + terminal_size(columns=105, lines=33) + diff --git a/contrib/deprecated/python/backports.shutil-get-terminal-size/backports/shutil_get_terminal_size/__init__.py b/contrib/deprecated/python/backports.shutil-get-terminal-size/backports/shutil_get_terminal_size/__init__.py new file mode 100644 index 0000000000..cfcbdf6671 --- /dev/null +++ b/contrib/deprecated/python/backports.shutil-get-terminal-size/backports/shutil_get_terminal_size/__init__.py @@ -0,0 +1,11 @@ +"""A backport of the get_terminal_size function from Python 3.3's shutil.""" + +__title__ = "backports.shutil_get_terminal_size" +__version__ = "1.0.0" +__license__ = "MIT" +__author__ = "Christopher Rosell" +__copyright__ = "Copyright 2014 Christopher Rosell" + +__all__ = ["get_terminal_size"] + +from .get_terminal_size import get_terminal_size diff --git a/contrib/deprecated/python/backports.shutil-get-terminal-size/backports/shutil_get_terminal_size/get_terminal_size.py b/contrib/deprecated/python/backports.shutil-get-terminal-size/backports/shutil_get_terminal_size/get_terminal_size.py new file mode 100644 index 0000000000..bbda2ba122 --- /dev/null +++ b/contrib/deprecated/python/backports.shutil-get-terminal-size/backports/shutil_get_terminal_size/get_terminal_size.py @@ -0,0 +1,101 @@ +"""This is a backport of shutil.get_terminal_size from Python 3.3. + +The original implementation is in C, but here we use the ctypes and +fcntl modules to create a pure Python version of os.get_terminal_size. +""" + +import os +import struct +import sys + +from collections import namedtuple + +__all__ = ["get_terminal_size"] + + +terminal_size = namedtuple("terminal_size", "columns lines") + +try: + from ctypes import windll, create_string_buffer + + _handles = { + 0: windll.kernel32.GetStdHandle(-10), + 1: windll.kernel32.GetStdHandle(-11), + 2: windll.kernel32.GetStdHandle(-12), + } + + def _get_terminal_size(fd): + columns = lines = 0 + + try: + handle = _handles[fd] + csbi = create_string_buffer(22) + res = windll.kernel32.GetConsoleScreenBufferInfo(handle, csbi) + if res: + res = struct.unpack("hhhhHhhhhhh", csbi.raw) + left, top, right, bottom = res[5:9] + columns = right - left + 1 + lines = bottom - top + 1 + except Exception: + pass + + return terminal_size(columns, lines) + +except (ImportError, OSError): + import fcntl + import termios + + def _get_terminal_size(fd): + try: + res = fcntl.ioctl(fd, termios.TIOCGWINSZ, b"\x00" * 4) + lines, columns = struct.unpack("hh", res) + except Exception: + columns = lines = 0 + + return terminal_size(columns, lines) + + +def get_terminal_size(fallback=(80, 24)): + """Get the size of the terminal window. + + For each of the two dimensions, the environment variable, COLUMNS + and LINES respectively, is checked. If the variable is defined and + the value is a positive integer, it is used. + + When COLUMNS or LINES is not defined, which is the common case, + the terminal connected to sys.__stdout__ is queried + by invoking os.get_terminal_size. + + If the terminal size cannot be successfully queried, either because + the system doesn't support querying, or because we are not + connected to a terminal, the value given in fallback parameter + is used. Fallback defaults to (80, 24) which is the default + size used by many terminal emulators. + + The value returned is a named tuple of type os.terminal_size. + """ + # Try the environment first + try: + columns = int(os.environ["COLUMNS"]) + except (KeyError, ValueError): + columns = 0 + + try: + lines = int(os.environ["LINES"]) + except (KeyError, ValueError): + lines = 0 + + # Only query if necessary + if columns <= 0 or lines <= 0: + try: + size = _get_terminal_size(sys.__stdout__.fileno()) + except (NameError, OSError): + size = terminal_size(*fallback) + + if columns <= 0: + columns = size.columns + if lines <= 0: + lines = size.lines + + return terminal_size(columns, lines) + diff --git a/contrib/deprecated/python/backports.shutil-get-terminal-size/ya.make b/contrib/deprecated/python/backports.shutil-get-terminal-size/ya.make new file mode 100644 index 0000000000..e9b60bde51 --- /dev/null +++ b/contrib/deprecated/python/backports.shutil-get-terminal-size/ya.make @@ -0,0 +1,23 @@ +# Generated by devtools/yamaker (pypi). + +PY2_LIBRARY() + +VERSION(1.0.0) + +LICENSE(MIT) + +NO_LINT() + +PY_SRCS( + TOP_LEVEL + backports/shutil_get_terminal_size/__init__.py + backports/shutil_get_terminal_size/get_terminal_size.py +) + +RESOURCE_FILES( + PREFIX contrib/deprecated/python/backports.shutil-get-terminal-size/ + .dist-info/METADATA + .dist-info/top_level.txt +) + +END() |