14 Commits

Author SHA1 Message Date
Kenneth Reitz dbb063840a v0.3.0 2012-01-05 22:14:33 -05:00
Thomas Kluyver 9a4705f090 Update trove classifiers. 2012-01-06 00:16:14 +00:00
Thomas Kluyver b16b2ce723 All examples work on Python 3. 2012-01-06 00:11:51 +00:00
Thomas Kluyver 1ea4c5afdc Installable on Python 3. 2012-01-05 23:24:25 +00:00
Kenneth Reitz 39bb08253f Merge pull request #20 from robbles/develop
fix mismatch with argument names for progress.bar
2011-12-24 23:01:49 -08:00
Kenneth Reitz 8e6973253f Update clint/textui/progress.py 2011-10-28 13:04:31 -03:00
robbles 84419f6bfb fix mismatch with argument names for progress.bar 2011-09-28 11:13:26 -07:00
Kenneth Reitz 7b6138eda6 v0.2.5 2011-09-24 14:36:30 -04:00
Kenneth Reitz d19650b93c add userpath and environ var expansion to expand_path 2011-09-24 14:33:13 -04:00
Kenneth Reitz 98edec43e9 move expand_path to utils 2011-09-24 14:32:47 -04:00
Kenneth Reitz ef48a47b8d Merge branch 'master' into develop 2011-09-24 14:30:05 -04:00
Kenneth Reitz 3be47add4a rename arguments for bar 2011-08-12 09:48:24 -04:00
Kenneth Reitz bf99084ece Merge pull request #18 from maraujop/develop
Adding kwargs to progress bar, so that bar chars can be customized
2011-08-12 06:46:42 -07:00
Miguel Araujo Perez 705cda4443 Adding kwargs to progress bar, so that bar_empty_char and bar_filled_char can be easily customized. 2011-08-11 16:19:48 +02:00
16 changed files with 114 additions and 76 deletions
+1
View File
@@ -2,3 +2,4 @@
MANIFEST
*.pyc
.tox
build/
+3 -1
View File
@@ -14,4 +14,6 @@ Patches and Suggestions
- Morgan Goose
- Travis Swicegood
- Will Thames
- Greg Haskins
- Greg Haskins
- Miguel Araujo <maraujop>
- takluyver
+5
View File
@@ -1,6 +1,11 @@
History
-------
0.3.0
+++++
* Python 3 support!
0.2.4
+++++
+3 -3
View File
@@ -19,11 +19,11 @@ from .pipes import piped_in
__title__ = 'clint'
__version__ = '0.2.4'
__build__ = 0x000204
__version__ = '0.3.0'
__build__ = 0x000300
__author__ = 'Kenneth Reitz'
__license__ = 'ISC'
__copyright__ = 'Copyright 2011 Kenneth Reitz'
__copyright__ = 'Copyright 2012 Kenneth Reitz'
__docformat__ = 'restructuredtext'
+22 -38
View File
@@ -13,33 +13,17 @@ from __future__ import absolute_import
import os
from sys import argv
from glob import glob
from .packages.ordereddict import OrderedDict
from .utils import is_collection
try:
from collections import OrderedDict
except ImportError:
from .packages.ordereddict import OrderedDict
from .utils import expand_path, is_collection
__all__ = ('Args', )
def _expand_path(path):
"""Expands directories and globs in given path."""
paths = []
if os.path.isdir(path):
for (dir, dirs, files) in os.walk(path):
for file in files:
paths.append(os.path.join(dir, file))
else:
paths.extend(glob(path))
return paths
class Args(object):
"""CLI Argument management."""
@@ -110,20 +94,20 @@ class Args(object):
def any_contain(self, x):
"""Tests if given string is contained in any stored argument."""
return bool(self.first_with(x))
def contains(self, x):
"""Tests if given object is in arguments list.
"""Tests if given object is in arguments list.
Accepts strings and lists of strings."""
return self.__contains__(x)
def first(self, x):
"""Returns first found index of given value (or list of values)"""
def _find( x):
try:
return self.all.index(str(x))
@@ -212,7 +196,7 @@ class Args(object):
return False
else:
return (x in self.all[index])
except IndexError:
return False
@@ -221,7 +205,7 @@ class Args(object):
"""Returns true if argument exists at given index.
Accepts: integer.
"""
try:
self.all[x]
return True
@@ -231,15 +215,15 @@ class Args(object):
def value_after(self, x):
"""Returns value of argument after given found argument (or list thereof)."""
try:
try:
i = self.all.index(x)
except ValueError:
return None
return self.all[i + 1]
except IndexError:
return None
@@ -266,21 +250,21 @@ class Args(object):
return collection
@property
def last(self):
"""Returns last argument."""
try:
return self.all[-1]
except IndexError:
return None
@property
def all(self):
"""Returns all arguments."""
return self._args
@@ -288,7 +272,7 @@ class Args(object):
"""Returns all arguments containing given string (or list thereof)"""
_args = []
for arg in self.all:
if is_collection(x):
for _x in x:
@@ -327,7 +311,7 @@ class Args(object):
return self.start_with('-')
@property
@property
def not_flags(self):
"""Returns Arg object excluding flagged arguments."""
@@ -341,7 +325,7 @@ class Args(object):
_paths = []
for arg in self.all:
for path in _expand_path(arg):
for path in expand_path(arg):
if os.path.exists(path):
if absolute:
_paths.append(os.path.abspath(path))
@@ -358,7 +342,7 @@ class Args(object):
_args = []
for arg in self.all:
if not len(_expand_path(arg)):
if not len(expand_path(arg)):
if not os.path.exists(arg):
_args.append(arg)
+12 -6
View File
@@ -7,12 +7,18 @@ clint.eng
This module provides English language string helpers.
"""
from __future__ import print_function
MORON_MODE = False
COMMA = ','
CONJUNCTION = 'and'
SPACE = ' '
try:
unicode
except NameError:
unicode = str
def join(l, conj=CONJUNCTION, im_a_moron=MORON_MODE, seperator=COMMA):
"""Joins lists of words. Oxford comma and all."""
@@ -41,9 +47,9 @@ def join(l, conj=CONJUNCTION, im_a_moron=MORON_MODE, seperator=COMMA):
return unicode(str().join(collector))
if __name__ == '__main__':
print join(['blue', 'red', 'yellow'], conj='or', im_a_moron=True)
print join(['blue', 'red', 'yellow'], conj='or')
print join(['blue', 'red'], conj='or')
print join(['blue', 'red'], conj='and')
print join(['blue'], conj='and')
print join(['blue', 'red', 'yellow', 'green', 'ello'], conj='and')
print(join(['blue', 'red', 'yellow'], conj='or', im_a_moron=True))
print(join(['blue', 'red', 'yellow'], conj='or'))
print(join(['blue', 'red'], conj='or'))
print(join(['blue', 'red'], conj='and'))
print(join(['blue'], conj='and'))
print(join(['blue', 'red', 'yellow', 'green', 'ello'], conj='and'))
+1 -1
View File
@@ -115,7 +115,7 @@ class AppDir(object):
remove(fn)
else:
removedirs(fn)
except OSError, why:
except OSError as why:
if why.errno == errno.ENOENT:
pass
else:
+1 -1
View File
@@ -12,4 +12,4 @@ This module provides the text output helper system.
from . import colored
from . import progress
from core import *
from .core import *
+13 -5
View File
@@ -14,6 +14,8 @@ from __future__ import absolute_import
import re
import sys
PY3 = sys.version_info[0] >= 3
from ..packages import colorama
__all__ = (
@@ -53,12 +55,18 @@ class ColoredString(object):
def __repr__(self):
return "<%s-string: '%s'>" % (self.color, self.s)
def __str__(self):
return self.__unicode__().encode('utf8')
def __unicode__(self):
return self.color_str
if PY3:
__str__ = __unicode__
else:
def __str__(self):
return unicode(self).encode('utf8')
def __iter__(self):
return iter(self.color_str)
def __add__(self, other):
return str(self.color_str) + str(other)
@@ -68,8 +76,8 @@ class ColoredString(object):
def __mul__(self, other):
return (self.color_str * other)
def split(self, x=' '):
return map(self._new, self.s.split(x))
def split(self, sep=None):
return [self._new(s) for s in self.s.split(sep)]
def _new(self, s):
return ColoredString(self.color, s)
+4 -5
View File
@@ -15,20 +15,19 @@ import sys
STREAM = sys.stderr
BAR_TEMPLATE = '%s[%s%s] %i/%i\r'
BAR_EMPTY_CHAR = '-'
BAR_FILLED_CHAR = '='
DOTS_CHAR = '.'
BAR_FILLED_CHAR = '#'
BAR_EMPTY_CHAR = ' '
def bar(it, label='', width=32, hide=False):
def bar(it, label='', width=32, hide=False, empty_char=BAR_EMPTY_CHAR, filled_char=BAR_FILLED_CHAR):
"""Progress iterator. Wrap your iterables with it."""
def _show(_i):
x = int(width*_i/count)
if not hide:
STREAM.write(BAR_TEMPLATE % (
label, BAR_FILLED_CHAR*x, BAR_EMPTY_CHAR*(width-x), _i, count))
label, filled_char*x, empty_char*(width-x), _i, count))
STREAM.flush()
count = len(it)
+29 -5
View File
@@ -11,9 +11,33 @@ Various Python helpers used within clint.
from __future__ import absolute_import
from __future__ import with_statement
import sys
import errno
import os.path
from os import makedirs
from glob import glob
try:
basestring
except NameError:
basestring = str
def expand_path(path):
"""Expands directories and globs in given path."""
paths = []
path = os.path.expanduser(path)
path = os.path.expandvars(path)
if os.path.isdir(path):
for (dir, dirs, files) in os.walk(path):
for file in files:
paths.append(os.path.join(dir, file))
else:
paths.extend(glob(path))
return paths
def is_collection(obj):
@@ -29,7 +53,7 @@ def mkdir_p(path):
"""Emulates `mkdir -p` behavior."""
try:
makedirs(path)
except OSError, exc: # Python >2.5
except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST:
pass
else:
@@ -37,17 +61,17 @@ def mkdir_p(path):
def tsplit(string, delimiters):
"""Behaves str.split but supports tuples of delimiters."""
delimiters = tuple(delimiters)
stack = [string,]
for delimiter in delimiters:
for i, substring in enumerate(stack):
substack = substring.split(delimiter)
stack.pop(i)
for j, _substring in enumerate(substack):
stack.insert(i+j, _substring)
return stack
def schunk(string, size):
+3 -1
View File
@@ -1,6 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
import os
@@ -13,4 +15,4 @@ text = 'THIS TEXT IS COLORED %s!'
if __name__ == '__main__':
for color in colored.COLORS:
print getattr(colored, color)(text % color.upper())
print(getattr(colored, color)(text % color.upper()))
+1 -1
View File
@@ -17,7 +17,7 @@ colors = [
colored.magenta('magenta')
]
colors = map(str, colors)
colors = [str(cs) for cs in colors]
puts('Smart:')
+7 -5
View File
@@ -1,6 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
import os
@@ -13,16 +15,16 @@ resources.init('kennethreitz', 'clint')
lorem = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
print '%s created.' % resources.user.path
print('%s created.' % resources.user.path)
resources.user.write('lorem.txt', lorem)
print 'lorem.txt created'
print('lorem.txt created')
assert resources.user.read('lorem.txt') == lorem
print 'lorem.txt has correct contents'
print('lorem.txt has correct contents')
resources.user.delete('lorem.txt')
print 'lorem.txt deleted'
print('lorem.txt deleted')
assert resources.user.read('lorem.txt') == None
print 'lorem.txt deletion confirmed'
print('lorem.txt deletion confirmed')
+3 -2
View File
@@ -19,5 +19,6 @@ if __name__ == '__main__':
col = 60
puts(columns([(colored.red('Column 1')), col], [(colored.green('Column Two')), None], [(colored.magenta('Column III')), col]))
puts(columns(['hi there my name is kenneth and this is a columns', col], [lorem, None], ['kenneths', col]))
puts(columns([(colored.red('Column 1')), col], [(colored.green('Column Two')), None],
[(colored.magenta('Column III')), col]))
puts(columns(['hi there my name is kenneth and this is a columns', col], [lorem, None], ['kenneths', col]))
+6 -2
View File
@@ -38,14 +38,18 @@ setup(
license='ISC',
classifiers=(
# 'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Intended Audience :: Developers',
'Natural Language :: English',
'License :: OSI Approved :: ISC License (ISCL)',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.5',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
# 'Programming Language :: Python :: 3.0',
# 'Programming Language :: Python :: 3.1',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.1',
'Programming Language :: Python :: 3.2',
'Topic :: Terminals :: Terminal Emulators/X Terminals',
),
)