forked from aljungberg/pyle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
89 lines (65 loc) · 2.71 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from distutils.core import setup
setup(name='pyle',
version='0.2',
description='Use Python for shell one-liners.',
author='Alexander Ljungberg',
author_email='[email protected]',
url='https://github.com/aljungberg/pyle',
py_modules=['pyle', 'pyle_test'],
scripts=['pyle'],
keywords=["shell"],
classifiers=[
"Programming Language :: Python",
"Development Status :: 3 - Alpha",
"Environment :: Console",
"Intended Audience :: System Administrators",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: POSIX",
"Topic :: System :: Shells",
"Topic :: System :: Systems Administration"
],
long_description="""\
Use Python for shell one-liners
-------------------------------
Pyle makes it easy to use Python as a replacement for command line tools
such as ``sed`` or ``perl``. For instance, to perform an in-place string
substitution, overwriting the original file with the updated file, you
might do:
::
pyle -ie "re.sub(r'alien(s|)?', r'ghost\1', line)" TextAboutAliens.md
To print the first 20 characters of each line of a file:
::
cat README.md | pyle -e "line[:20]"
or:
::
pyle -e "line[:20]" README.md
In addition to ``line``, a list called ``words`` is also available which
is the current line split by whitespace. To print just the URLs in an
Apache access log (the seventh "word" in the line):
::
tail access_log | pyle -e "words[6]"
Print the SHA 256 sum of each ``*.py`` file in the current directory:
::
$ ls *.py | pyle -m hashlib -e "'%s %s' % (hashlib.sha256(line).hexdigest(), line)"
348e4a65e24bab4eed8e2bbe6f4c8176ddec60051d1918eea38b34b1103a8af6 pyle.py
b28c7f73e6df990a96cfb724be1d673c2d3c43f68d4b6c06d8e5a9b29e5d12cb pyle_test.py
If your expression returns a list or a tuple, the items will be printed
joined by spaces. With that in mind we can simplify the above example:
::
$ ls *.py | pyle -m hashlib -e "(hashlib.sha256(line).hexdigest(), line)"
348e4a65e24bab4eed8e2bbe6f4c8176ddec60051d1918eea38b34b1103a8af6 pyle.py
b28c7f73e6df990a96cfb724be1d673c2d3c43f68d4b6c06d8e5a9b29e5d12cb pyle_test.py
Print the first five lines of each file with filenames and line numbers:
::
$ pyle -e "'%-15s:%04d %s' % (filename, 1 + num, line) if num < 5 else None" *.py
The idea for Pyle is based on Graham Fawcett's
`PyLine <http://code.activestate.com/recipes/437932-pyle-a-grep-like-sed-like-command-line-tool/>`_.
Pyle is mostly compatible with PyLine but requires a ``-e`` before the
evaluation statement.
""",
install_requires=[
'argparse >= 1.2.1',
'sh >= 1.0.9',
],
)