#!/usr/bin/python # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # Copyright Red Hat Inc. 2010 # # Author: James Antill # Examples: # # yum --ttysz=60 blah | whatever # yum --ttysz=160 blah | whatever from yum.plugins import TYPE_INTERACTIVE import logging # for commands import urlgrabber.grabber import tempfile import os import shutil import time requires_api_version = '2.5' plugin_type = (TYPE_INTERACTIVE,) def config_hook(conduit): ''' Yum Plugin Config Hook: Add the --ttysz option. ''' parser = conduit.getOptParser() if not parser: return if hasattr(parser, 'plugin_option_group'): parser = parser.plugin_option_group parser.add_option("--ttysz", type='string', default=None, help="override the size for the tty", metavar='[size]') import urlgrabber.progress def prereposetup_hook(conduit): opts, args = conduit.getCmdLine() if opts.ttysz is None: return sz = opts.ttysz try: sz = int(sz) except: return def _override_terminal_width(fd=1, *args, **kwargs): return sz def _override_terminal_width_cached(fd=1, cache_timeout=1.000, *args, **kwargs): return sz urlgrabber.progress.terminal_width = _override_terminal_width urlgrabber.progress.terminal_width_cached = _override_terminal_width_cached