Add pypi Support
This commit is contained in:
commit
266c182f2a
6 changed files with 48 additions and 158 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1 +1,4 @@
|
||||||
*.pyc
|
*.pyc
|
||||||
|
build/
|
||||||
|
dist/
|
||||||
|
colout.egg-info/
|
||||||
|
|
|
||||||
150
README.md
150
README.md
|
|
@ -1,150 +0,0 @@
|
||||||
colout(1) -- Color Up Arbitrary Command Ouput
|
|
||||||
=============================================
|
|
||||||
|
|
||||||
## SYNOPSIS
|
|
||||||
|
|
||||||
`colout` [-h] [-e] [-g] [-t] [-s] [-l] PATTERN [COLOR(S)] [STYLE(S)]
|
|
||||||
|
|
||||||
|
|
||||||
## DESCRIPTION
|
|
||||||
|
|
||||||
`colout` read lines of text stream on the standard input and output characters
|
|
||||||
matching a given regular expression *PATTERN* in given <COLOR> and *STYLE*.
|
|
||||||
|
|
||||||
If groups are specified in the regular expression pattern, only them are taken
|
|
||||||
into account, else the whole matching pattern is colored.
|
|
||||||
|
|
||||||
You can specify severall colors or styles when using groups by separating them
|
|
||||||
with commas. If you indicate more colors than groups, the last ones will be ignored.
|
|
||||||
If you ask for less colors, the last one will be duplicated across remaining
|
|
||||||
groups.
|
|
||||||
|
|
||||||
Available colors are: blue, black, yellow, cyan, green, magenta, white, red,
|
|
||||||
rainbow, random, Random, scale, none or any number between 0 and 255.
|
|
||||||
|
|
||||||
Available styles are: normal, bold, faint, italic, underline, blink,
|
|
||||||
rapid_blink, reverse, conceal or random.
|
|
||||||
|
|
||||||
`Random` will color each matching pattern with a random color among the 255
|
|
||||||
available in the ANSI table. `random` will do the same in 8 colors mode.
|
|
||||||
|
|
||||||
`rainbow` will cycle over a 8 colors rainbow at each matching pattern.
|
|
||||||
|
|
||||||
`scale` will parse the matching text as a decimal number and apply the rainbow
|
|
||||||
colormap according to its position on a scale defined by the `-l` option (see
|
|
||||||
below, [0-100] by default).
|
|
||||||
|
|
||||||
When not specified, a *COLOR* defaults to _red_ and a *STYLE* defaults to _bold_.
|
|
||||||
|
|
||||||
`colout` comes with some predefined themes to rapidely color well-known outputs
|
|
||||||
(see the `-t` switch below).
|
|
||||||
|
|
||||||
If the python-pygments library is available, `colout` can be used as an interface
|
|
||||||
to it (see also the `-s` switch below).
|
|
||||||
|
|
||||||
`colout` is released under the GNU Public License v3.
|
|
||||||
|
|
||||||
|
|
||||||
## OPTIONS
|
|
||||||
|
|
||||||
* `-h`, `--help`:
|
|
||||||
Show an help message and exit
|
|
||||||
|
|
||||||
* `-g`, `--groups`:
|
|
||||||
For color maps (like "rainbow"), iterate over matching groups in the pattern instead of over patterns.
|
|
||||||
|
|
||||||
* `-c`, `--colormap`:
|
|
||||||
Use the given list of comma-separated colors as a colormap (cycle the colors at each match).
|
|
||||||
|
|
||||||
* `-l`, `--scale`:
|
|
||||||
When using the 'scale' colormap, parse matches as decimal numbers (taking your locale into account)
|
|
||||||
and apply the rainbow colormap linearly between the given SCALE=min,max (SCALE=0,100, by default).
|
|
||||||
|
|
||||||
* `-a`, `--all`:
|
|
||||||
Color the whole input at once instead of line per line
|
|
||||||
(really useful for coloring a source code file with strings on multiple lines).
|
|
||||||
|
|
||||||
* `-t`, `--theme`:
|
|
||||||
Interpret PATTERN as a predefined theme (perm, cmake, g++, etc.)
|
|
||||||
|
|
||||||
* `-s`, `--source`:
|
|
||||||
Interpret PATTERN as a source code readable by the Pygments library. If the first letter of PATTERN
|
|
||||||
is upper case, use the 256 colors mode, if it is lower case, use the 8 colors mode.
|
|
||||||
In 256 colors, interpret COLOR as a Pygments style (e.g. "default").
|
|
||||||
|
|
||||||
|
|
||||||
## REGULAR EXPRESSIONS
|
|
||||||
|
|
||||||
A regular expression (or _regex_) is a pattern that describes a set of strings
|
|
||||||
that matches it.
|
|
||||||
|
|
||||||
`colout` understands regex as specifed in the _re_ python module. Given that
|
|
||||||
`colout` is generally called by the command line, you may have to escape
|
|
||||||
special characters that would be recognize by your shell.
|
|
||||||
|
|
||||||
|
|
||||||
## DEPENDENCIES
|
|
||||||
|
|
||||||
Recommended packages :
|
|
||||||
|
|
||||||
* `argparse` for a usable arguments parsing
|
|
||||||
* `pygments` for the source code syntax coloring
|
|
||||||
* `babel` for a locale-aware number parsing
|
|
||||||
|
|
||||||
|
|
||||||
## EXAMPLES
|
|
||||||
|
|
||||||
* Color in bold red every occurence of the word _color_ in colout sources:
|
|
||||||
`cat colout.py | colout color red bold`
|
|
||||||
|
|
||||||
* Color in bold violet home directories in _/etc/passwd_:
|
|
||||||
`colout '/home/[a-z]+' 135 < /etc/passwd`
|
|
||||||
|
|
||||||
* Use a different color for each line of the auth log
|
|
||||||
`grep user /var/log/auth.log | colout "^.*$" rainbow`
|
|
||||||
|
|
||||||
* Color in yellow user/groups id, in bold green name and in bold red home directories in _/etc/passwd_:
|
|
||||||
`colout ':x:([0-9]+:[0-9]+):([^:]+).*(/home/[a-z]+)' yellow,green,red normal,bold < /etc/passwd`
|
|
||||||
|
|
||||||
* Color in yellow file permissions with read rights for everyone:
|
|
||||||
`ls -l | colout '.(r.-){3}' yellow normal`
|
|
||||||
|
|
||||||
* Color in green read permission, in bold red write and execution ones:
|
|
||||||
`ls -l | colout '(r)(w*)(x*)' green,red normal,bold`
|
|
||||||
|
|
||||||
* Color permissions with a predefined template:
|
|
||||||
`ls -l | colout -t perm`
|
|
||||||
|
|
||||||
* Color in green comments in colout sources:
|
|
||||||
`colout '.*(#.*)$' green normal < colout.py`
|
|
||||||
|
|
||||||
* Color in light green comments in non-empty colout sources, with the sharp in bold green:
|
|
||||||
`grep -v '^\s*$' colout.py | colout '.*(#)(.*)$' green,119 bold,normal`
|
|
||||||
|
|
||||||
* Color in bold green every numbers and in bold red the words _error_ in make output:
|
|
||||||
`make 2>&1 | colout '[0-9]+' green normal | colout error`
|
|
||||||
|
|
||||||
* Color a make output, line numbers in yellow, errors in bold red, warning in magenta, pragma in green and C++ file base names in cyan:
|
|
||||||
`make 2>&1 | colout ':([0-9]+):[0-9]*' yellow normal | colout error | colout warning magenta | colout pragma green normal | colout '/(\w+)*\.(h|cpp)' cyan normal`
|
|
||||||
Or using themes:
|
|
||||||
`make 2>&³ | colout -t cmake | colout -t g++`
|
|
||||||
|
|
||||||
* Color each word in the head of auth.log with a rainbow color map, starting a new colormap at each new line (the
|
|
||||||
begining of the command is just bash magic to repeat the string "(\\w+)\\W+":
|
|
||||||
`L=$(seq 10) ; P=${L//??/(\\w+)\\W+} ; head /var/log/auth.log | colout -g "^${P}(.*)$" rainbow`
|
|
||||||
|
|
||||||
* Color each line of a file with a different color among a 256 color gradient from cyan to green:
|
|
||||||
`head /var/log/auth.log | colout -c "^.*$" 39,38,37,36,35,34`
|
|
||||||
|
|
||||||
* Color a source code in 8 colors mode, without seeing comments:
|
|
||||||
`cat colout.py | grep -v "#" | colout -s python`
|
|
||||||
|
|
||||||
* Color a source code in 256 colors mode:
|
|
||||||
`cat colout.py | colout -s Python monokai`
|
|
||||||
|
|
||||||
* Color a JSON stream:
|
|
||||||
`echo '{"foo": "lorem", "bar":"ipsum"}' | python -mjson.tool | colout -t json`
|
|
||||||
|
|
||||||
* Color a source code substring:
|
|
||||||
`echo "There is an error in 'static void Functor::operator()( EOT& indiv ) { return indiv; }' you should fix it" | colout "'(.*)'" Cpp monokai`
|
|
||||||
|
|
||||||
11
bin/colout
Normal file
11
bin/colout
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Copyright © 2013 Martin Ueding <dev@martin-ueding.de>
|
||||||
|
|
||||||
|
# Small launcher script for the main module.
|
||||||
|
|
||||||
|
# Licence: GPL 3
|
||||||
|
|
||||||
|
set -e
|
||||||
|
set -u
|
||||||
|
|
||||||
|
python3 -m colout.colout "$@"
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
#encoding: utf-8
|
#encoding: utf-8
|
||||||
|
|
||||||
|
def default_gettext( msg ):
|
||||||
|
return msg
|
||||||
|
|
||||||
def theme():
|
def theme():
|
||||||
import os
|
import os
|
||||||
import gettext
|
import gettext
|
||||||
|
|
@ -9,7 +12,11 @@ def theme():
|
||||||
gv = os.popen("g++ -dumpversion").read().strip()
|
gv = os.popen("g++ -dumpversion").read().strip()
|
||||||
|
|
||||||
# get the current translations of gcc
|
# get the current translations of gcc
|
||||||
|
try:
|
||||||
t = gettext.translation("gcc-"+gv)
|
t = gettext.translation("gcc-"+gv)
|
||||||
|
except IOError:
|
||||||
|
_ = default_gettext
|
||||||
|
else:
|
||||||
_ = t.gettext
|
_ = t.gettext
|
||||||
# _("msg") will return the given message, translated
|
# _("msg") will return the given message, translated
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
def theme():
|
def theme():
|
||||||
return [
|
return [
|
||||||
[ '[{}]' ],
|
[ '[][{}]' ],
|
||||||
[ '[:,]', "blue" ],
|
[ '[:,]', "blue" ],
|
||||||
[ '".*"', "green" ]
|
[ '".*"', "green" ]
|
||||||
]
|
]
|
||||||
|
|
|
||||||
29
setup.py
29
setup.py
|
|
@ -1,9 +1,9 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import colout
|
#import colout
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
|
@ -11,26 +11,45 @@ except ImportError:
|
||||||
from distutils.core import setup
|
from distutils.core import setup
|
||||||
|
|
||||||
if sys.argv[-1] == 'publish':
|
if sys.argv[-1] == 'publish':
|
||||||
os.system('python setup.py sdist upload')
|
os.system('python3 setup.py sdist upload')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
packages = ['colout']
|
packages = ['colout']
|
||||||
|
|
||||||
requires = ['pygments']
|
requires = ['argparse', 'pygments', 'babel']
|
||||||
|
|
||||||
|
classifiers = """\
|
||||||
|
Development Status :: 4 - Beta
|
||||||
|
Environment :: Console
|
||||||
|
Intended Audience :: End Users/Desktop
|
||||||
|
License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
||||||
|
Operating System :: OS Independent
|
||||||
|
Programming Language :: Python
|
||||||
|
Programming Language :: Python :: 2.5
|
||||||
|
Programming Language :: Python :: 2.6
|
||||||
|
Programming Language :: Python :: 2.7
|
||||||
|
Programming Language :: Python :: 3
|
||||||
|
Topic :: Text Processing
|
||||||
|
Topic :: Utilities
|
||||||
|
Topic :: Software Development :: Libraries :: Python Modules
|
||||||
|
"""
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='colout',
|
name='colout',
|
||||||
version='0.1',
|
version='0.1',
|
||||||
description='Color Up Arbitrary Command Ouput.',
|
description='Color Up Arbitrary Command Ouput.',
|
||||||
long_description=open('README.md').read(),
|
long_description=open('README').read(),
|
||||||
author='nojhan',
|
author='nojhan',
|
||||||
author_email='nojhan@nojhan.net',
|
author_email='nojhan@nojhan.net',
|
||||||
url='http://nojhan.github.com/colout/',
|
url='http://nojhan.github.com/colout/',
|
||||||
|
download_url = 'https://pypi.python.org/packages/source/C/colout/colout-0.1.tar.gz',
|
||||||
packages=packages,
|
packages=packages,
|
||||||
package_data={'': ['LICENSE']},
|
package_data={'': ['LICENSE']},
|
||||||
package_dir={'colout': 'colout'},
|
package_dir={'colout': 'colout'},
|
||||||
|
scripts=['bin/colout'],
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
install_requires=requires,
|
install_requires=requires,
|
||||||
license=open('LICENSE').read(),
|
license=open('LICENSE').read(),
|
||||||
|
classifiers = filter(None, classifiers.split("\n")),
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue