From f5238fc47b0b677e289b5c78bb765cf88a7eff24 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 20 Mar 2011 14:11:32 -0400 Subject: [PATCH] many fixes --- clint/__init__.py | 10 ++++++---- clint/textui/core.py | 16 ++++++---------- clint/textui/progress.py | 18 ++++++++++++++++++ clint/utils.py | 20 -------------------- setup.py | 5 ++++- 5 files changed, 34 insertions(+), 35 deletions(-) create mode 100644 clint/textui/progress.py diff --git a/clint/__init__.py b/clint/__init__.py index 78057ec..1bb0b48 100644 --- a/clint/__init__.py +++ b/clint/__init__.py @@ -1,7 +1,9 @@ -from . import arguments -from . import textui -from . import utils -from .pipes import piped_in +# -*- coding: utf-8 -*- + +import arguments +import textui +import utils +from pipes import piped_in __title__ = 'clint' diff --git a/clint/textui/core.py b/clint/textui/core.py index 84f2a9c..9bbf58d 100644 --- a/clint/textui/core.py +++ b/clint/textui/core.py @@ -1,15 +1,17 @@ # -*- coding: utf-8 -*- """ -x +clint.textui.core +~~~~~~~~~~~~~~~~~ """ import sys -from contextlib import contextmanager + +from progress import progressbar -__all__ = ('puts', 'puts_err', 'indent', 'maxwidth') +__all__ = ('puts', 'puts_err', 'indent', 'progressbar') STDOUT = sys.stdout.write @@ -52,7 +54,7 @@ class Writer(object): '\n' if newline else '' )) stream(_str) - + def puts(s, newline=True): """Prints given string to stdout via Writer interface.""" @@ -67,9 +69,3 @@ def puts_err(s, newline=True): def indent(indent=4, quote=''): """Indentation context manager""" return Writer(indent=indent, quote=quote) - - -@contextmanager -def maxwidth(x=None): - # if none, detect from applib - print x \ No newline at end of file diff --git a/clint/textui/progress.py b/clint/textui/progress.py new file mode 100644 index 0000000..654d8b2 --- /dev/null +++ b/clint/textui/progress.py @@ -0,0 +1,18 @@ +import sys + +def progressbar(it, prefix='', size=32, hide=False): + count = len(it) + if count: + def _show(_i): + x = int(size*_i/count) + if not hide: + sys.stdout.write("%s[%s>%s] %i/%i\r" % (prefix, "="*x, "-"*(size-x), _i, count)) + sys.stdout.flush() + + _show(0) + for i, item in enumerate(it): + yield item + _show(i+1) + if not hide: + sys.stdout.write("\n") + sys.stdout.flush() diff --git a/clint/utils.py b/clint/utils.py index dec1a67..dd779ed 100644 --- a/clint/utils.py +++ b/clint/utils.py @@ -4,26 +4,6 @@ import sys import errno from os import makedirs - - -def progressbar(it, prefix='', size=32, hide=False): - count = len(it) - if count: - def _show(_i): - x = int(size*_i/count) - if not hide: - sys.stdout.write("%s[%s>%s] %i/%i\r" % (prefix, "="*x, "-"*(size-x), _i, count)) - sys.stdout.flush() - - _show(0) - for i, item in enumerate(it): - yield item - _show(i+1) - if not hide: - sys.stdout.write("\n") - sys.stdout.flush() - - def is_collection(obj): """Tests if an object is a collection""" diff --git a/setup.py b/setup.py index f6a4d0e..22eb3f8 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,10 @@ setup( author_email='me@kennethreitz.com', url='https://github.com/kennethreitz/clint', packages= [ - 'clint', 'clint.packages', 'clint.packages.colorama' + 'clint', + 'clint.textui', + + 'clint.packages', 'clint.packages.colorama' ], install_requires=required, license='ISC',