mirror of
https://github.com/kennethreitz/clint.git
synced 2026-06-05 23:00:18 +00:00
Compare commits
220 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6a417e5bdf | |||
| 7431c17fe4 | |||
| 30da40376e | |||
| 9153edaba1 | |||
| c4cf340284 | |||
| 137ba12a10 | |||
| 29c1ea82ff | |||
| 2982cefb91 | |||
| f2bcc93760 | |||
| 52e7cb8a7d | |||
| 8ef067958d | |||
| 6dbc68df5b | |||
| 6aadd5ad8b | |||
| 0aa2ea4b18 | |||
| e93a6a5ee4 | |||
| 6e32222d3c | |||
| 7ee2ebfa7d | |||
| b99f79c98e | |||
| df7b9594a4 | |||
| a00621ed59 | |||
| cf4b06cf4e | |||
| 57955b9156 | |||
| f1ab574413 | |||
| 2aff70618c | |||
| 4b7688b220 | |||
| 03731d6ef2 | |||
| 8a2aed6c32 | |||
| 98cab56e97 | |||
| 13df32316f | |||
| 93c3f9a4e1 | |||
| 9f14dbb6c5 | |||
| 0e0284f967 | |||
| c5dbe0708e | |||
| 00b522510c | |||
| 4b98c46519 | |||
| e62f5657a5 | |||
| 8e17e8ce50 | |||
| 84dafbeabe | |||
| 5305d1e116 | |||
| 73b1bdd2d4 | |||
| 7bde48ce53 | |||
| a0e14e4181 | |||
| de2cbfca90 | |||
| c909d7dca0 | |||
| 6220552ebf | |||
| a9623213e3 | |||
| 77eab0c0e6 | |||
| 3d01b405b3 | |||
| 6c50b92cb3 | |||
| e00476d195 | |||
| fc463f16c3 | |||
| 9324af95b2 | |||
| 50294ea2dc | |||
| 56fe6138b6 | |||
| d22847fb95 | |||
| ce25cea7e8 | |||
| cab8004284 | |||
| c76cc35289 | |||
| 8e86e4c1fa | |||
| 858db011d8 | |||
| c111ba5d92 | |||
| 9e43717921 | |||
| 8e351ac4d0 | |||
| cb8bcee077 | |||
| 3df99a6a2b | |||
| 5b37fb544d | |||
| 099a506344 | |||
| d7fdbe85a9 | |||
| 7b2130e582 | |||
| f884841082 | |||
| 112ea81b51 | |||
| 399fa2bb24 | |||
| ab2f37219a | |||
| 464849e575 | |||
| acdddbabea | |||
| 1a11a670e7 | |||
| 1dc521de1a | |||
| 1e3888e530 | |||
| 2c8561a492 | |||
| 04f0cdd646 | |||
| 0bd5026d21 | |||
| b69ceb18d2 | |||
| e1bdaa4d0d | |||
| 8103032de8 | |||
| ab401e7af2 | |||
| fc841b0a61 | |||
| b591c3edc2 | |||
| 70c0680b8c | |||
| e7db8c7e37 | |||
| 944af48ba5 | |||
| a1808173d9 | |||
| c2aa315a58 | |||
| 3e03a9ceb9 | |||
| 02016e8b06 | |||
| a7e2d21273 | |||
| 911a84406e | |||
| afd410125d | |||
| e2a169ab9c | |||
| cfad07a774 | |||
| 48d9c16f0f | |||
| 86b196811f | |||
| d479ea3a3c | |||
| fc873deb3b | |||
| d4cb4e8c01 | |||
| 7c48045b57 | |||
| ea9b2186d5 | |||
| 761dce7237 | |||
| 72b04cf5af | |||
| 0378771f94 | |||
| 129fea5e4f | |||
| a9d1089bbd | |||
| 270afcca03 | |||
| c7f5296b13 | |||
| e8f6f7737a | |||
| 43b152cf0e | |||
| 0d0d482156 | |||
| 3a40b682f4 | |||
| 1d1bb71203 | |||
| b917e68837 | |||
| 66a6148088 | |||
| a95e803268 | |||
| 7e1c739755 | |||
| ec46d65bd2 | |||
| 73a9cd836b | |||
| c9bf3bac3a | |||
| 5f2df1218a | |||
| 526cf84ebb | |||
| 3709f090b4 | |||
| d6214ababb | |||
| ee089c2d39 | |||
| dbb063840a | |||
| 9a4705f090 | |||
| b16b2ce723 | |||
| 1ea4c5afdc | |||
| 39bb08253f | |||
| 8e6973253f | |||
| 84419f6bfb | |||
| 53ec4c2e09 | |||
| 7b6138eda6 | |||
| d19650b93c | |||
| 98edec43e9 | |||
| ef48a47b8d | |||
| 3be47add4a | |||
| bf99084ece | |||
| 705cda4443 | |||
| 79cf7a023b | |||
| 7900853dbc | |||
| 96827698df | |||
| 23689f8b0a | |||
| 1a9e15dbba | |||
| a07602fdeb | |||
| 0855525fca | |||
| 872c78a5b9 | |||
| 5d7485c144 | |||
| 25b8d6a10e | |||
| 003411ebcd | |||
| f651e71093 | |||
| e500773da3 | |||
| 4b9e35c631 | |||
| e85fffdbb6 | |||
| b58f8dccdc | |||
| 3d63ed01f9 | |||
| 81165754a4 | |||
| 6f106e2f12 | |||
| 8adda14a27 | |||
| cc072a18f3 | |||
| c226b6b736 | |||
| 3406ab5329 | |||
| cf0c0bda70 | |||
| a4c2be8865 | |||
| fa2bbf9a0d | |||
| 9736b4cd71 | |||
| 2e68207d0a | |||
| 164d68ce37 | |||
| aa5008b2e0 | |||
| 8b7161b15b | |||
| 763ca94e7b | |||
| 2d200e3709 | |||
| d0f2375a7b | |||
| 2369bc387d | |||
| f12e47fa7c | |||
| 5d733d123d | |||
| 9e1ea1ef91 | |||
| 6d151a0794 | |||
| 13afb11dea | |||
| faeacbbfad | |||
| 401344ff1e | |||
| 598deda4d9 | |||
| bf7b5d0930 | |||
| 6404b0e49c | |||
| b92f3204c9 | |||
| 61225d90e6 | |||
| 3688a2a67b | |||
| dda561387c | |||
| 06af338874 | |||
| 9b91cf16b5 | |||
| ec8fe4a0b7 | |||
| dc6a9c63ea | |||
| 82d31e555f | |||
| 2f6e9cbfaa | |||
| b576ccbaae | |||
| 8e021f95e9 | |||
| 83bf2288dd | |||
| f2fc21755b | |||
| 52488ace36 | |||
| 8b6eb543b9 | |||
| 2cd9bd5263 | |||
| 76bee9c4ba | |||
| 14c4cdf904 | |||
| f6a20fc413 | |||
| fc3eeca54f | |||
| ebdb04848a | |||
| f0206b21fc | |||
| 5366c7e5b2 | |||
| 35ec821e37 | |||
| 1cdb5dca3f | |||
| d043fd0a56 | |||
| 1250a857e0 | |||
| 3cb3314d34 | |||
| 4597f19625 |
+10
-1
@@ -1,2 +1,11 @@
|
||||
.idea
|
||||
MANIFEST
|
||||
.project
|
||||
.settings
|
||||
.pydevproject
|
||||
MANIFEST
|
||||
*.pyc
|
||||
.tox
|
||||
build/
|
||||
clint.egg-info/
|
||||
dist/
|
||||
|
||||
|
||||
@@ -6,10 +6,28 @@ Development Lead
|
||||
|
||||
- Kenneth Reitz <me@kennethreitz.com>
|
||||
|
||||
Maintainers
|
||||
```````````
|
||||
|
||||
- Jason Piper <j.piper@me.com>
|
||||
|
||||
Patches and Suggestions
|
||||
```````````````````````
|
||||
|
||||
- Jeff Forcier
|
||||
- Morgan Goose
|
||||
- Travis Swicegood
|
||||
- Travis Swicegood
|
||||
- Will Thames
|
||||
- Greg Haskins
|
||||
- Miguel Araujo <maraujop>
|
||||
- takluyver
|
||||
- kracekumar
|
||||
- Alejandro Gómez <alejandrogomez>
|
||||
- Jason Piper <jpiper>
|
||||
- Gianluca Brindisi <gbrindisi>
|
||||
- Don Spaulding <donspauldingii@gmail.com>
|
||||
- Justin Barber <barber.justin (at) gmail>
|
||||
- Dmitry Medvinsky
|
||||
- Eric Anderson
|
||||
- Joshua Richardson
|
||||
- Brandon Liu <thenovices>
|
||||
|
||||
@@ -11,4 +11,4 @@ All functionality should be available in pure Python. Optional C (via Cython)
|
||||
implementations may be written for performance reasons, but should never
|
||||
replace the Python implementation.
|
||||
|
||||
Lastly, don't take yourself too seriously :)
|
||||
Lastly, don't take yourself too seriously :)
|
||||
|
||||
+106
-2
@@ -1,10 +1,109 @@
|
||||
History
|
||||
-------
|
||||
|
||||
0.1.0 (2011-03-20)
|
||||
0.4.1
|
||||
+++++
|
||||
* Fix bug in logic that decides whether progress bars should be hidden or not
|
||||
|
||||
|
||||
0.4.0
|
||||
+++++
|
||||
* clint.textui.prompt now has a query function with validators! (thanks to @aeby) - see `examples/prompt.py`
|
||||
* Clint docs are now included in sdist (thanks to @alunduil)
|
||||
* Misc. bug fixes
|
||||
|
||||
|
||||
0.3.7
|
||||
+++++
|
||||
* Clint now obeys the CLINT_FORCE_COLOR environmental variable
|
||||
|
||||
|
||||
0.3.6
|
||||
+++++
|
||||
* Fixed faulty PyPI deployment
|
||||
|
||||
|
||||
0.3.5
|
||||
+++++
|
||||
* progress.bar is now a context manager - doesn't require an iterable anymore (thanks to @jric)
|
||||
* Bug fixes
|
||||
|
||||
|
||||
0.3.4
|
||||
+++++
|
||||
* Fixed Python 3 basestring deprecation
|
||||
* Fixed examples
|
||||
|
||||
|
||||
0.3.3
|
||||
+++++
|
||||
* Fixed Python 3 build issues
|
||||
* Fixed README and HISTORY being installed to /usr
|
||||
* Support added for bold text
|
||||
|
||||
|
||||
0.3.2
|
||||
+++++
|
||||
* Unknown
|
||||
|
||||
|
||||
0.3.1
|
||||
+++++
|
||||
* Unknown
|
||||
|
||||
|
||||
0.3.0
|
||||
+++++
|
||||
|
||||
* Python 3 support!
|
||||
|
||||
|
||||
0.2.4
|
||||
+++++
|
||||
|
||||
* New eng module
|
||||
* Win32 Bugfix
|
||||
|
||||
|
||||
0.2.3
|
||||
+++++
|
||||
|
||||
* Only init colors if they are used (iPython compatability)
|
||||
* New progress module
|
||||
* Various bugfixes
|
||||
|
||||
|
||||
0.2.2
|
||||
+++++
|
||||
|
||||
* Auto Color Disabling
|
||||
* Progress Namespace Change
|
||||
* New Progress Bars
|
||||
* textui.puts newline fix
|
||||
|
||||
|
||||
0.2.1 (2011-03-24)
|
||||
++++++++++++++++++
|
||||
|
||||
* Initial Release!
|
||||
* Python 2.5 Support
|
||||
* List of available colors
|
||||
|
||||
|
||||
0.2.0 (2011-03-23)
|
||||
++++++++++++++++++
|
||||
|
||||
* Column Printing!!!
|
||||
* (Auto/Manual) Disabling of Colors
|
||||
* Smarter Colors
|
||||
* max_width, min_width
|
||||
* Strip cli colors
|
||||
* bug fixes
|
||||
|
||||
|
||||
0.1.2 (2011-03-21)
|
||||
++++++++++++++++++
|
||||
|
||||
* Bugfixes
|
||||
|
||||
|
||||
0.1.1 (2011-03-20)
|
||||
@@ -16,3 +115,8 @@ History
|
||||
* Lots of Examples
|
||||
|
||||
|
||||
0.1.0 (2011-03-20)
|
||||
++++++++++++++++++
|
||||
|
||||
* Initial Release!
|
||||
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
include HISTORY.rst README.rst LICENSE AUTHORS NOTICE
|
||||
include HISTORY.rst README.rst LICENSE AUTHORS NOTICE
|
||||
@@ -1,4 +1,4 @@
|
||||
Clint includes some vendorized python libraries: appdirs, colorama, ordereddict.
|
||||
Clint includes some vendorized python libraries: appdirs, applib, colorama, ordereddict.
|
||||
|
||||
AppDirs License
|
||||
===============
|
||||
@@ -25,6 +25,33 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
AppLib License (console width detection functions are from this library)
|
||||
==============
|
||||
|
||||
# This is the MIT license
|
||||
|
||||
# Copyright (c) 2010 ActiveState Software Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
|
||||
Colorama License
|
||||
================
|
||||
|
||||
+44
-8
@@ -4,7 +4,7 @@ Clint: Python Command-line Application Tools
|
||||
**Clint** is a module filled with a set of awesome tools for developing
|
||||
commandline applications.
|
||||
|
||||
.. image:: https://github.com/kennethreitz/clint/raw/master/misc/clint.jpeg
|
||||
.. image:: https://raw.github.com/kennethreitz/clint/master/misc/clint.jpeg
|
||||
|
||||
**C** ommand
|
||||
**L** ine
|
||||
@@ -12,16 +12,42 @@ commandline applications.
|
||||
**T** ools
|
||||
.
|
||||
|
||||
Features:
|
||||
---------
|
||||
|
||||
Clint is awesome. Crazy awesome. It supports colors, but detects if the session is a TTY, so doesn't render the colors if you're piping stuff around. Automagically.
|
||||
|
||||
Awesome nest-able indentation context manager. Example: (``with indent(4): puts('indented text')``). It supports custom email-style quotes. Of course, it supports color too, if and when needed.
|
||||
|
||||
It has an awesome Column printer with optional auto-expanding columns. It detects how wide your current console is and adjusts accordingly. It wraps your words properly to fit the column size. With or without colors mixed in. All with a single function call.
|
||||
|
||||
The world's easiest to use implicit argument system w/ chaining methods for filtering. Seriously.
|
||||
|
||||
|
||||
Run the various executables in examples_ to get a good feel for what Clint offers.
|
||||
|
||||
.. _examples: https://github.com/kennethreitz/clint/tree/master/examples
|
||||
|
||||
You'll never want to not use it.
|
||||
|
||||
|
||||
|
||||
Current Features:
|
||||
-----------------
|
||||
- Little Documentation (bear with me for now)
|
||||
- CLI Colors and Indents
|
||||
- Extremely Simple + Powerful Column Printer
|
||||
- Iterator-based Progress Bar
|
||||
- Implicit Argument Handling
|
||||
- Simple Support for Unix Pipes
|
||||
- Simple Support for Incoming Unix Pipes
|
||||
- Application Directory management
|
||||
|
||||
|
||||
Future Features:
|
||||
----------------
|
||||
- Documentation!
|
||||
- Simple choice system ``Are you sure? [Yn]``
|
||||
- Suggestions welcome.
|
||||
|
||||
|
||||
Example
|
||||
-------
|
||||
|
||||
@@ -43,7 +69,7 @@ I want to quote my console text (like email). ::
|
||||
>>> puts('pretty cool, eh?')
|
||||
|
||||
not indented text
|
||||
> indented text
|
||||
> quoted text
|
||||
> pretty cool, eh?
|
||||
|
||||
I want to color my console text. ::
|
||||
@@ -64,7 +90,9 @@ I want to get data piped to stdin. ::
|
||||
|
||||
I want to get the first commandline argument passed in. ::
|
||||
|
||||
>>> clint.args.get(0)
|
||||
>>> from clint import arguments
|
||||
>>> args = arguments.Args()
|
||||
>>> args.get(0)
|
||||
|
||||
# if no argument was passed, get returns None
|
||||
|
||||
@@ -80,6 +108,15 @@ I want to store a configuration file. ::
|
||||
# Windows: 'C:\\Users\\appuser\\AppData\\Local\\Company\\AppName\\config.ini'
|
||||
# Linux: '/home/appuser/.config/appname/config.ini'
|
||||
|
||||
I want to force color output even if stdout is not a TTY:
|
||||
|
||||
$ export CLINT_FORCE_COLOR=1
|
||||
|
||||
I want to ask for input. ::
|
||||
|
||||
>>> from clint.textui import prompt, validators
|
||||
>>> path = prompt.query('Installation Path', default='/usr/local/bin/', validators=[validators.PathValidator()])
|
||||
|
||||
|
||||
Installation
|
||||
------------
|
||||
@@ -120,7 +157,7 @@ Contribute
|
||||
----------
|
||||
|
||||
If you'd like to contribute, simply fork `the repository`_, commit your changes
|
||||
to the **develop** branch (or branch off of it), and send a pull request. Make
|
||||
to the **master** branch (or branch off of it), and send a pull request. Make
|
||||
sure you add yourself to AUTHORS_.
|
||||
|
||||
|
||||
@@ -128,7 +165,6 @@ Roadmap
|
||||
-------
|
||||
- Unittests
|
||||
- Sphinx Documentation
|
||||
- Python 2.5, 3.1, 3.2 Support
|
||||
|
||||
|
||||
|
||||
|
||||
+11
-7
@@ -11,7 +11,14 @@ This module sets up the main interface for all of clint.
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from . import arguments
|
||||
try:
|
||||
from collections import OrderedDict
|
||||
except ImportError:
|
||||
from .packages.ordereddict import OrderedDict
|
||||
import collections
|
||||
collections.OrderedDict = OrderedDict
|
||||
|
||||
from .arguments import *
|
||||
from . import textui
|
||||
from . import utils
|
||||
from .pipes import piped_in
|
||||
@@ -19,12 +26,9 @@ from .pipes import piped_in
|
||||
|
||||
|
||||
__title__ = 'clint'
|
||||
__version__ = '0.1.1'
|
||||
__build__ = 0x000101
|
||||
__version__ = '0.4.1'
|
||||
__build__ = 0x000401
|
||||
__author__ = 'Kenneth Reitz'
|
||||
__license__ = 'ISC'
|
||||
__copyright__ = 'Copyright 2011 Kenneth Reitz'
|
||||
__copyright__ = 'Copyright 2012 Kenneth Reitz'
|
||||
__docformat__ = 'restructuredtext'
|
||||
|
||||
|
||||
args = arguments.Args()
|
||||
|
||||
+48
-45
@@ -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."""
|
||||
|
||||
@@ -69,7 +53,7 @@ class Args(object):
|
||||
|
||||
|
||||
def __contains__(self, x):
|
||||
return bool(self.first(x))
|
||||
return self.first(x) is not None
|
||||
|
||||
|
||||
def get(self, x):
|
||||
@@ -89,8 +73,8 @@ class Args(object):
|
||||
"""Removes given arg (or list thereof) from Args object."""
|
||||
|
||||
def _remove(x):
|
||||
found = self.find(x)
|
||||
if found:
|
||||
found = self.first(x)
|
||||
if found is not None:
|
||||
self._args.pop(found)
|
||||
|
||||
if is_collection(x):
|
||||
@@ -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))
|
||||
@@ -133,7 +117,7 @@ class Args(object):
|
||||
if is_collection(x):
|
||||
for item in x:
|
||||
found = _find(item)
|
||||
if found:
|
||||
if found is not None:
|
||||
return found
|
||||
return None
|
||||
else:
|
||||
@@ -181,6 +165,25 @@ class Args(object):
|
||||
else:
|
||||
return _find(x)
|
||||
|
||||
|
||||
def start_with(self, x):
|
||||
"""Returns all arguments beginning with given string (or list thereof)"""
|
||||
|
||||
_args = []
|
||||
|
||||
for arg in self.all:
|
||||
if is_collection(x):
|
||||
for _x in x:
|
||||
if arg.startswith(x):
|
||||
_args.append(arg)
|
||||
break
|
||||
else:
|
||||
if arg.startswith(x):
|
||||
_args.append(arg)
|
||||
|
||||
return Args(_args, no_argv=True)
|
||||
|
||||
|
||||
def contains_at(self, x, index):
|
||||
"""Tests if given [list of] string is at given index."""
|
||||
|
||||
@@ -193,7 +196,7 @@ class Args(object):
|
||||
return False
|
||||
else:
|
||||
return (x in self.all[index])
|
||||
|
||||
|
||||
except IndexError:
|
||||
return False
|
||||
|
||||
@@ -202,7 +205,7 @@ class Args(object):
|
||||
"""Returns true if argument exists at given index.
|
||||
Accepts: integer.
|
||||
"""
|
||||
|
||||
|
||||
try:
|
||||
self.all[x]
|
||||
return True
|
||||
@@ -212,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
|
||||
|
||||
@@ -238,7 +241,7 @@ class Args(object):
|
||||
for arg in self.all:
|
||||
if arg.startswith('-'):
|
||||
_current_group = arg
|
||||
collection[arg] = Args(no_argv=True)
|
||||
collection.setdefault(arg, Args(no_argv=True))
|
||||
else:
|
||||
if _current_group:
|
||||
collection[_current_group]._args.append(arg)
|
||||
@@ -247,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
|
||||
|
||||
|
||||
@@ -269,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:
|
||||
@@ -305,10 +308,10 @@ class Args(object):
|
||||
def flags(self):
|
||||
"""Returns Arg object including only flagged arguments."""
|
||||
|
||||
return self.all_with('-')
|
||||
return self.start_with('-')
|
||||
|
||||
|
||||
@property
|
||||
@property
|
||||
def not_flags(self):
|
||||
"""Returns Arg object excluding flagged arguments."""
|
||||
|
||||
@@ -322,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))
|
||||
@@ -339,11 +342,11 @@ 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)
|
||||
|
||||
return _args
|
||||
return Args(_args, no_argv=True)
|
||||
|
||||
@property
|
||||
def copy(self):
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
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, separator=COMMA):
|
||||
"""Joins lists of words. Oxford comma and all."""
|
||||
|
||||
collector = []
|
||||
left = len(l)
|
||||
separator = separator + SPACE
|
||||
conj = conj + SPACE
|
||||
|
||||
for _l in l[:]:
|
||||
|
||||
left += -1
|
||||
|
||||
collector.append(_l)
|
||||
if left == 1:
|
||||
if len(l) == 2 or im_a_moron:
|
||||
collector.append(SPACE)
|
||||
else:
|
||||
collector.append(separator)
|
||||
|
||||
collector.append(conj)
|
||||
|
||||
elif left is not 0:
|
||||
collector.append(separator)
|
||||
|
||||
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'))
|
||||
@@ -1,6 +1,6 @@
|
||||
from .initialise import init
|
||||
from .initialise import init, deinit, reinit
|
||||
from .ansi import Fore, Back, Style
|
||||
from .ansitowin32 import AnsiToWin32
|
||||
|
||||
VERSION = '0.1.18'
|
||||
VERSION = '0.2.3'
|
||||
|
||||
|
||||
@@ -118,12 +118,12 @@ class AnsiToWin32(object):
|
||||
self.wrapped.flush()
|
||||
if self.autoreset:
|
||||
self.reset_all()
|
||||
|
||||
|
||||
|
||||
def reset_all(self):
|
||||
if self.convert:
|
||||
self.call_win32('m', (0,))
|
||||
else:
|
||||
elif is_a_tty(self.wrapped):
|
||||
self.wrapped.write(Style.RESET_ALL)
|
||||
|
||||
|
||||
@@ -173,4 +173,10 @@ class AnsiToWin32(object):
|
||||
args = func_args[1:]
|
||||
kwargs = dict(on_stderr=self.on_stderr)
|
||||
func(*args, **kwargs)
|
||||
elif command in ('H', 'f'): # set cursor position
|
||||
func = winterm.set_cursor_position
|
||||
func(params, on_stderr=self.on_stderr)
|
||||
elif command in ('J'):
|
||||
func = winterm.erase_data
|
||||
func(params, on_stderr=self.on_stderr)
|
||||
|
||||
|
||||
@@ -7,6 +7,9 @@ from .ansitowin32 import AnsiToWin32
|
||||
orig_stdout = sys.stdout
|
||||
orig_stderr = sys.stderr
|
||||
|
||||
wrapped_stdout = sys.stdout
|
||||
wrapped_stderr = sys.stderr
|
||||
|
||||
atexit_done = False
|
||||
|
||||
|
||||
@@ -16,11 +19,14 @@ def reset_all():
|
||||
|
||||
def init(autoreset=False, convert=None, strip=None, wrap=True):
|
||||
|
||||
if wrap==False and (autoreset==True or convert==True or strip==True):
|
||||
if not wrap and any([autoreset, convert, strip]):
|
||||
raise ValueError('wrap=False conflicts with any other arg=True')
|
||||
|
||||
sys.stdout = wrap_stream(orig_stdout, convert, strip, autoreset, wrap)
|
||||
sys.stderr = wrap_stream(orig_stderr, convert, strip, autoreset, wrap)
|
||||
global wrapped_stdout, wrapped_stderr
|
||||
sys.stdout = wrapped_stdout = \
|
||||
wrap_stream(orig_stdout, convert, strip, autoreset, wrap)
|
||||
sys.stderr = wrapped_stderr = \
|
||||
wrap_stream(orig_stderr, convert, strip, autoreset, wrap)
|
||||
|
||||
global atexit_done
|
||||
if not atexit_done:
|
||||
@@ -28,6 +34,16 @@ def init(autoreset=False, convert=None, strip=None, wrap=True):
|
||||
atexit_done = True
|
||||
|
||||
|
||||
def deinit():
|
||||
sys.stdout = orig_stdout
|
||||
sys.stderr = orig_stderr
|
||||
|
||||
|
||||
def reinit():
|
||||
sys.stdout = wrapped_stdout
|
||||
sys.stderr = wrapped_stdout
|
||||
|
||||
|
||||
def wrap_stream(stream, convert, strip, autoreset, wrap):
|
||||
if wrap:
|
||||
wrapper = AnsiToWin32(stream,
|
||||
@@ -36,3 +52,4 @@ def wrap_stream(stream, convert, strip, autoreset, wrap):
|
||||
stream = wrapper.stream
|
||||
return stream
|
||||
|
||||
|
||||
|
||||
@@ -48,8 +48,16 @@ else:
|
||||
("srWindow", SMALL_RECT),
|
||||
("dwMaximumWindowSize", COORD),
|
||||
]
|
||||
def __str__(self):
|
||||
return '(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)' % (
|
||||
self.dwSize.Y, self.dwSize.X
|
||||
, self.dwCursorPosition.Y, self.dwCursorPosition.X
|
||||
, self.wAttributes
|
||||
, self.srWindow.Top, self.srWindow.Left, self.srWindow.Bottom, self.srWindow.Right
|
||||
, self.dwMaximumWindowSize.Y, self.dwMaximumWindowSize.X
|
||||
)
|
||||
|
||||
def GetConsoleScreenBufferInfo(stream_id):
|
||||
def GetConsoleScreenBufferInfo(stream_id=STDOUT):
|
||||
handle = handles[stream_id]
|
||||
csbi = CONSOLE_SCREEN_BUFFER_INFO()
|
||||
success = windll.kernel32.GetConsoleScreenBufferInfo(
|
||||
@@ -62,34 +70,54 @@ else:
|
||||
|
||||
def SetConsoleTextAttribute(stream_id, attrs):
|
||||
handle = handles[stream_id]
|
||||
success = windll.kernel32.SetConsoleTextAttribute(handle, attrs)
|
||||
assert success
|
||||
return windll.kernel32.SetConsoleTextAttribute(handle, attrs)
|
||||
|
||||
def SetConsoleCursorPosition(stream_id, position):
|
||||
handle = handles[stream_id]
|
||||
position = COORD(*position)
|
||||
success = windll.kernel32.SetConsoleCursorPosition(handle, position)
|
||||
assert success
|
||||
# If the position is out of range, do nothing.
|
||||
if position.Y <= 0 or position.X <= 0:
|
||||
return
|
||||
# Adjust for Windows' SetConsoleCursorPosition:
|
||||
# 1. being 0-based, while ANSI is 1-based.
|
||||
# 2. expecting (x,y), while ANSI uses (y,x).
|
||||
adjusted_position = COORD(position.Y - 1, position.X - 1)
|
||||
# Adjust for viewport's scroll position
|
||||
sr = GetConsoleScreenBufferInfo(STDOUT).srWindow
|
||||
adjusted_position.Y += sr.Top
|
||||
adjusted_position.X += sr.Left
|
||||
# Resume normal processing
|
||||
handle = handles[stream_id]
|
||||
success = windll.kernel32.SetConsoleCursorPosition(handle, adjusted_position)
|
||||
return success
|
||||
|
||||
def FillConsoleOutputCharacter(stream_id, char, length, start):
|
||||
handle = handles[stream_id]
|
||||
char = TCHAR(char)
|
||||
length = DWORD(length)
|
||||
start = COORD(*start)
|
||||
num_written = DWORD(0)
|
||||
# AttributeError: function 'FillConsoleOutputCharacter' not found
|
||||
# could it just be that my types are wrong?
|
||||
success = windll.kernel32.FillConsoleOutputCharacter(
|
||||
# Note that this is hard-coded for ANSI (vs wide) bytes.
|
||||
success = windll.kernel32.FillConsoleOutputCharacterA(
|
||||
handle, char, length, start, byref(num_written))
|
||||
assert success
|
||||
return num_written.value
|
||||
|
||||
def FillConsoleOutputAttribute(stream_id, attr, length, start):
|
||||
''' FillConsoleOutputAttribute( hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten )'''
|
||||
handle = handles[stream_id]
|
||||
attribute = WORD(attr)
|
||||
length = DWORD(length)
|
||||
num_written = DWORD(0)
|
||||
# Note that this is hard-coded for ANSI (vs wide) bytes.
|
||||
success = windll.kernel32.FillConsoleOutputAttribute(
|
||||
handle, attribute, length, start, byref(num_written))
|
||||
return success
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
x = GetConsoleScreenBufferInfo(STDOUT)
|
||||
print(x.dwSize)
|
||||
print(x.dwCursorPosition)
|
||||
print(x.wAttributes)
|
||||
print(x.srWindow)
|
||||
print(x.dwMaximumWindowSize)
|
||||
print(x)
|
||||
print('dwSize(height,width) = (%d,%d)' % (x.dwSize.Y, x.dwSize.X))
|
||||
print('dwCursorPosition(y,x) = (%d,%d)' % (x.dwCursorPosition.Y, x.dwCursorPosition.X))
|
||||
print('wAttributes(color) = %d = 0x%02x' % (x.wAttributes, x.wAttributes))
|
||||
print('srWindow(Top,Left)-(Bottom,Right) = (%d,%d)-(%d,%d)' % (x.srWindow.Top, x.srWindow.Left, x.srWindow.Bottom, x.srWindow.Right))
|
||||
print('dwMaximumWindowSize(maxHeight,maxWidth) = (%d,%d)' % (x.dwMaximumWindowSize.Y, x.dwMaximumWindowSize.X))
|
||||
|
||||
|
||||
@@ -22,8 +22,7 @@ class WinStyle(object):
|
||||
class WinTerm(object):
|
||||
|
||||
def __init__(self):
|
||||
self._default = \
|
||||
win32.GetConsoleScreenBufferInfo(win32.STDOUT).wAttributes
|
||||
self._default = win32.GetConsoleScreenBufferInfo(win32.STDOUT).wAttributes
|
||||
self.set_attrs(self._default)
|
||||
self._default_fore = self._fore
|
||||
self._default_back = self._back
|
||||
@@ -67,3 +66,37 @@ class WinTerm(object):
|
||||
handle = win32.STDERR
|
||||
win32.SetConsoleTextAttribute(handle, attrs)
|
||||
|
||||
def set_cursor_position(self, position=None, on_stderr=False):
|
||||
if position is None:
|
||||
#I'm not currently tracking the position, so there is no default.
|
||||
#position = self.get_position()
|
||||
return
|
||||
handle = win32.STDOUT
|
||||
if on_stderr:
|
||||
handle = win32.STDERR
|
||||
win32.SetConsoleCursorPosition(handle, position)
|
||||
|
||||
def erase_data(self, mode=0, on_stderr=False):
|
||||
# 0 (or None) should clear from the cursor to the end of the screen.
|
||||
# 1 should clear from the cursor to the beginning of the screen.
|
||||
# 2 should clear the entire screen. (And maybe move cursor to (1,1)?)
|
||||
#
|
||||
# At the moment, I only support mode 2. From looking at the API, it
|
||||
# should be possible to calculate a different number of bytes to clear,
|
||||
# and to do so relative to the cursor position.
|
||||
if mode[0] not in (2,):
|
||||
return
|
||||
handle = win32.STDOUT
|
||||
if on_stderr:
|
||||
handle = win32.STDERR
|
||||
# here's where we'll home the cursor
|
||||
coord_screen = win32.COORD(0,0)
|
||||
csbi = win32.GetConsoleScreenBufferInfo(handle)
|
||||
# get the number of character cells in the current buffer
|
||||
dw_con_size = csbi.dwSize.X * csbi.dwSize.Y
|
||||
# fill the entire screen with blanks
|
||||
win32.FillConsoleOutputCharacter(handle, ord(' '), dw_con_size, coord_screen)
|
||||
# now set the buffer's attributes accordingly
|
||||
win32.FillConsoleOutputAttribute(handle, self.get_attrs(), dw_con_size, coord_screen );
|
||||
# put the cursor at (0, 0)
|
||||
win32.SetConsoleCursorPosition(handle, (coord_screen.X, coord_screen.Y))
|
||||
|
||||
@@ -9,6 +9,7 @@ This module contains the helper functions for dealing with unix pipes.
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import with_statement
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
+10
-9
@@ -10,6 +10,7 @@ This module contains all the application resource features of clint.
|
||||
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import with_statement
|
||||
|
||||
import errno
|
||||
from os import remove, removedirs
|
||||
@@ -38,7 +39,7 @@ class AppDir(object):
|
||||
|
||||
def __repr__(self):
|
||||
return '<app-dir: %s>' % (self.path)
|
||||
|
||||
|
||||
|
||||
def __getattribute__(self, name):
|
||||
|
||||
@@ -52,11 +53,11 @@ class AppDir(object):
|
||||
"""Raises if operations are carried out on an unconfigured AppDir."""
|
||||
if not self.path:
|
||||
raise NotConfigured()
|
||||
|
||||
|
||||
|
||||
def _create(self):
|
||||
"""Creates current AppDir at AppDir.path."""
|
||||
|
||||
|
||||
self._raise_if_none()
|
||||
if not self._exists:
|
||||
mkdir_p(self.path)
|
||||
@@ -65,7 +66,7 @@ class AppDir(object):
|
||||
|
||||
def open(self, filename, mode='r'):
|
||||
"""Returns file object from given filename."""
|
||||
|
||||
|
||||
self._raise_if_none()
|
||||
fn = path_join(self.path, filename)
|
||||
|
||||
@@ -114,17 +115,17 @@ class AppDir(object):
|
||||
remove(fn)
|
||||
else:
|
||||
removedirs(fn)
|
||||
except OSError, why:
|
||||
except OSError as why:
|
||||
if why.errno == errno.ENOENT:
|
||||
pass
|
||||
else:
|
||||
raise why
|
||||
|
||||
|
||||
|
||||
def read(self, filename, binary=False):
|
||||
"""Returns contents of given file with AppDir.
|
||||
If file doesn't exist, returns None."""
|
||||
|
||||
|
||||
self._raise_if_none()
|
||||
fn = path_join(self.path, filename)
|
||||
|
||||
@@ -160,11 +161,11 @@ log = AppDir()
|
||||
def init(vendor, name):
|
||||
|
||||
global user, site, cache, log
|
||||
|
||||
|
||||
ad = AppDirs(name, vendor)
|
||||
|
||||
user.path = ad.user_data_dir
|
||||
|
||||
|
||||
site.path = ad.site_data_dir
|
||||
cache.path = ad.user_cache_dir
|
||||
log.path = ad.user_log_dir
|
||||
|
||||
@@ -7,9 +7,13 @@ clint.textui
|
||||
This module provides the text output helper system.
|
||||
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import sys
|
||||
if sys.platform.startswith('win'):
|
||||
from ..packages import colorama
|
||||
colorama.init()
|
||||
|
||||
from . import colored
|
||||
from . import progress
|
||||
from . import prompt
|
||||
|
||||
from .core import *
|
||||
|
||||
+109
-35
@@ -11,71 +11,145 @@ This module provides a simple and elegant wrapper for colorama.
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
PY3 = sys.version_info[0] >= 3
|
||||
|
||||
from ..packages import colorama
|
||||
|
||||
|
||||
|
||||
colorama.init(autoreset=True)
|
||||
|
||||
|
||||
__all__ = (
|
||||
'red', 'green', 'yellow', 'blue',
|
||||
'black', 'magenta', 'cyan', 'white'
|
||||
'black', 'magenta', 'cyan', 'white',
|
||||
'clean', 'disable'
|
||||
)
|
||||
|
||||
COLORS = __all__[:-2]
|
||||
|
||||
if 'get_ipython' in dir():
|
||||
"""
|
||||
when ipython is fired lot of variables like _oh, etc are used.
|
||||
There are so many ways to find current python interpreter is ipython.
|
||||
get_ipython is easiest is most appealing for readers to understand.
|
||||
"""
|
||||
DISABLE_COLOR = True
|
||||
else:
|
||||
DISABLE_COLOR = False
|
||||
|
||||
|
||||
class ColoredString(object):
|
||||
"""Enhanced string for __len__ operations on Colored output."""
|
||||
def __init__(self, color, s):
|
||||
def __init__(self, color, s, always_color=False, bold=False):
|
||||
super(ColoredString, self).__init__()
|
||||
self.s = s
|
||||
self.color = color
|
||||
self.color_str = '%s%s%s' % (
|
||||
getattr(colorama.Fore, self.color), self.s, colorama.Fore.RESET)
|
||||
|
||||
self.always_color = always_color
|
||||
self.bold = bold
|
||||
if os.environ.get('CLINT_FORCE_COLOR'):
|
||||
self.always_color = True
|
||||
|
||||
def __getattr__(self, att):
|
||||
def func_help(*args, **kwargs):
|
||||
result = getattr(self.s, att)(*args, **kwargs)
|
||||
try:
|
||||
is_result_string = isinstance(result, basestring)
|
||||
except NameError:
|
||||
is_result_string = isinstance(result, str)
|
||||
if is_result_string:
|
||||
return self._new(result)
|
||||
elif isinstance(result, list):
|
||||
return [self._new(x) for x in result]
|
||||
else:
|
||||
return result
|
||||
return func_help
|
||||
|
||||
@property
|
||||
def color_str(self):
|
||||
style = 'BRIGHT' if self.bold else 'NORMAL'
|
||||
c = '%s%s%s%s%s' % (getattr(colorama.Fore, self.color), getattr(colorama.Style, style), self.s, colorama.Fore.RESET, getattr(colorama.Style, 'NORMAL'))
|
||||
|
||||
if self.always_color:
|
||||
return c
|
||||
elif sys.stdout.isatty() and not DISABLE_COLOR:
|
||||
return c
|
||||
else:
|
||||
return self.s
|
||||
|
||||
|
||||
def __len__(self):
|
||||
return len(self.s)
|
||||
|
||||
|
||||
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
|
||||
|
||||
value = self.color_str
|
||||
if isinstance(value, bytes):
|
||||
return value.decode('utf8')
|
||||
return value
|
||||
|
||||
if PY3:
|
||||
__str__ = __unicode__
|
||||
else:
|
||||
def __str__(self):
|
||||
value = self.color_str
|
||||
if isinstance(value, bytes):
|
||||
return value
|
||||
return value.encode('utf8')
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self.color_str)
|
||||
|
||||
def __add__(self, other):
|
||||
return str(self.color_str) + str(other)
|
||||
|
||||
|
||||
def __radd__(self, other):
|
||||
return str(other) + str(self.color_str)
|
||||
|
||||
|
||||
def __mul__(self, other):
|
||||
return (self.color_str * other)
|
||||
|
||||
def _new(self, s):
|
||||
return ColoredString(self.color, s)
|
||||
|
||||
|
||||
def black(string):
|
||||
return ColoredString('BLACK', string)
|
||||
def clean(s):
|
||||
strip = re.compile("([^-_a-zA-Z0-9!@#%&=,/'\";:~`\$\^\*\(\)\+\[\]\.\{\}\|\?\<\>\\]+|[^\s]+)")
|
||||
txt = strip.sub('', str(s))
|
||||
|
||||
def red(string):
|
||||
return ColoredString('RED', string)
|
||||
strip = re.compile(r'\[\d+m')
|
||||
txt = strip.sub('', txt)
|
||||
|
||||
def green(string):
|
||||
return ColoredString('GREEN', string)
|
||||
return txt
|
||||
|
||||
def yellow(string):
|
||||
return ColoredString('YELLOW', string)
|
||||
|
||||
def blue(string):
|
||||
return ColoredString('BLUE', string)
|
||||
def black(string, always=False, bold=False):
|
||||
return ColoredString('BLACK', string, always_color=always, bold=bold)
|
||||
|
||||
def magenta(string):
|
||||
return ColoredString('MAGENTA', string)
|
||||
def red(string, always=False, bold=False):
|
||||
return ColoredString('RED', string, always_color=always, bold=bold)
|
||||
|
||||
def cyan(string):
|
||||
return ColoredString('CYAN', string)
|
||||
def green(string, always=False, bold=False):
|
||||
return ColoredString('GREEN', string, always_color=always, bold=bold)
|
||||
|
||||
def white(string):
|
||||
return ColoredString('WHITE', string)
|
||||
def yellow(string, always=False, bold=False):
|
||||
return ColoredString('YELLOW', string, always_color=always, bold=bold)
|
||||
|
||||
def blue(string, always=False, bold=False):
|
||||
return ColoredString('BLUE', string, always_color=always, bold=bold)
|
||||
|
||||
def magenta(string, always=False, bold=False):
|
||||
return ColoredString('MAGENTA', string, always_color=always, bold=bold)
|
||||
|
||||
def cyan(string, always=False, bold=False):
|
||||
return ColoredString('CYAN', string, always_color=always, bold=bold)
|
||||
|
||||
def white(string, always=False, bold=False):
|
||||
return ColoredString('WHITE', string, always_color=always, bold=bold)
|
||||
|
||||
def disable():
|
||||
"""Disables colors."""
|
||||
global DISABLE_COLOR
|
||||
|
||||
DISABLE_COLOR = True
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
clint.textui.columns
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Core TextUI functionality for column formatting.
|
||||
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from .formatters import max_width, min_width
|
||||
from ..utils import tsplit
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
NEWLINES = ('\n', '\r', '\r\n')
|
||||
|
||||
|
||||
|
||||
def _find_unix_console_width():
|
||||
import termios, fcntl, struct, sys
|
||||
|
||||
# fcntl.ioctl will fail if stdout is not a tty
|
||||
if not sys.stdout.isatty():
|
||||
return None
|
||||
|
||||
s = struct.pack("HHHH", 0, 0, 0, 0)
|
||||
fd_stdout = sys.stdout.fileno()
|
||||
size = fcntl.ioctl(fd_stdout, termios.TIOCGWINSZ, s)
|
||||
height, width = struct.unpack("HHHH", size)[:2]
|
||||
return width
|
||||
|
||||
|
||||
def _find_windows_console_width():
|
||||
# http://code.activestate.com/recipes/440694/
|
||||
from ctypes import windll, create_string_buffer
|
||||
STDIN, STDOUT, STDERR = -10, -11, -12
|
||||
|
||||
h = windll.kernel32.GetStdHandle(STDERR)
|
||||
csbi = create_string_buffer(22)
|
||||
res = windll.kernel32.GetConsoleScreenBufferInfo(h, csbi)
|
||||
|
||||
if res:
|
||||
import struct
|
||||
(bufx, bufy, curx, cury, wattr,
|
||||
left, top, right, bottom,
|
||||
maxx, maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw)
|
||||
sizex = right - left + 1
|
||||
sizey = bottom - top + 1
|
||||
return sizex
|
||||
|
||||
|
||||
def console_width(kwargs):
|
||||
""""Determine console_width."""
|
||||
|
||||
if sys.platform.startswith('win'):
|
||||
console_width = _find_windows_console_width()
|
||||
else:
|
||||
console_width = _find_unix_console_width()
|
||||
|
||||
_width = kwargs.get('width', None)
|
||||
if _width:
|
||||
console_width = _width
|
||||
else:
|
||||
if not console_width:
|
||||
console_width = 80
|
||||
|
||||
return console_width
|
||||
|
||||
|
||||
|
||||
def columns(*cols, **kwargs):
|
||||
|
||||
columns = list(cols)
|
||||
|
||||
cwidth = console_width(kwargs)
|
||||
|
||||
_big_col = None
|
||||
_total_cols = 0
|
||||
|
||||
|
||||
for i, (string, width) in enumerate(cols):
|
||||
|
||||
if width is not None:
|
||||
_total_cols += (width + 1)
|
||||
cols[i][0] = max_width(string, width).split('\n')
|
||||
else:
|
||||
_big_col = i
|
||||
|
||||
if _big_col:
|
||||
cols[_big_col][1] = (cwidth - _total_cols) - len(cols)
|
||||
cols[_big_col][0] = max_width(cols[_big_col][0], cols[_big_col][1]).split('\n')
|
||||
|
||||
height = len(max([c[0] for c in cols], key=len))
|
||||
|
||||
for i, (strings, width) in enumerate(cols):
|
||||
|
||||
for _ in range(height - len(strings)):
|
||||
cols[i][0].append('')
|
||||
|
||||
for j, string in enumerate(strings):
|
||||
cols[i][0][j] = min_width(string, width)
|
||||
|
||||
stack = [c[0] for c in cols]
|
||||
_out = []
|
||||
|
||||
for i in range(height):
|
||||
_row = ''
|
||||
|
||||
for col in stack:
|
||||
_row += col[i]
|
||||
_row += ' '
|
||||
|
||||
_out.append(_row)
|
||||
# try:
|
||||
# pass
|
||||
# except:
|
||||
# pass
|
||||
|
||||
|
||||
|
||||
|
||||
return '\n'.join(_out)
|
||||
|
||||
|
||||
# string = max_width(string, width)
|
||||
# string = min_width(string, width)
|
||||
# pass
|
||||
# columns.append()
|
||||
|
||||
|
||||
|
||||
###########################
|
||||
|
||||
a = 'this is text that goes into a small column\n cool?'
|
||||
b = 'this is other text\nothertext\nothertext'
|
||||
|
||||
#columns((a, 10), (b, 20), (b, None))
|
||||
+56
-54
@@ -13,76 +13,78 @@ from __future__ import absolute_import
|
||||
|
||||
import sys
|
||||
|
||||
from .progress import progressbar
|
||||
from contextlib import contextmanager
|
||||
|
||||
from .formatters import max_width, min_width
|
||||
from .cols import columns
|
||||
from ..utils import tsplit
|
||||
|
||||
|
||||
__all__ = ('puts', 'puts_err', 'indent', 'progressbar')
|
||||
__all__ = ('puts', 'puts_err', 'indent', 'dedent', 'columns', 'max_width',
|
||||
'min_width', 'STDOUT', 'STDERR')
|
||||
|
||||
|
||||
STDOUT = sys.stdout.write
|
||||
STDERR = sys.stderr.write
|
||||
|
||||
NEWLINES = ('\n', '\r', '\r\n')
|
||||
|
||||
class Writer(object):
|
||||
"""WriterUtilized by context managers."""
|
||||
INDENT_STRINGS = []
|
||||
|
||||
shared = dict(indent_level=0, indent_strings=[])
|
||||
# Private
|
||||
|
||||
|
||||
def __init__(self, indent=0, quote='', indent_char=' '):
|
||||
self.indent = indent
|
||||
self.indent_char = indent_char
|
||||
self.indent_quote = quote
|
||||
if self.indent > 0:
|
||||
self.indent_string = ''.join((
|
||||
str(quote),
|
||||
(self.indent_char * (indent - len(self.indent_quote)))
|
||||
))
|
||||
else:
|
||||
self.indent_string = ''.join((
|
||||
('\x08' * (-1 * (indent - len(self.indent_quote)))),
|
||||
str(quote))
|
||||
)
|
||||
|
||||
if len(self.indent_string):
|
||||
self.shared['indent_strings'].append(self.indent_string)
|
||||
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
|
||||
def __exit__(self, type, value, traceback):
|
||||
self.shared['indent_strings'].pop()
|
||||
|
||||
|
||||
def __call__(self, s, newline=True, stream=STDOUT):
|
||||
|
||||
if newline:
|
||||
s = tsplit(s, ('\n', '\r', '\r\n'))
|
||||
indent = ''.join(self.shared['indent_strings'])
|
||||
|
||||
s = ('\n' + indent).join(s)
|
||||
|
||||
_str = ''.join((
|
||||
''.join(self.shared['indent_strings']),
|
||||
str(s),
|
||||
'\n' if newline else ''
|
||||
def _indent(indent=0, quote='', indent_char=' '):
|
||||
"""Indent util function, compute new indent_string"""
|
||||
if indent > 0:
|
||||
indent_string = ''.join((
|
||||
str(quote),
|
||||
(indent_char * (indent - len(quote)))
|
||||
))
|
||||
stream(_str)
|
||||
else:
|
||||
indent_string = ''.join((
|
||||
('\x08' * (-1 * (indent - len(quote)))),
|
||||
str(quote))
|
||||
)
|
||||
|
||||
if len(indent_string):
|
||||
INDENT_STRINGS.append(indent_string)
|
||||
|
||||
def puts(s, newline=True):
|
||||
"""Prints given string to stdout via Writer interface."""
|
||||
Writer()(s, stream=STDOUT)
|
||||
# Public
|
||||
|
||||
def puts(s='', newline=True, stream=STDOUT):
|
||||
"""Prints given string to stdout."""
|
||||
if newline:
|
||||
s = tsplit(s, NEWLINES)
|
||||
s = map(str, s)
|
||||
indent = ''.join(INDENT_STRINGS)
|
||||
|
||||
def puts_err(s, newline=True):
|
||||
"""Prints given string to stderr via Writer interface."""
|
||||
Writer()(s, stream=STDERR)
|
||||
s = (str('\n' + indent)).join(s)
|
||||
|
||||
_str = ''.join((
|
||||
''.join(INDENT_STRINGS),
|
||||
str(s),
|
||||
'\n' if newline else ''
|
||||
))
|
||||
stream(_str)
|
||||
|
||||
def puts_err(s='', newline=True, stream=STDERR):
|
||||
"""Prints given string to stderr."""
|
||||
puts(s, newline, stream)
|
||||
|
||||
def dedent():
|
||||
"""Dedent next strings, use only if you use indent otherwise than as a
|
||||
context."""
|
||||
INDENT_STRINGS.pop()
|
||||
|
||||
@contextmanager
|
||||
def _indent_context():
|
||||
"""Indentation context manager."""
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
dedent()
|
||||
|
||||
def indent(indent=4, quote=''):
|
||||
"""Indentation context manager."""
|
||||
return Writer(indent=indent, quote=quote)
|
||||
"""Indentation manager, return an indentation context manager."""
|
||||
_indent(indent, quote)
|
||||
return _indent_context()
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
clint.textui.formatters
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Core TextUI functionality for text formatting.
|
||||
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from .colored import ColoredString, clean
|
||||
from ..utils import tsplit, schunk
|
||||
|
||||
|
||||
NEWLINES = ('\n', '\r', '\r\n')
|
||||
|
||||
|
||||
def min_width(string, cols, padding=' '):
|
||||
"""Returns given string with right padding."""
|
||||
|
||||
is_color = isinstance(string, ColoredString)
|
||||
|
||||
stack = tsplit(str(string), NEWLINES)
|
||||
|
||||
for i, substring in enumerate(stack):
|
||||
_sub = clean(substring).ljust((cols + 0), padding)
|
||||
if is_color:
|
||||
_sub = (_sub.replace(clean(substring), substring))
|
||||
stack[i] = _sub
|
||||
|
||||
return '\n'.join(stack)
|
||||
|
||||
|
||||
def max_width(string, cols, separator='\n'):
|
||||
"""Returns a freshly formatted """
|
||||
|
||||
is_color = isinstance(string, ColoredString)
|
||||
|
||||
if is_color:
|
||||
offset = 10
|
||||
string_copy = string._new('')
|
||||
else:
|
||||
offset = 0
|
||||
|
||||
stack = tsplit(string, NEWLINES)
|
||||
|
||||
for i, substring in enumerate(stack):
|
||||
stack[i] = substring.split()
|
||||
|
||||
_stack = []
|
||||
|
||||
for row in stack:
|
||||
_row = ['',]
|
||||
_row_i = 0
|
||||
|
||||
for word in row:
|
||||
if (len(_row[_row_i]) + len(word)) < (cols + offset):
|
||||
_row[_row_i] += word
|
||||
_row[_row_i] += ' '
|
||||
|
||||
elif len(word) > (cols - offset):
|
||||
|
||||
# ensure empty row
|
||||
if len(_row[_row_i]):
|
||||
_row.append('')
|
||||
_row_i += 1
|
||||
|
||||
chunks = schunk(word, (cols + offset))
|
||||
for i, chunk in enumerate(chunks):
|
||||
if not (i + 1) == len(chunks):
|
||||
_row[_row_i] += chunk
|
||||
_row.append('')
|
||||
_row_i += 1
|
||||
else:
|
||||
_row[_row_i] += chunk
|
||||
_row[_row_i] += ' '
|
||||
else:
|
||||
_row.append('')
|
||||
_row_i += 1
|
||||
_row[_row_i] += word
|
||||
_row[_row_i] += ' '
|
||||
|
||||
_row = map(str, _row)
|
||||
_stack.append(separator.join(_row))
|
||||
|
||||
_s = '\n'.join(_stack)
|
||||
if is_color:
|
||||
_s = string_copy._new(_s)
|
||||
return _s
|
||||
+150
-11
@@ -11,22 +11,161 @@ This module provides the progressbar functionality.
|
||||
from __future__ import absolute_import
|
||||
|
||||
import sys
|
||||
import time
|
||||
|
||||
STREAM = sys.stderr
|
||||
|
||||
BAR_TEMPLATE = '%s[%s%s] %i/%i - %s\r'
|
||||
MILL_TEMPLATE = '%s %s %i/%i\r'
|
||||
|
||||
DOTS_CHAR = '.'
|
||||
BAR_FILLED_CHAR = '#'
|
||||
BAR_EMPTY_CHAR = ' '
|
||||
MILL_CHARS = ['|', '/', '-', '\\']
|
||||
|
||||
# How long to wait before recalculating the ETA
|
||||
ETA_INTERVAL = 1
|
||||
# How many intervals (excluding the current one) to calculate the simple moving
|
||||
# average
|
||||
ETA_SMA_WINDOW = 9
|
||||
|
||||
|
||||
def progressbar(it, prefix='', size=32, hide=False):
|
||||
class Bar(object):
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
self.done()
|
||||
return False # we're not suppressing exceptions
|
||||
|
||||
def __init__(self, label='', width=32, hide=None, empty_char=BAR_EMPTY_CHAR,
|
||||
filled_char=BAR_FILLED_CHAR, expected_size=None, every=1):
|
||||
self.label = label
|
||||
self.width = width
|
||||
self.hide = hide
|
||||
# Only show bar in terminals by default (better for piping, logging etc.)
|
||||
if hide is None:
|
||||
try:
|
||||
self.hide = not STREAM.isatty()
|
||||
except AttributeError: # output does not support isatty()
|
||||
self.hide = True
|
||||
self.empty_char = empty_char
|
||||
self.filled_char = filled_char
|
||||
self.expected_size = expected_size
|
||||
self.every = every
|
||||
self.start = time.time()
|
||||
self.ittimes = []
|
||||
self.eta = 0
|
||||
self.etadelta = time.time()
|
||||
self.etadisp = self.format_time(self.eta)
|
||||
self.last_progress = 0
|
||||
if (self.expected_size):
|
||||
self.show(0)
|
||||
|
||||
def show(self, progress, count=None):
|
||||
if count is not None:
|
||||
self.expected_size = count
|
||||
if self.expected_size is None:
|
||||
raise Exception("expected_size not initialized")
|
||||
self.last_progress = progress
|
||||
if (time.time() - self.etadelta) > ETA_INTERVAL:
|
||||
self.etadelta = time.time()
|
||||
self.ittimes = \
|
||||
self.ittimes[-ETA_SMA_WINDOW:] + \
|
||||
[-(self.start - time.time()) / (progress+1)]
|
||||
self.eta = \
|
||||
sum(self.ittimes) / float(len(self.ittimes)) * \
|
||||
(self.expected_size - progress)
|
||||
self.etadisp = self.format_time(self.eta)
|
||||
x = int(self.width * progress / self.expected_size)
|
||||
if not self.hide:
|
||||
if ((progress % self.every) == 0 or # True every "every" updates
|
||||
(progress == self.expected_size)): # And when we're done
|
||||
STREAM.write(BAR_TEMPLATE % (
|
||||
self.label, self.filled_char * x,
|
||||
self.empty_char * (self.width - x), progress,
|
||||
self.expected_size, self.etadisp))
|
||||
STREAM.flush()
|
||||
|
||||
def done(self):
|
||||
self.elapsed = time.time() - self.start
|
||||
elapsed_disp = self.format_time(self.elapsed)
|
||||
if not self.hide:
|
||||
# Print completed bar with elapsed time
|
||||
STREAM.write(BAR_TEMPLATE % (
|
||||
self.label, self.filled_char * self.width,
|
||||
self.empty_char * 0, self.last_progress,
|
||||
self.expected_size, elapsed_disp))
|
||||
STREAM.write('\n')
|
||||
STREAM.flush()
|
||||
|
||||
def format_time(self, seconds):
|
||||
return time.strftime('%H:%M:%S', time.gmtime(seconds))
|
||||
|
||||
|
||||
def bar(it, label='', width=32, hide=None, empty_char=BAR_EMPTY_CHAR,
|
||||
filled_char=BAR_FILLED_CHAR, expected_size=None, every=1):
|
||||
"""Progress iterator. Wrap your iterables with it."""
|
||||
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()
|
||||
|
||||
count = len(it) if expected_size is None else expected_size
|
||||
|
||||
with Bar(label=label, width=width, hide=hide, empty_char=BAR_EMPTY_CHAR,
|
||||
filled_char=BAR_FILLED_CHAR, expected_size=count, every=every) \
|
||||
as bar:
|
||||
for i, item in enumerate(it):
|
||||
yield item
|
||||
bar.show(i + 1)
|
||||
|
||||
|
||||
def dots(it, label='', hide=None, every=1):
|
||||
"""Progress iterator. Prints a dot for each item being iterated"""
|
||||
|
||||
count = 0
|
||||
|
||||
if not hide:
|
||||
STREAM.write(label)
|
||||
|
||||
for i, item in enumerate(it):
|
||||
if not hide:
|
||||
if i % every == 0: # True every "every" updates
|
||||
STREAM.write(DOTS_CHAR)
|
||||
sys.stderr.flush()
|
||||
|
||||
count += 1
|
||||
|
||||
yield item
|
||||
|
||||
STREAM.write('\n')
|
||||
STREAM.flush()
|
||||
|
||||
|
||||
def mill(it, label='', hide=None, expected_size=None, every=1):
|
||||
"""Progress iterator. Prints a mill while iterating over the items."""
|
||||
|
||||
def _mill_char(_i):
|
||||
if _i >= count:
|
||||
return ' '
|
||||
else:
|
||||
return MILL_CHARS[(_i // every) % len(MILL_CHARS)]
|
||||
|
||||
def _show(_i):
|
||||
if not hide:
|
||||
if ((_i % every) == 0 or # True every "every" updates
|
||||
(_i == count)): # And when we're done
|
||||
|
||||
STREAM.write(MILL_TEMPLATE % (
|
||||
label, _mill_char(_i), _i, count))
|
||||
STREAM.flush()
|
||||
|
||||
count = len(it) if expected_size is None else expected_size
|
||||
|
||||
if count:
|
||||
_show(0)
|
||||
|
||||
for i, item in enumerate(it):
|
||||
yield item
|
||||
_show(i+1)
|
||||
_show(i + 1)
|
||||
|
||||
if not hide:
|
||||
sys.stdout.write("\n")
|
||||
sys.stdout.flush()
|
||||
STREAM.write('\n')
|
||||
STREAM.flush()
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
# -*- coding: utf8 -*-
|
||||
|
||||
"""
|
||||
clint.textui.prompt
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Module for simple interactive prompts handling
|
||||
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import, print_function
|
||||
|
||||
from re import match, I
|
||||
|
||||
from .core import puts
|
||||
from .colored import yellow
|
||||
from .validators import RegexValidator
|
||||
|
||||
try:
|
||||
raw_input
|
||||
except NameError:
|
||||
raw_input = input
|
||||
|
||||
|
||||
def yn(prompt, default='y', batch=False):
|
||||
# A sanity check against default value
|
||||
# If not y/n then y is assumed
|
||||
if default not in ['y', 'n']:
|
||||
default = 'y'
|
||||
|
||||
# Let's build the prompt
|
||||
choicebox = '[Y/n]' if default == 'y' else '[y/N]'
|
||||
prompt = prompt + ' ' + choicebox + ' '
|
||||
|
||||
# If input is not a yes/no variant or empty
|
||||
# keep asking
|
||||
while True:
|
||||
# If batch option is True then auto reply
|
||||
# with default input
|
||||
if not batch:
|
||||
input = raw_input(prompt).strip()
|
||||
else:
|
||||
print(prompt)
|
||||
input = ''
|
||||
|
||||
# If input is empty default choice is assumed
|
||||
# so we return True
|
||||
if input == '':
|
||||
return True
|
||||
|
||||
# Given 'yes' as input if default choice is y
|
||||
# then return True, False otherwise
|
||||
if match('y(?:es)?', input, I):
|
||||
return True if default == 'y' else False
|
||||
|
||||
# Given 'no' as input if default choice is n
|
||||
# then return True, False otherwise
|
||||
elif match('n(?:o)?', input, I):
|
||||
return True if default == 'n' else False
|
||||
|
||||
|
||||
def query(prompt, default='', validators=None, batch=False):
|
||||
# Set the nonempty validator as default
|
||||
if validators is None:
|
||||
validators = [RegexValidator(r'.+')]
|
||||
|
||||
# Let's build the prompt
|
||||
if prompt[-1] is not ' ':
|
||||
prompt += ' '
|
||||
|
||||
if default:
|
||||
prompt += '[' + default + '] '
|
||||
|
||||
# If input is not valid keep asking
|
||||
while True:
|
||||
# If batch option is True then auto reply
|
||||
# with default input
|
||||
if not batch:
|
||||
user_input = raw_input(prompt).strip() or default
|
||||
else:
|
||||
print(prompt)
|
||||
user_input = ''
|
||||
|
||||
# Validate the user input
|
||||
try:
|
||||
for validator in validators:
|
||||
user_input = validator(user_input)
|
||||
return user_input
|
||||
except Exception as e:
|
||||
puts(yellow(e.message))
|
||||
@@ -0,0 +1,104 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
clint.textui.validators
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Core TextUI functionality for input validation.
|
||||
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
|
||||
# Useful for very coarse version differentiation.
|
||||
PY2 = sys.version_info[0] == 2
|
||||
PY3 = sys.version_info[0] == 3
|
||||
|
||||
if PY3:
|
||||
string_types = str,
|
||||
else:
|
||||
string_types = basestring,
|
||||
|
||||
|
||||
class ValidationError(Exception):
|
||||
"""An error while validating data."""
|
||||
|
||||
def __init__(self, message):
|
||||
self.message = message
|
||||
self.error_list = [self]
|
||||
|
||||
|
||||
class RegexValidator(object):
|
||||
regex = ''
|
||||
message = 'Enter a valid value.'
|
||||
|
||||
def __init__(self, regex=None, message=None):
|
||||
if regex is not None:
|
||||
self.regex = regex
|
||||
if message is not None:
|
||||
self.message = message
|
||||
|
||||
# Compile the regex if it was not passed pre-compiled.
|
||||
if isinstance(self.regex, string_types):
|
||||
self.regex = re.compile(self.regex)
|
||||
|
||||
def __call__(self, value):
|
||||
"""
|
||||
Validates that the input matches the regular expression.
|
||||
"""
|
||||
if not self.regex.search(value):
|
||||
raise ValidationError(self.message)
|
||||
return value
|
||||
|
||||
|
||||
class PathValidator(object):
|
||||
message = 'Enter a valid path.'
|
||||
|
||||
def __init__(self, message=None):
|
||||
if message is not None:
|
||||
self.message = message
|
||||
|
||||
def __call__(self, value):
|
||||
"""
|
||||
Validates that the input is a valid directory.
|
||||
"""
|
||||
if not os.path.isdir(value):
|
||||
raise ValidationError(self.message)
|
||||
return value
|
||||
|
||||
|
||||
class FileValidator(object):
|
||||
message = 'Enter a valid file.'
|
||||
|
||||
def __init__(self, message=None):
|
||||
if message is not None:
|
||||
self.message = message
|
||||
|
||||
def __call__(self, value):
|
||||
"""
|
||||
Validates that the input is a valid file.
|
||||
"""
|
||||
if not os.path.isfile(value):
|
||||
raise ValidationError(self.message)
|
||||
return value
|
||||
|
||||
|
||||
class IntegerValidator(object):
|
||||
message = 'Enter a valid number.'
|
||||
|
||||
def __init__(self, message=None):
|
||||
if message is not None:
|
||||
self.message = message
|
||||
|
||||
def __call__(self, value):
|
||||
"""
|
||||
Validates that the input is a integer.
|
||||
"""
|
||||
try:
|
||||
return int(value)
|
||||
except (TypeError, ValueError):
|
||||
raise ValidationError(self.message)
|
||||
+36
-12
@@ -9,10 +9,35 @@ 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):
|
||||
@@ -36,16 +61,15 @@ 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
|
||||
if len(delimiters) < 1:
|
||||
return [string,]
|
||||
final_delimiter = delimiters[0]
|
||||
for i in delimiters[1:]:
|
||||
string = string.replace(i, final_delimiter)
|
||||
return string.split(final_delimiter)
|
||||
|
||||
|
||||
def schunk(string, size):
|
||||
"""Splits string into n sized chunks."""
|
||||
return [string[i:i+size] for i in range(0, len(string), size)]
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
_build/*
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
# Makefile for Sphinx documentation
|
||||
#
|
||||
|
||||
# You can set these variables from the command line.
|
||||
SPHINXOPTS =
|
||||
SPHINXBUILD = sphinx-build
|
||||
PAPER =
|
||||
BUILDDIR = _build
|
||||
|
||||
# Internal variables.
|
||||
PAPEROPT_a4 = -D latex_paper_size=a4
|
||||
PAPEROPT_letter = -D latex_paper_size=letter
|
||||
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
|
||||
|
||||
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest
|
||||
|
||||
help:
|
||||
@echo "Please use \`make <target>' where <target> is one of"
|
||||
@echo " html to make standalone HTML files"
|
||||
@echo " dirhtml to make HTML files named index.html in directories"
|
||||
@echo " singlehtml to make a single large HTML file"
|
||||
@echo " pickle to make pickle files"
|
||||
@echo " json to make JSON files"
|
||||
@echo " htmlhelp to make HTML files and a HTML help project"
|
||||
@echo " qthelp to make HTML files and a qthelp project"
|
||||
@echo " devhelp to make HTML files and a Devhelp project"
|
||||
@echo " epub to make an epub"
|
||||
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
|
||||
@echo " latexpdf to make LaTeX files and run them through pdflatex"
|
||||
@echo " text to make text files"
|
||||
@echo " man to make manual pages"
|
||||
@echo " changes to make an overview of all changed/added/deprecated items"
|
||||
@echo " linkcheck to check all external links for integrity"
|
||||
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
|
||||
|
||||
clean:
|
||||
-rm -rf $(BUILDDIR)/*
|
||||
|
||||
html:
|
||||
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
|
||||
|
||||
dirhtml:
|
||||
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
|
||||
|
||||
singlehtml:
|
||||
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
|
||||
@echo
|
||||
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
|
||||
|
||||
pickle:
|
||||
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
|
||||
@echo
|
||||
@echo "Build finished; now you can process the pickle files."
|
||||
|
||||
json:
|
||||
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
|
||||
@echo
|
||||
@echo "Build finished; now you can process the JSON files."
|
||||
|
||||
htmlhelp:
|
||||
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
|
||||
@echo
|
||||
@echo "Build finished; now you can run HTML Help Workshop with the" \
|
||||
".hhp project file in $(BUILDDIR)/htmlhelp."
|
||||
|
||||
qthelp:
|
||||
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
|
||||
@echo
|
||||
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
|
||||
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
|
||||
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/osxpython.qhcp"
|
||||
@echo "To view the help file:"
|
||||
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/osxpython.qhc"
|
||||
|
||||
devhelp:
|
||||
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
|
||||
@echo
|
||||
@echo "Build finished."
|
||||
@echo "To view the help file:"
|
||||
@echo "# mkdir -p $$HOME/.local/share/devhelp/osxpython"
|
||||
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/osxpython"
|
||||
@echo "# devhelp"
|
||||
|
||||
epub:
|
||||
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
|
||||
@echo
|
||||
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
|
||||
|
||||
latex:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo
|
||||
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
|
||||
@echo "Run \`make' in that directory to run these through (pdf)latex" \
|
||||
"(use \`make latexpdf' here to do that automatically)."
|
||||
|
||||
latexpdf:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo "Running LaTeX files through pdflatex..."
|
||||
make -C $(BUILDDIR)/latex all-pdf
|
||||
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
|
||||
|
||||
text:
|
||||
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
|
||||
@echo
|
||||
@echo "Build finished. The text files are in $(BUILDDIR)/text."
|
||||
|
||||
man:
|
||||
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
|
||||
@echo
|
||||
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
|
||||
|
||||
changes:
|
||||
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
|
||||
@echo
|
||||
@echo "The overview file is in $(BUILDDIR)/changes."
|
||||
|
||||
linkcheck:
|
||||
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
|
||||
@echo
|
||||
@echo "Link check complete; look for any errors in the above output " \
|
||||
"or in $(BUILDDIR)/linkcheck/output.txt."
|
||||
|
||||
doctest:
|
||||
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
|
||||
@echo "Testing of doctests in the sources finished, look at the " \
|
||||
"results in $(BUILDDIR)/doctest/output.txt."
|
||||
Vendored
Vendored
@@ -0,0 +1,3 @@
|
||||
*.pyc
|
||||
*.pyo
|
||||
.DS_Store
|
||||
Vendored
+45
@@ -0,0 +1,45 @@
|
||||
Modifications:
|
||||
|
||||
Copyright (c) 2010 Kenneth Reitz.
|
||||
|
||||
|
||||
Original Project:
|
||||
|
||||
Copyright (c) 2010 by Armin Ronacher.
|
||||
|
||||
|
||||
Some rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms of the theme, with or
|
||||
without modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials provided
|
||||
with the distribution.
|
||||
|
||||
* The names of the contributors may not be used to endorse or
|
||||
promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
We kindly ask you to only use these themes in an unmodified manner just
|
||||
for Flask and Flask-related products, not for unrelated projects. If you
|
||||
like the visual style and want to use it for your own projects, please
|
||||
consider making some larger changes to the themes (such as changing
|
||||
font faces, sizes, colors or margins).
|
||||
|
||||
THIS THEME IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS THEME, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
krTheme Sphinx Style
|
||||
====================
|
||||
|
||||
This repository contains sphinx styles Kenneth Reitz uses in most of
|
||||
his projects. It is a drivative of Mitsuhiko's themes for Flask and Flask related
|
||||
projects. To use this style in your Sphinx documentation, follow
|
||||
this guide:
|
||||
|
||||
1. put this folder as _themes into your docs folder. Alternatively
|
||||
you can also use git submodules to check out the contents there.
|
||||
|
||||
2. add this to your conf.py: ::
|
||||
|
||||
sys.path.append(os.path.abspath('_themes'))
|
||||
html_theme_path = ['_themes']
|
||||
html_theme = 'flask'
|
||||
|
||||
The following themes exist:
|
||||
|
||||
**kr**
|
||||
the standard flask documentation theme for large projects
|
||||
|
||||
**kr_small**
|
||||
small one-page theme. Intended to be used by very small addon libraries.
|
||||
|
||||
Vendored
+86
@@ -0,0 +1,86 @@
|
||||
# flasky extensions. flasky pygments style based on tango style
|
||||
from pygments.style import Style
|
||||
from pygments.token import Keyword, Name, Comment, String, Error, \
|
||||
Number, Operator, Generic, Whitespace, Punctuation, Other, Literal
|
||||
|
||||
|
||||
class FlaskyStyle(Style):
|
||||
background_color = "#f8f8f8"
|
||||
default_style = ""
|
||||
|
||||
styles = {
|
||||
# No corresponding class for the following:
|
||||
#Text: "", # class: ''
|
||||
Whitespace: "underline #f8f8f8", # class: 'w'
|
||||
Error: "#a40000 border:#ef2929", # class: 'err'
|
||||
Other: "#000000", # class 'x'
|
||||
|
||||
Comment: "italic #8f5902", # class: 'c'
|
||||
Comment.Preproc: "noitalic", # class: 'cp'
|
||||
|
||||
Keyword: "bold #004461", # class: 'k'
|
||||
Keyword.Constant: "bold #004461", # class: 'kc'
|
||||
Keyword.Declaration: "bold #004461", # class: 'kd'
|
||||
Keyword.Namespace: "bold #004461", # class: 'kn'
|
||||
Keyword.Pseudo: "bold #004461", # class: 'kp'
|
||||
Keyword.Reserved: "bold #004461", # class: 'kr'
|
||||
Keyword.Type: "bold #004461", # class: 'kt'
|
||||
|
||||
Operator: "#582800", # class: 'o'
|
||||
Operator.Word: "bold #004461", # class: 'ow' - like keywords
|
||||
|
||||
Punctuation: "bold #000000", # class: 'p'
|
||||
|
||||
# because special names such as Name.Class, Name.Function, etc.
|
||||
# are not recognized as such later in the parsing, we choose them
|
||||
# to look the same as ordinary variables.
|
||||
Name: "#000000", # class: 'n'
|
||||
Name.Attribute: "#c4a000", # class: 'na' - to be revised
|
||||
Name.Builtin: "#004461", # class: 'nb'
|
||||
Name.Builtin.Pseudo: "#3465a4", # class: 'bp'
|
||||
Name.Class: "#000000", # class: 'nc' - to be revised
|
||||
Name.Constant: "#000000", # class: 'no' - to be revised
|
||||
Name.Decorator: "#888", # class: 'nd' - to be revised
|
||||
Name.Entity: "#ce5c00", # class: 'ni'
|
||||
Name.Exception: "bold #cc0000", # class: 'ne'
|
||||
Name.Function: "#000000", # class: 'nf'
|
||||
Name.Property: "#000000", # class: 'py'
|
||||
Name.Label: "#f57900", # class: 'nl'
|
||||
Name.Namespace: "#000000", # class: 'nn' - to be revised
|
||||
Name.Other: "#000000", # class: 'nx'
|
||||
Name.Tag: "bold #004461", # class: 'nt' - like a keyword
|
||||
Name.Variable: "#000000", # class: 'nv' - to be revised
|
||||
Name.Variable.Class: "#000000", # class: 'vc' - to be revised
|
||||
Name.Variable.Global: "#000000", # class: 'vg' - to be revised
|
||||
Name.Variable.Instance: "#000000", # class: 'vi' - to be revised
|
||||
|
||||
Number: "#990000", # class: 'm'
|
||||
|
||||
Literal: "#000000", # class: 'l'
|
||||
Literal.Date: "#000000", # class: 'ld'
|
||||
|
||||
String: "#4e9a06", # class: 's'
|
||||
String.Backtick: "#4e9a06", # class: 'sb'
|
||||
String.Char: "#4e9a06", # class: 'sc'
|
||||
String.Doc: "italic #8f5902", # class: 'sd' - like a comment
|
||||
String.Double: "#4e9a06", # class: 's2'
|
||||
String.Escape: "#4e9a06", # class: 'se'
|
||||
String.Heredoc: "#4e9a06", # class: 'sh'
|
||||
String.Interpol: "#4e9a06", # class: 'si'
|
||||
String.Other: "#4e9a06", # class: 'sx'
|
||||
String.Regex: "#4e9a06", # class: 'sr'
|
||||
String.Single: "#4e9a06", # class: 's1'
|
||||
String.Symbol: "#4e9a06", # class: 'ss'
|
||||
|
||||
Generic: "#000000", # class: 'g'
|
||||
Generic.Deleted: "#a40000", # class: 'gd'
|
||||
Generic.Emph: "italic #000000", # class: 'ge'
|
||||
Generic.Error: "#ef2929", # class: 'gr'
|
||||
Generic.Heading: "bold #000080", # class: 'gh'
|
||||
Generic.Inserted: "#00A000", # class: 'gi'
|
||||
Generic.Output: "#888", # class: 'go'
|
||||
Generic.Prompt: "#745334", # class: 'gp'
|
||||
Generic.Strong: "bold #000000", # class: 'gs'
|
||||
Generic.Subheading: "bold #800080", # class: 'gu'
|
||||
Generic.Traceback: "bold #a40000", # class: 'gt'
|
||||
}
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
{%- extends "basic/layout.html" %}
|
||||
{%- block extrahead %}
|
||||
{{ super() }}
|
||||
{% if theme_touch_icon %}
|
||||
<link rel="apple-touch-icon" href="{{ pathto('_static/' ~ theme_touch_icon, 1) }}" />
|
||||
{% endif %}
|
||||
<link media="only screen and (max-device-width: 480px)" href="{{
|
||||
pathto('_static/small_flask.css', 1) }}" type= "text/css" rel="stylesheet" />
|
||||
{% endblock %}
|
||||
{%- block relbar2 %}{% endblock %}
|
||||
{%- block footer %}
|
||||
<div class="footer">
|
||||
© Copyright {{ copyright }}.
|
||||
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
|
||||
</div>
|
||||
{%- endblock %}
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
<h3>Related Topics</h3>
|
||||
<ul>
|
||||
<li><a href="{{ pathto(master_doc) }}">Documentation overview</a><ul>
|
||||
{%- for parent in parents %}
|
||||
<li><a href="{{ parent.link|e }}">{{ parent.title }}</a><ul>
|
||||
{%- endfor %}
|
||||
{%- if prev %}
|
||||
<li>Previous: <a href="{{ prev.link|e }}" title="{{ _('previous chapter')
|
||||
}}">{{ prev.title }}</a></li>
|
||||
{%- endif %}
|
||||
{%- if next %}
|
||||
<li>Next: <a href="{{ next.link|e }}" title="{{ _('next chapter')
|
||||
}}">{{ next.title }}</a></li>
|
||||
{%- endif %}
|
||||
{%- for parent in parents %}
|
||||
</ul></li>
|
||||
{%- endfor %}
|
||||
</ul></li>
|
||||
</ul>
|
||||
Vendored
+387
@@ -0,0 +1,387 @@
|
||||
/*
|
||||
* flasky.css_t
|
||||
* ~~~~~~~~~~~~
|
||||
*
|
||||
* :copyright: Copyright 2010 by Armin Ronacher. Modifications by Kenneth Reitz.
|
||||
* :license: Flask Design License, see LICENSE for details.
|
||||
*/
|
||||
|
||||
{% set page_width = '940px' %}
|
||||
{% set sidebar_width = '220px' %}
|
||||
|
||||
@import url("basic.css");
|
||||
|
||||
/* -- page layout ----------------------------------------------------------- */
|
||||
|
||||
body {
|
||||
font-family: 'goudy old style', 'minion pro', 'bell mt', Georgia, 'Hiragino Mincho Pro';
|
||||
font-size: 17px;
|
||||
background-color: white;
|
||||
color: #000;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
div.document {
|
||||
width: {{ page_width }};
|
||||
margin: 30px auto 0 auto;
|
||||
}
|
||||
|
||||
div.documentwrapper {
|
||||
float: left;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
div.bodywrapper {
|
||||
margin: 0 0 0 {{ sidebar_width }};
|
||||
}
|
||||
|
||||
div.sphinxsidebar {
|
||||
width: {{ sidebar_width }};
|
||||
}
|
||||
|
||||
hr {
|
||||
border: 1px solid #B1B4B6;
|
||||
}
|
||||
|
||||
div.body {
|
||||
background-color: #ffffff;
|
||||
color: #3E4349;
|
||||
padding: 0 30px 0 30px;
|
||||
}
|
||||
|
||||
img.floatingflask {
|
||||
padding: 0 0 10px 10px;
|
||||
float: right;
|
||||
}
|
||||
|
||||
div.footer {
|
||||
width: {{ page_width }};
|
||||
margin: 20px auto 30px auto;
|
||||
font-size: 14px;
|
||||
color: #888;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
div.footer a {
|
||||
color: #888;
|
||||
}
|
||||
|
||||
div.related {
|
||||
display: none;
|
||||
}
|
||||
|
||||
div.sphinxsidebar a {
|
||||
color: #444;
|
||||
text-decoration: none;
|
||||
border-bottom: 1px dotted #999;
|
||||
}
|
||||
|
||||
div.sphinxsidebar a:hover {
|
||||
border-bottom: 1px solid #999;
|
||||
}
|
||||
|
||||
div.sphinxsidebar {
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
div.sphinxsidebarwrapper {
|
||||
padding: 18px 10px;
|
||||
}
|
||||
|
||||
div.sphinxsidebarwrapper p.logo {
|
||||
padding: 0 0 20px 0;
|
||||
margin: 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
div.sphinxsidebar h3,
|
||||
div.sphinxsidebar h4 {
|
||||
font-family: 'Garamond', 'Georgia', serif;
|
||||
color: #444;
|
||||
font-size: 24px;
|
||||
font-weight: normal;
|
||||
margin: 0 0 5px 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
div.sphinxsidebar h4 {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
div.sphinxsidebar h3 a {
|
||||
color: #444;
|
||||
}
|
||||
|
||||
div.sphinxsidebar p.logo a,
|
||||
div.sphinxsidebar h3 a,
|
||||
div.sphinxsidebar p.logo a:hover,
|
||||
div.sphinxsidebar h3 a:hover {
|
||||
border: none;
|
||||
}
|
||||
|
||||
div.sphinxsidebar p {
|
||||
color: #555;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
div.sphinxsidebar ul {
|
||||
margin: 10px 0;
|
||||
padding: 0;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
div.sphinxsidebar input {
|
||||
border: 1px solid #ccc;
|
||||
font-family: 'Georgia', serif;
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
/* -- body styles ----------------------------------------------------------- */
|
||||
|
||||
a {
|
||||
color: #004B6B;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #6D4100;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
div.body h1,
|
||||
div.body h2,
|
||||
div.body h3,
|
||||
div.body h4,
|
||||
div.body h5,
|
||||
div.body h6 {
|
||||
font-family: 'Garamond', 'Georgia', serif;
|
||||
font-weight: normal;
|
||||
margin: 30px 0px 10px 0px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
div.body h1 { margin-top: 0; padding-top: 0; font-size: 240%; }
|
||||
div.body h2 { font-size: 180%; }
|
||||
div.body h3 { font-size: 150%; }
|
||||
div.body h4 { font-size: 130%; }
|
||||
div.body h5 { font-size: 100%; }
|
||||
div.body h6 { font-size: 100%; }
|
||||
|
||||
a.headerlink {
|
||||
color: #ddd;
|
||||
padding: 0 4px;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a.headerlink:hover {
|
||||
color: #444;
|
||||
background: #eaeaea;
|
||||
}
|
||||
|
||||
div.body p, div.body dd, div.body li {
|
||||
line-height: 1.4em;
|
||||
}
|
||||
|
||||
div.admonition {
|
||||
background: #fafafa;
|
||||
margin: 20px -30px;
|
||||
padding: 10px 30px;
|
||||
border-top: 1px solid #ccc;
|
||||
border-bottom: 1px solid #ccc;
|
||||
}
|
||||
|
||||
div.admonition tt.xref, div.admonition a tt {
|
||||
border-bottom: 1px solid #fafafa;
|
||||
}
|
||||
|
||||
dd div.admonition {
|
||||
margin-left: -60px;
|
||||
padding-left: 60px;
|
||||
}
|
||||
|
||||
div.admonition p.admonition-title {
|
||||
font-family: 'Garamond', 'Georgia', serif;
|
||||
font-weight: normal;
|
||||
font-size: 24px;
|
||||
margin: 0 0 10px 0;
|
||||
padding: 0;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
div.admonition p.last {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
div.highlight {
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
dt:target, .highlight {
|
||||
background: #FAF3E8;
|
||||
}
|
||||
|
||||
div.note {
|
||||
background-color: #eee;
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
|
||||
div.seealso {
|
||||
background-color: #ffc;
|
||||
border: 1px solid #ff6;
|
||||
}
|
||||
|
||||
div.topic {
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
p.admonition-title {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
p.admonition-title:after {
|
||||
content: ":";
|
||||
}
|
||||
|
||||
pre, tt {
|
||||
font-family: 'Consolas', 'Menlo', 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
img.screenshot {
|
||||
}
|
||||
|
||||
tt.descname, tt.descclassname {
|
||||
font-size: 0.95em;
|
||||
}
|
||||
|
||||
tt.descname {
|
||||
padding-right: 0.08em;
|
||||
}
|
||||
|
||||
img.screenshot {
|
||||
-moz-box-shadow: 2px 2px 4px #eee;
|
||||
-webkit-box-shadow: 2px 2px 4px #eee;
|
||||
box-shadow: 2px 2px 4px #eee;
|
||||
}
|
||||
|
||||
table.docutils {
|
||||
border: 1px solid #888;
|
||||
-moz-box-shadow: 2px 2px 4px #eee;
|
||||
-webkit-box-shadow: 2px 2px 4px #eee;
|
||||
box-shadow: 2px 2px 4px #eee;
|
||||
}
|
||||
|
||||
table.docutils td, table.docutils th {
|
||||
border: 1px solid #888;
|
||||
padding: 0.25em 0.7em;
|
||||
}
|
||||
|
||||
table.field-list, table.footnote {
|
||||
border: none;
|
||||
-moz-box-shadow: none;
|
||||
-webkit-box-shadow: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
table.footnote {
|
||||
margin: 15px 0;
|
||||
width: 100%;
|
||||
border: 1px solid #eee;
|
||||
background: #fdfdfd;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
table.footnote + table.footnote {
|
||||
margin-top: -15px;
|
||||
border-top: none;
|
||||
}
|
||||
|
||||
table.field-list th {
|
||||
padding: 0 0.8em 0 0;
|
||||
}
|
||||
|
||||
table.field-list td {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
table.footnote td.label {
|
||||
width: 0px;
|
||||
padding: 0.3em 0 0.3em 0.5em;
|
||||
}
|
||||
|
||||
table.footnote td {
|
||||
padding: 0.3em 0.5em;
|
||||
}
|
||||
|
||||
dl {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
dl dd {
|
||||
margin-left: 30px;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
margin: 0 0 0 30px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
ul, ol {
|
||||
margin: 10px 0 10px 30px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
pre {
|
||||
background: #eee;
|
||||
padding: 7px 30px;
|
||||
margin: 15px -30px;
|
||||
line-height: 1.3em;
|
||||
}
|
||||
|
||||
dl pre, blockquote pre, li pre {
|
||||
margin-left: -60px;
|
||||
padding-left: 60px;
|
||||
}
|
||||
|
||||
dl dl pre {
|
||||
margin-left: -90px;
|
||||
padding-left: 90px;
|
||||
}
|
||||
|
||||
tt {
|
||||
background-color: #ecf0f3;
|
||||
color: #222;
|
||||
/* padding: 1px 2px; */
|
||||
}
|
||||
|
||||
tt.xref, a tt {
|
||||
background-color: #FBFBFB;
|
||||
border-bottom: 1px solid white;
|
||||
}
|
||||
|
||||
a.reference {
|
||||
text-decoration: none;
|
||||
border-bottom: 1px dotted #004B6B;
|
||||
}
|
||||
|
||||
a.reference:hover {
|
||||
border-bottom: 1px solid #6D4100;
|
||||
}
|
||||
|
||||
a.footnote-reference {
|
||||
text-decoration: none;
|
||||
font-size: 0.7em;
|
||||
vertical-align: top;
|
||||
border-bottom: 1px dotted #004B6B;
|
||||
}
|
||||
|
||||
a.footnote-reference:hover {
|
||||
border-bottom: 1px solid #6D4100;
|
||||
}
|
||||
|
||||
a:hover tt {
|
||||
background: #EEE;
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* small_flask.css_t
|
||||
* ~~~~~~~~~~~~~~~~~
|
||||
*
|
||||
* :copyright: Copyright 2010 by Armin Ronacher.
|
||||
* :license: Flask Design License, see LICENSE for details.
|
||||
*/
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 20px 30px;
|
||||
}
|
||||
|
||||
div.documentwrapper {
|
||||
float: none;
|
||||
background: white;
|
||||
}
|
||||
|
||||
div.sphinxsidebar {
|
||||
display: block;
|
||||
float: none;
|
||||
width: 102.5%;
|
||||
margin: 50px -30px -20px -30px;
|
||||
padding: 10px 20px;
|
||||
background: #333;
|
||||
color: white;
|
||||
}
|
||||
|
||||
div.sphinxsidebar h3, div.sphinxsidebar h4, div.sphinxsidebar p,
|
||||
div.sphinxsidebar h3 a {
|
||||
color: white;
|
||||
}
|
||||
|
||||
div.sphinxsidebar a {
|
||||
color: #aaa;
|
||||
}
|
||||
|
||||
div.sphinxsidebar p.logo {
|
||||
display: none;
|
||||
}
|
||||
|
||||
div.document {
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
div.related {
|
||||
display: block;
|
||||
margin: 0;
|
||||
padding: 10px 0 20px 0;
|
||||
}
|
||||
|
||||
div.related ul,
|
||||
div.related ul li {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
div.footer {
|
||||
display: none;
|
||||
}
|
||||
|
||||
div.bodywrapper {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
div.body {
|
||||
min-height: 0;
|
||||
padding: 0;
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
[theme]
|
||||
inherit = basic
|
||||
stylesheet = flasky.css
|
||||
pygments_style = flask_theme_support.FlaskyStyle
|
||||
|
||||
[options]
|
||||
touch_icon =
|
||||
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
{% extends "basic/layout.html" %}
|
||||
{% block header %}
|
||||
{{ super() }}
|
||||
{% if pagename == 'index' %}
|
||||
<div class=indexwrapper>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% block footer %}
|
||||
{% if pagename == 'index' %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{# do not display relbars #}
|
||||
{% block relbar1 %}{% endblock %}
|
||||
{% block relbar2 %}
|
||||
{% if theme_github_fork %}
|
||||
<a href="http://github.com/{{ theme_github_fork }}"><img style="position: fixed; top: 0; right: 0; border: 0;"
|
||||
src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" /></a>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% block sidebar1 %}{% endblock %}
|
||||
{% block sidebar2 %}{% endblock %}
|
||||
+287
@@ -0,0 +1,287 @@
|
||||
/*
|
||||
* flasky.css_t
|
||||
* ~~~~~~~~~~~~
|
||||
*
|
||||
* Sphinx stylesheet -- flasky theme based on nature theme.
|
||||
*
|
||||
* :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS.
|
||||
* :license: BSD, see LICENSE for details.
|
||||
*
|
||||
*/
|
||||
|
||||
@import url("basic.css");
|
||||
|
||||
/* -- page layout ----------------------------------------------------------- */
|
||||
|
||||
body {
|
||||
font-family: 'Georgia', serif;
|
||||
font-size: 17px;
|
||||
color: #000;
|
||||
background: white;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
div.documentwrapper {
|
||||
float: left;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
div.bodywrapper {
|
||||
margin: 40px auto 0 auto;
|
||||
width: 700px;
|
||||
}
|
||||
|
||||
hr {
|
||||
border: 1px solid #B1B4B6;
|
||||
}
|
||||
|
||||
div.body {
|
||||
background-color: #ffffff;
|
||||
color: #3E4349;
|
||||
padding: 0 30px 30px 30px;
|
||||
}
|
||||
|
||||
img.floatingflask {
|
||||
padding: 0 0 10px 10px;
|
||||
float: right;
|
||||
}
|
||||
|
||||
div.footer {
|
||||
text-align: right;
|
||||
color: #888;
|
||||
padding: 10px;
|
||||
font-size: 14px;
|
||||
width: 650px;
|
||||
margin: 0 auto 40px auto;
|
||||
}
|
||||
|
||||
div.footer a {
|
||||
color: #888;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
div.related {
|
||||
line-height: 32px;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
div.related ul {
|
||||
padding: 0 0 0 10px;
|
||||
}
|
||||
|
||||
div.related a {
|
||||
color: #444;
|
||||
}
|
||||
|
||||
/* -- body styles ----------------------------------------------------------- */
|
||||
|
||||
a {
|
||||
color: #004B6B;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #6D4100;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
div.body {
|
||||
padding-bottom: 40px; /* saved for footer */
|
||||
}
|
||||
|
||||
div.body h1,
|
||||
div.body h2,
|
||||
div.body h3,
|
||||
div.body h4,
|
||||
div.body h5,
|
||||
div.body h6 {
|
||||
font-family: 'Garamond', 'Georgia', serif;
|
||||
font-weight: normal;
|
||||
margin: 30px 0px 10px 0px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
{% if theme_index_logo %}
|
||||
div.indexwrapper h1 {
|
||||
text-indent: -999999px;
|
||||
background: url({{ theme_index_logo }}) no-repeat center center;
|
||||
height: {{ theme_index_logo_height }};
|
||||
}
|
||||
{% endif %}
|
||||
|
||||
div.body h2 { font-size: 180%; }
|
||||
div.body h3 { font-size: 150%; }
|
||||
div.body h4 { font-size: 130%; }
|
||||
div.body h5 { font-size: 100%; }
|
||||
div.body h6 { font-size: 100%; }
|
||||
|
||||
a.headerlink {
|
||||
color: white;
|
||||
padding: 0 4px;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a.headerlink:hover {
|
||||
color: #444;
|
||||
background: #eaeaea;
|
||||
}
|
||||
|
||||
div.body p, div.body dd, div.body li {
|
||||
line-height: 1.4em;
|
||||
}
|
||||
|
||||
div.admonition {
|
||||
background: #fafafa;
|
||||
margin: 20px -30px;
|
||||
padding: 10px 30px;
|
||||
border-top: 1px solid #ccc;
|
||||
border-bottom: 1px solid #ccc;
|
||||
}
|
||||
|
||||
div.admonition p.admonition-title {
|
||||
font-family: 'Garamond', 'Georgia', serif;
|
||||
font-weight: normal;
|
||||
font-size: 24px;
|
||||
margin: 0 0 10px 0;
|
||||
padding: 0;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
div.admonition p.last {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
div.highlight{
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
dt:target, .highlight {
|
||||
background: #FAF3E8;
|
||||
}
|
||||
|
||||
div.note {
|
||||
background-color: #eee;
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
|
||||
div.seealso {
|
||||
background-color: #ffc;
|
||||
border: 1px solid #ff6;
|
||||
}
|
||||
|
||||
div.topic {
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
div.warning {
|
||||
background-color: #ffe4e4;
|
||||
border: 1px solid #f66;
|
||||
}
|
||||
|
||||
p.admonition-title {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
p.admonition-title:after {
|
||||
content: ":";
|
||||
}
|
||||
|
||||
pre, tt {
|
||||
font-family: 'Consolas', 'Menlo', 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace;
|
||||
font-size: 0.85em;
|
||||
}
|
||||
|
||||
img.screenshot {
|
||||
}
|
||||
|
||||
tt.descname, tt.descclassname {
|
||||
font-size: 0.95em;
|
||||
}
|
||||
|
||||
tt.descname {
|
||||
padding-right: 0.08em;
|
||||
}
|
||||
|
||||
img.screenshot {
|
||||
-moz-box-shadow: 2px 2px 4px #eee;
|
||||
-webkit-box-shadow: 2px 2px 4px #eee;
|
||||
box-shadow: 2px 2px 4px #eee;
|
||||
}
|
||||
|
||||
table.docutils {
|
||||
border: 1px solid #888;
|
||||
-moz-box-shadow: 2px 2px 4px #eee;
|
||||
-webkit-box-shadow: 2px 2px 4px #eee;
|
||||
box-shadow: 2px 2px 4px #eee;
|
||||
}
|
||||
|
||||
table.docutils td, table.docutils th {
|
||||
border: 1px solid #888;
|
||||
padding: 0.25em 0.7em;
|
||||
}
|
||||
|
||||
table.field-list, table.footnote {
|
||||
border: none;
|
||||
-moz-box-shadow: none;
|
||||
-webkit-box-shadow: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
table.footnote {
|
||||
margin: 15px 0;
|
||||
width: 100%;
|
||||
border: 1px solid #eee;
|
||||
}
|
||||
|
||||
table.field-list th {
|
||||
padding: 0 0.8em 0 0;
|
||||
}
|
||||
|
||||
table.field-list td {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
table.footnote td {
|
||||
padding: 0.5em;
|
||||
}
|
||||
|
||||
dl {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
dl dd {
|
||||
margin-left: 30px;
|
||||
}
|
||||
|
||||
pre {
|
||||
padding: 0;
|
||||
margin: 15px -30px;
|
||||
padding: 8px;
|
||||
line-height: 1.3em;
|
||||
padding: 7px 30px;
|
||||
background: #eee;
|
||||
border-radius: 2px;
|
||||
-moz-border-radius: 2px;
|
||||
-webkit-border-radius: 2px;
|
||||
}
|
||||
|
||||
dl pre {
|
||||
margin-left: -60px;
|
||||
padding-left: 60px;
|
||||
}
|
||||
|
||||
tt {
|
||||
background-color: #ecf0f3;
|
||||
color: #222;
|
||||
/* padding: 1px 2px; */
|
||||
}
|
||||
|
||||
tt.xref, a tt {
|
||||
background-color: #FBFBFB;
|
||||
}
|
||||
|
||||
a:hover tt {
|
||||
background: #EEE;
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
[theme]
|
||||
inherit = basic
|
||||
stylesheet = flasky.css
|
||||
nosidebar = true
|
||||
pygments_style = flask_theme_support.FlaskyStyle
|
||||
|
||||
[options]
|
||||
index_logo = ''
|
||||
index_logo_height = 120px
|
||||
github_fork = ''
|
||||
+261
@@ -0,0 +1,261 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# osxpython documentation build configuration file, created by
|
||||
# sphinx-quickstart on Wed Aug 4 22:51:11 2010.
|
||||
#
|
||||
# This file is execfile()d with the current directory set to its containing dir.
|
||||
#
|
||||
# Note that not all possible configuration values are present in this
|
||||
# autogenerated file.
|
||||
#
|
||||
# All configuration values have a default; values that are commented out
|
||||
# serve to show the default.
|
||||
|
||||
import sys, os
|
||||
sys.path.insert(0, os.path.abspath('..'))
|
||||
|
||||
import clint
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
sys.path.append(os.path.abspath('_themes'))
|
||||
|
||||
|
||||
|
||||
# -- General configuration -----------------------------------------------------
|
||||
|
||||
# If your documentation needs a minimal Sphinx version, state it here.
|
||||
#needs_sphinx = '1.0'
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be extensions
|
||||
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
|
||||
extensions = ['sphinx.ext.ifconfig']
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
|
||||
# The suffix of source filenames.
|
||||
source_suffix = '.rst'
|
||||
|
||||
# The encoding of source files.
|
||||
#source_encoding = 'utf-8-sig'
|
||||
|
||||
# The master toctree document.
|
||||
master_doc = 'index'
|
||||
|
||||
# General information about the project.
|
||||
project = u'clint'
|
||||
copyright = u'2011, Kenneth Reitz'
|
||||
|
||||
# The version info for the project you're documenting, acts as replacement for
|
||||
# |version| and |release|, also used in various other places throughout the
|
||||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = clint.__version__
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = version
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
#language = None
|
||||
|
||||
# There are two options for replacing |today|: either, you set today to some
|
||||
# non-false value, then it is used:
|
||||
#today = ''
|
||||
# Else, today_fmt is used as the format for a strftime call.
|
||||
#today_fmt = '%B %d, %Y'
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
exclude_patterns = ['_build']
|
||||
|
||||
# The reST default role (used for this markup: `text`) to use for all documents.
|
||||
#default_role = None
|
||||
|
||||
# If true, '()' will be appended to :func: etc. cross-reference text.
|
||||
#add_function_parentheses = True
|
||||
|
||||
# If true, the current module name will be prepended to all description
|
||||
# unit titles (such as .. function::).
|
||||
#add_module_names = True
|
||||
|
||||
# If true, sectionauthor and moduleauthor directives will be shown in the
|
||||
# output. They are ignored by default.
|
||||
#show_authors = False
|
||||
|
||||
# The name of the Pygments (syntax highlighting) style to use.
|
||||
pygments_style = 'sphinx'
|
||||
|
||||
# A list of ignored prefixes for module index sorting.
|
||||
#modindex_common_prefix = []
|
||||
|
||||
|
||||
# -- Options for HTML output ---------------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
html_theme = 'kr'
|
||||
|
||||
# Theme options are theme-specific and customize the look and feel of a theme
|
||||
# further. For a list of options available for each theme, see the
|
||||
# documentation.
|
||||
#html_theme_options = {}
|
||||
|
||||
# Add any paths that contain custom themes here, relative to this directory.
|
||||
html_theme_path = ['_themes']
|
||||
|
||||
# The name for this set of Sphinx documents. If None, it defaults to
|
||||
# "<project> v<release> documentation".
|
||||
#html_title = None
|
||||
|
||||
# A shorter title for the navigation bar. Default is the same as html_title.
|
||||
#html_short_title = None
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top
|
||||
# of the sidebar.
|
||||
#html_logo = None
|
||||
|
||||
# The name of an image file (within the static path) to use as favicon of the
|
||||
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
|
||||
# pixels large.
|
||||
#html_favicon = None
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = ['_static']
|
||||
|
||||
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
|
||||
# using the given strftime format.
|
||||
#html_last_updated_fmt = '%b %d, %Y'
|
||||
|
||||
# If true, SmartyPants will be used to convert quotes and dashes to
|
||||
# typographically correct entities.
|
||||
#html_use_smartypants = True
|
||||
|
||||
# Custom sidebar templates, maps document names to template names.
|
||||
#html_sidebars = {}
|
||||
|
||||
# Additional templates that should be rendered to pages, maps page names to
|
||||
# template names.
|
||||
#html_additional_pages = {}
|
||||
|
||||
# If false, no module index is generated.
|
||||
#html_domain_indices = True
|
||||
|
||||
# If false, no index is generated.
|
||||
#html_use_index = True
|
||||
|
||||
# If true, the index is split into individual pages for each letter.
|
||||
#html_split_index = False
|
||||
|
||||
# If true, links to the reST sources are added to the pages.
|
||||
#html_show_sourcelink = True
|
||||
|
||||
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
|
||||
#html_show_sphinx = True
|
||||
|
||||
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
|
||||
#html_show_copyright = True
|
||||
|
||||
# If true, an OpenSearch description file will be output, and all pages will
|
||||
# contain a <link> tag referring to it. The value of this option must be the
|
||||
# base URL from which the finished HTML is served.
|
||||
#html_use_opensearch = ''
|
||||
|
||||
# This is the file name suffix for HTML files (e.g. ".xhtml").
|
||||
#html_file_suffix = None
|
||||
|
||||
# Output file base name for HTML help builder.
|
||||
htmlhelp_basename = 'clint'
|
||||
|
||||
|
||||
# -- Options for LaTeX output --------------------------------------------------
|
||||
|
||||
# The paper size ('letter' or 'a4').
|
||||
#latex_paper_size = 'letter'
|
||||
|
||||
# The font size ('10pt', '11pt' or '12pt').
|
||||
#latex_font_size = '10pt'
|
||||
|
||||
# Grouping the document tree into LaTeX files. List of tuples
|
||||
# (source start file, target name, title, author, documentclass [howto/manual]).
|
||||
# latex_documents = [
|
||||
# ('index', 'osxpython.tex', u'osxpython Documentation',
|
||||
# u'Kenneth Reitz', 'manual'),
|
||||
# ]
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top of
|
||||
# the title page.
|
||||
#latex_logo = None
|
||||
|
||||
# For "manual" documents, if this is true, then toplevel headings are parts,
|
||||
# not chapters.
|
||||
#latex_use_parts = False
|
||||
|
||||
# If true, show page references after internal links.
|
||||
#latex_show_pagerefs = False
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
#latex_show_urls = False
|
||||
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
#latex_preamble = ''
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
#latex_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
#latex_domain_indices = True
|
||||
|
||||
|
||||
# -- Options for manual page output --------------------------------------------
|
||||
|
||||
# One entry per manual page. List of tuples
|
||||
# (source start file, name, description, authors, manual section).
|
||||
man_pages = [
|
||||
('index', 'clint', u'Clint Documentation',
|
||||
[u'Kenneth Reitz'], 1)
|
||||
]
|
||||
|
||||
|
||||
# -- Options for Epub output ---------------------------------------------------
|
||||
|
||||
# Bibliographic Dublin Core info.
|
||||
epub_title = u'clint'
|
||||
epub_author = u'Kenneth Reitz'
|
||||
epub_publisher = u'Kenneth Reitz'
|
||||
epub_copyright = u'2010, Kenneth Reitz'
|
||||
|
||||
# The language of the text. It defaults to the language option
|
||||
# or en if the language is not set.
|
||||
#epub_language = ''
|
||||
|
||||
# The scheme of the identifier. Typical schemes are ISBN or URL.
|
||||
#epub_scheme = ''
|
||||
|
||||
# The unique identifier of the text. This can be a ISBN number
|
||||
# or the project homepage.
|
||||
#epub_identifier = ''
|
||||
|
||||
# A unique identification for the text.
|
||||
#epub_uid = ''
|
||||
|
||||
# HTML files that should be inserted before the pages created by sphinx.
|
||||
# The format is a list of tuples containing the path and title.
|
||||
#epub_pre_files = []
|
||||
|
||||
# HTML files shat should be inserted after the pages created by sphinx.
|
||||
# The format is a list of tuples containing the path and title.
|
||||
#epub_post_files = []
|
||||
|
||||
# A list of files that should not be packed into the epub file.
|
||||
#epub_exclude_files = []
|
||||
|
||||
# The depth of the table of contents in toc.ncx.
|
||||
#epub_tocdepth = 3
|
||||
|
||||
# Allow duplicate toc entries.
|
||||
#epub_tocdup = True
|
||||
@@ -0,0 +1,41 @@
|
||||
Contents
|
||||
--------
|
||||
|
||||
This part of the documentation, which is mostly prose, begins with some
|
||||
background information about Clint, then focuses on step-by-step
|
||||
instructions for using Clint for development.
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
foreword
|
||||
installation
|
||||
useful-tools
|
||||
tutorial/index
|
||||
templating
|
||||
testing
|
||||
errorhandling
|
||||
config
|
||||
signals
|
||||
shell
|
||||
patterns/index
|
||||
deploying/index
|
||||
becomingbig
|
||||
|
||||
|
||||
API Documentation
|
||||
-----------------
|
||||
|
||||
api
|
||||
|
||||
|
||||
Additional Notes
|
||||
----------------
|
||||
|
||||
Contribution notes and legal information are here for the interested.
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
contribute
|
||||
license
|
||||
@@ -0,0 +1,17 @@
|
||||
Contribute
|
||||
----------
|
||||
|
||||
Python-guide is under active development, and contributors are welcome.
|
||||
|
||||
If you have a feature request, suggestion, or bug report, please open a new issue on GitHub_. To submit patches, please send a pull request on GitHub_. Make sure you add yourself to AUTHORS_.
|
||||
|
||||
|
||||
If you'd like to contribute, there's plenty to do. Here's a short todo list.
|
||||
|
||||
.. include:: ../TODO.rst
|
||||
|
||||
|
||||
.. _GitHub: http://github.com/kennethreitz/python-guide/
|
||||
.. _AUTHORS: http://github.com/kennethreitz/python-guide/blob/master/AUTHORS
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
.. osxpython documentation master file, created by
|
||||
sphinx-quickstart on Wed Aug 4 22:51:11 2010.
|
||||
You can adapt this file completely to your liking, but it should at least
|
||||
contain the root `toctree` directive.
|
||||
|
||||
Welcome to Clint's Documentation!
|
||||
=================================
|
||||
|
||||
Welcome to Clint.
|
||||
|
||||
.. include:: contents.rst.inc
|
||||
@@ -0,0 +1,128 @@
|
||||
Properly Installing Python
|
||||
==========================
|
||||
|
||||
Mac OS X
|
||||
::::::::
|
||||
|
||||
*Or, "Installing Python 2.7 via Homebrew".*
|
||||
|
||||
One of the reasons everybody loves Python is the interactive shell. It
|
||||
basically allows you to execute Python commands in real time and
|
||||
immediately get results back. Flask itself does not come with an
|
||||
interactive shell, because it does not require any specific setup upfront,
|
||||
just import your application and start playing around.
|
||||
|
||||
|
||||
Package Manager
|
||||
---------------
|
||||
|
||||
While Snow Leopard comes with a large number of UNIX utilities, those
|
||||
familiar with Linux systems will notice one key component missing: a
|
||||
package manager. Mxcl's *Homebrew* is the answer.
|
||||
|
||||
To install Homebrew, simply run: ::
|
||||
|
||||
$ ruby -e "$(curl -fsS http://gist.github.com/raw/323731/install_homebrew.rb)"
|
||||
|
||||
|
||||
It's basic commands are **update**, **install**, and **remove**.
|
||||
|
||||
.. man brew
|
||||
|
||||
|
||||
|
||||
Python Interpreter
|
||||
------------------
|
||||
|
||||
And we can now install Python 2.7: ::
|
||||
|
||||
$ brew install python --framework
|
||||
|
||||
|
||||
The ``--framework`` option tells Homebrew to compile a Framework-style Python build, rather than a UNIX-style build. The outdated version of Python that Snow Leopard comes packaged with
|
||||
is built as a Framework, so this helps avoid some future module installation
|
||||
bugs.
|
||||
|
||||
*Don't forget to update your environment PATH.*
|
||||
|
||||
|
||||
Distribute & Pip
|
||||
----------------
|
||||
|
||||
*Distribute* is a fantastic drop-in replacement for *easy_install* and
|
||||
*setuptools*. It allows you to install and manage python packages from
|
||||
pypi.python.org, amongst a few other sources. It also plays well with
|
||||
*virtualenv* and user-enviornments.
|
||||
|
||||
**easy_install** is considered by many to be a deprecated system, so we
|
||||
will install it's replacement: **pip**. Pip allows for uninstallation
|
||||
of packages, and is actively maintained, unlike setuptool's easy_install.
|
||||
|
||||
To install *pip* and Distribute's *easy_install*:
|
||||
|
||||
If you have homebrew: ::
|
||||
|
||||
$ brew install pip
|
||||
|
||||
...And, if you're a masochist: ::
|
||||
|
||||
$ curl -O http://python-distribute.org/distribute_setup.py
|
||||
$ python distribute_setup.py
|
||||
|
||||
$ easy_install pip
|
||||
|
||||
|
||||
|
||||
To install ``pip``: ::
|
||||
|
||||
Hopefully you'll never have to use **easy_install** again.
|
||||
|
||||
|
||||
Updating Python
|
||||
---------------
|
||||
|
||||
Homebrew makes it simple. ::
|
||||
|
||||
$ brew update
|
||||
$ brew install --force python
|
||||
|
||||
|
||||
Windows
|
||||
:::::::
|
||||
|
||||
|
||||
|
||||
Prerequisites:
|
||||
--------------
|
||||
|
||||
* Python2.7 (x86) from Python.org
|
||||
* Microsoft Visual Studio
|
||||
|
||||
|
||||
Step 1: Install Distribute & Pip
|
||||
--------------------------------
|
||||
|
||||
**Distribute** is a fantastic drop-in replacement for **easy_install** and **setuptools**. It allows you to install and manage python packages from PyPi, amongst a few other sources.
|
||||
|
||||
To install it, run the python script available here:
|
||||
<http://python-distribute.org/distribute_setup.py>
|
||||
|
||||
Make sure that ```C:\Python27\```, and ```C:\Python27\Scripts``` are in your PATH.
|
||||
|
||||
**easy_install** is considered by many to be a deprecated system, so we will install it's replacement: **pip**. Pip allows for uninstallation of packages, and is actively maintained, unlike setuptool's easy_install.
|
||||
|
||||
To install pip, simply run: ::
|
||||
|
||||
$ easy_install pip
|
||||
|
||||
|
||||
Linux (Ubuntu)
|
||||
::::::::::::::
|
||||
|
||||
|
||||
|
||||
Linux (Manual)
|
||||
::::::::::::::
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
License
|
||||
-------
|
||||
|
||||
TBD.
|
||||
+155
@@ -0,0 +1,155 @@
|
||||
@ECHO OFF
|
||||
|
||||
REM Command file for Sphinx documentation
|
||||
|
||||
if "%SPHINXBUILD%" == "" (
|
||||
set SPHINXBUILD=sphinx-build
|
||||
)
|
||||
set BUILDDIR=_build
|
||||
set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% .
|
||||
if NOT "%PAPER%" == "" (
|
||||
set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
|
||||
)
|
||||
|
||||
if "%1" == "" goto help
|
||||
|
||||
if "%1" == "help" (
|
||||
:help
|
||||
echo.Please use `make ^<target^>` where ^<target^> is one of
|
||||
echo. html to make standalone HTML files
|
||||
echo. dirhtml to make HTML files named index.html in directories
|
||||
echo. singlehtml to make a single large HTML file
|
||||
echo. pickle to make pickle files
|
||||
echo. json to make JSON files
|
||||
echo. htmlhelp to make HTML files and a HTML help project
|
||||
echo. qthelp to make HTML files and a qthelp project
|
||||
echo. devhelp to make HTML files and a Devhelp project
|
||||
echo. epub to make an epub
|
||||
echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
|
||||
echo. text to make text files
|
||||
echo. man to make manual pages
|
||||
echo. changes to make an overview over all changed/added/deprecated items
|
||||
echo. linkcheck to check all external links for integrity
|
||||
echo. doctest to run all doctests embedded in the documentation if enabled
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "clean" (
|
||||
for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
|
||||
del /q /s %BUILDDIR%\*
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "html" (
|
||||
%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
|
||||
echo.
|
||||
echo.Build finished. The HTML pages are in %BUILDDIR%/html.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "dirhtml" (
|
||||
%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
|
||||
echo.
|
||||
echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "singlehtml" (
|
||||
%SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
|
||||
echo.
|
||||
echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "pickle" (
|
||||
%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
|
||||
echo.
|
||||
echo.Build finished; now you can process the pickle files.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "json" (
|
||||
%SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
|
||||
echo.
|
||||
echo.Build finished; now you can process the JSON files.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "htmlhelp" (
|
||||
%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
|
||||
echo.
|
||||
echo.Build finished; now you can run HTML Help Workshop with the ^
|
||||
.hhp project file in %BUILDDIR%/htmlhelp.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "qthelp" (
|
||||
%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
|
||||
echo.
|
||||
echo.Build finished; now you can run "qcollectiongenerator" with the ^
|
||||
.qhcp project file in %BUILDDIR%/qthelp, like this:
|
||||
echo.^> qcollectiongenerator %BUILDDIR%\qthelp\osxpython.qhcp
|
||||
echo.To view the help file:
|
||||
echo.^> assistant -collectionFile %BUILDDIR%\qthelp\osxpython.ghc
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "devhelp" (
|
||||
%SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
|
||||
echo.
|
||||
echo.Build finished.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "epub" (
|
||||
%SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
|
||||
echo.
|
||||
echo.Build finished. The epub file is in %BUILDDIR%/epub.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "latex" (
|
||||
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
|
||||
echo.
|
||||
echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "text" (
|
||||
%SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
|
||||
echo.
|
||||
echo.Build finished. The text files are in %BUILDDIR%/text.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "man" (
|
||||
%SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
|
||||
echo.
|
||||
echo.Build finished. The manual pages are in %BUILDDIR%/man.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "changes" (
|
||||
%SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
|
||||
echo.
|
||||
echo.The overview file is in %BUILDDIR%/changes.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "linkcheck" (
|
||||
%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
|
||||
echo.
|
||||
echo.Link check complete; look for any errors in the above output ^
|
||||
or in %BUILDDIR%/linkcheck/output.txt.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "doctest" (
|
||||
%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
|
||||
echo.
|
||||
echo.Testing of doctests in the sources finished, look at the ^
|
||||
results in %BUILDDIR%/doctest/output.txt.
|
||||
goto end
|
||||
)
|
||||
|
||||
:end
|
||||
@@ -0,0 +1,18 @@
|
||||
Useful Tools
|
||||
============
|
||||
|
||||
IPython
|
||||
-------
|
||||
|
||||
::
|
||||
|
||||
$ pip install ipython
|
||||
|
||||
|
||||
|
||||
BPython
|
||||
-------
|
||||
|
||||
::
|
||||
|
||||
$ pip install bpython
|
||||
Regular → Executable
+5
-2
@@ -6,9 +6,11 @@ import os
|
||||
|
||||
sys.path.insert(0, os.path.abspath('..'))
|
||||
|
||||
from clint import args
|
||||
from clint.arguments import Args
|
||||
from clint.textui import puts, colored, indent
|
||||
|
||||
args = Args()
|
||||
|
||||
with indent(4, quote='>>>'):
|
||||
puts(colored.red('Aruments passed in: ') + str(args.all))
|
||||
puts(colored.red('Flags detected: ') + str(args.flags))
|
||||
@@ -16,4 +18,5 @@ with indent(4, quote='>>>'):
|
||||
puts(colored.red('NOT Files detected: ') + str(args.not_files))
|
||||
puts(colored.red('Grouped Arguments: ') + str(dict(args.grouped)))
|
||||
|
||||
print
|
||||
print
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
@@ -12,5 +14,5 @@ text = 'THIS TEXT IS COLORED %s!'
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
for color in colored.__all__:
|
||||
print getattr(colored, color)(text % color.upper())
|
||||
for color in colored.COLORS:
|
||||
print(getattr(colored, color)(text % color.upper()))
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import with_statement
|
||||
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(0, os.path.abspath('..'))
|
||||
|
||||
from clint.eng import join
|
||||
from clint.textui import colored, indent, puts
|
||||
|
||||
colors = [
|
||||
colored.blue('blue'),
|
||||
colored.red('red'),
|
||||
colored.yellow('yellow'),
|
||||
colored.green('green'),
|
||||
colored.magenta('magenta')
|
||||
]
|
||||
|
||||
colors = [str(cs) for cs in colors]
|
||||
|
||||
|
||||
puts('Smart:')
|
||||
with indent(4):
|
||||
for i in range(len(colors)):
|
||||
puts(join(colors[:i+1]))
|
||||
puts('\n')
|
||||
puts('Stupid:')
|
||||
with indent(4):
|
||||
for i in range(len(colors)):
|
||||
puts(join(colors[:i+1], im_a_moron=True, conj='\'n'))
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
#! /usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from clint.arguments import Args
|
||||
from clint.textui import puts, colored
|
||||
|
||||
all_args = Args().grouped
|
||||
|
||||
for item in all_args:
|
||||
if item is not '_':
|
||||
puts(colored.red("key:%s"%item))
|
||||
print(all_args[item].all)
|
||||
|
||||
Executable
+4
@@ -0,0 +1,4 @@
|
||||
echo "python get_each_args.py --name kracekumar --email me@kracekumar.com"
|
||||
python get_each_args.py --name kracekumar --email me@kracekumar.com
|
||||
echo "python get_each_args.py --languages python c html ruby --email me@kracekumar.com"
|
||||
python get_each_args.py --langauges python c html ruby --email me@kracekumar.com
|
||||
@@ -1,6 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import with_statement
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import with_statement
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
||||
+3
-1
@@ -1,6 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import with_statement
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
@@ -21,4 +23,4 @@ if __name__ == '__main__':
|
||||
with indent(5, quote=colored.red(' |')):
|
||||
puts(in_data)
|
||||
else:
|
||||
puts(colored.red('Warning: ') + 'No data was piped in.')
|
||||
puts(colored.red('Warning: ') + 'No data was piped in.')
|
||||
|
||||
+19
-4
@@ -8,12 +8,27 @@ sys.path.insert(0, os.path.abspath('..'))
|
||||
|
||||
from time import sleep
|
||||
from random import random
|
||||
from clint.textui import progressbar
|
||||
from clint.textui import progress
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
for i in progressbar(range(100)):
|
||||
for i in progress.bar(range(100)):
|
||||
sleep(random() * 0.2)
|
||||
|
||||
with progress.Bar(label="nonlinear", expected_size=10) as bar:
|
||||
last_val = 0
|
||||
for val in (1,2,3,9,10):
|
||||
sleep(2 * (val - last_val))
|
||||
bar.show(val)
|
||||
last_val = val
|
||||
|
||||
for i in progress.dots(range(100)):
|
||||
sleep(random() * 0.2)
|
||||
|
||||
|
||||
|
||||
for i in progress.mill(range(100)):
|
||||
sleep(random() * 0.2)
|
||||
|
||||
# Override the expected_size, for iterables that don't support len()
|
||||
D = dict(zip(range(100), range(100)))
|
||||
for k, v in progress.bar(D.items(), expected_size=len(D)):
|
||||
sleep(random() * 0.2)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(0, os.path.abspath('..'))
|
||||
|
||||
from clint.textui import prompt, puts, colored, validators
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Standard non-empty input
|
||||
name = prompt.query("What's your name?")
|
||||
|
||||
# Set validators to an empty list for an optional input
|
||||
language = prompt.query("Your favorite tool (optional)?", validators=[])
|
||||
|
||||
# Use a default value and a validator
|
||||
path = prompt.query('Installation Path', default='/usr/local/bin/', validators=[validators.PathValidator()])
|
||||
|
||||
puts(colored.blue('Hi {0}. Install {1} to {2}'.format(name, language or 'nothing', path)))
|
||||
@@ -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')
|
||||
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(0, os.path.abspath('..'))
|
||||
|
||||
from clint.textui import puts, colored
|
||||
from clint.textui import columns
|
||||
|
||||
lorem = 'Lorem ipsum dolor sit amet, consehdfhdfhdfhdfhdfhctetur adi pisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 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.'
|
||||
|
||||
if __name__ == '__main__':
|
||||
# puts(min_width('test\nit', 20) + ' me')
|
||||
# puts(max_width(lorem, 20) + ' me')
|
||||
|
||||
# print max_width(lorem, 45)
|
||||
|
||||
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]))
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"title": "Bashō's 'old pond'",
|
||||
"text": "古池や蛙飛込む水の音"
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import sys
|
||||
import codecs
|
||||
|
||||
sys.path.insert(0, os.path.abspath('..'))
|
||||
|
||||
try:
|
||||
import json
|
||||
except:
|
||||
import simplejson as json
|
||||
|
||||
from clint.arguments import Args
|
||||
from clint import piped_in
|
||||
from clint.textui import colored, puts, indent
|
||||
|
||||
args = Args()
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
puts('Test:')
|
||||
with indent(4):
|
||||
puts('%s Fake test 1.' % colored.green('✔'))
|
||||
puts('%s Fake test 2.' % colored.red('✖'))
|
||||
|
||||
puts('')
|
||||
puts('Greet:')
|
||||
with indent(4):
|
||||
puts(colored.red('Здравствуйте'))
|
||||
puts(colored.green('你好。'))
|
||||
puts(colored.yellow('سلام'))
|
||||
puts(colored.magenta('안녕하세요'))
|
||||
puts(colored.blue('नमस्ते'))
|
||||
puts(colored.cyan('γειά σου'))
|
||||
|
||||
puts('')
|
||||
puts('Arguments:')
|
||||
with indent(4):
|
||||
puts('%s' % colored.red(args[0]))
|
||||
|
||||
puts('')
|
||||
puts('File:')
|
||||
with indent(4):
|
||||
f = args.files[0]
|
||||
puts(colored.yellow('%s:' % f))
|
||||
with indent(2):
|
||||
fd = codecs.open(f, encoding='utf-8')
|
||||
for line in fd:
|
||||
line = line.strip('\n\r')
|
||||
puts(colored.yellow(' %s' % line))
|
||||
fd.close()
|
||||
|
||||
puts('')
|
||||
puts('Input:')
|
||||
with indent(4):
|
||||
in_data = json.loads(piped_in())
|
||||
title = in_data['title']
|
||||
text = in_data['text']
|
||||
puts(colored.blue('Title: %s' % title))
|
||||
puts(colored.magenta('Text: %s' % text))
|
||||
Executable
+3
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
python unicode.py こんにちは。 unicode.json < unicode.json
|
||||
@@ -4,8 +4,12 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
from distutils.core import setup
|
||||
try:
|
||||
from setuptools import setup
|
||||
except ImportError:
|
||||
from distutils.core import setup
|
||||
|
||||
import clint
|
||||
|
||||
def publish():
|
||||
"""Publish to PyPi"""
|
||||
@@ -15,11 +19,11 @@ if sys.argv[-1] == "publish":
|
||||
publish()
|
||||
sys.exit()
|
||||
|
||||
required = []
|
||||
required = ['args']
|
||||
|
||||
setup(
|
||||
name='clint',
|
||||
version='0.1.1',
|
||||
version=clint.__version__,
|
||||
description='Python Command-line Application Tools',
|
||||
long_description=open('README.rst').read() + '\n\n' +
|
||||
open('HISTORY.rst').read(),
|
||||
@@ -29,21 +33,23 @@ setup(
|
||||
packages= [
|
||||
'clint',
|
||||
'clint.textui',
|
||||
|
||||
'clint.packages', 'clint.packages.colorama'
|
||||
],
|
||||
install_requires=required,
|
||||
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.5',
|
||||
'Programming Language :: Python :: 2',
|
||||
'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',
|
||||
),
|
||||
)
|
||||
|
||||
Executable
+62
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""Clint Test Suite."""
|
||||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
|
||||
class ClintTestCase(unittest.TestCase):
|
||||
"""Clint test cases."""
|
||||
|
||||
def setUp(self):
|
||||
import clint
|
||||
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
class ColoredStringTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
from clint.textui.colored import ColoredString
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_split(self):
|
||||
from clint.textui.colored import ColoredString
|
||||
new_str = ColoredString('red', "hello world")
|
||||
output = new_str.split()
|
||||
assert output[0].s == "hello"
|
||||
|
||||
def test_find(self):
|
||||
from clint.textui.colored import ColoredString
|
||||
new_str = ColoredString('blue', "hello world")
|
||||
output = new_str.find('h')
|
||||
self.assertEqual(output, 0)
|
||||
|
||||
def test_replace(self):
|
||||
from clint.textui.colored import ColoredString
|
||||
new_str = ColoredString('green', "hello world")
|
||||
output = new_str.replace("world", "universe")
|
||||
assert output.s == "hello universe"
|
||||
|
||||
def test_py2_bytes_not_mangled(self):
|
||||
from clint.textui.colored import ColoredString
|
||||
# On python 2 make sure the same bytes come out as went in
|
||||
new_str = ColoredString('RED', '\xe4')
|
||||
assert '\xe4' in str(new_str)
|
||||
from clint.textui import puts
|
||||
puts(new_str)
|
||||
|
||||
def test_clint_force_color_env_var(self):
|
||||
from clint.textui.colored import ColoredString
|
||||
os.environ['CLINT_FORCE_COLOR'] = "1"
|
||||
new_str = ColoredString('RED', 'hello world')
|
||||
assert new_str.always_color == True
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user