Add .gitignore

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Stop using versiontools

Versions works with python3 but is, for now, incompatible with 2to3.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Use 2to3 to create python3 compatible installations

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Explicitly iterate over all lines

This fixes incompatibility with python3 where iter(stream.readline, '')
would simply hang. It still has the same property of actually working
line-by-line (so it won't have to wait for the whole output to become
available or to buffer it in memory)

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Fix typo

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Add support for closing streams in Redirect.on_end()

The redirect class can now optionally close either of the output
streams when on_end() is reached. This is useful in quick examples
where the full with open(...) as stream: syntax would be undesired.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Add Decode class

This class can decode byte strings into unicode strings with the
specified encoding, defaultingto UTF-8

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Add Encode and EncodeInPython2 classes

Encode allows one to encode Unicode strings to byte strings. The
EncodeInPython2 class is useful in cases where the output stream
is already expecting Unicode strings (such as the default stdout/stderr
IOTextBase classes being used in python3 when attached to a terminal).

In python2 it behaves just as Encode() (since stdout/stderr is a dumb
file there and we really want to explicitly convert all Unicode
strings to byte strings before calling write())

In python3 it will be a no-op, hopefully forwarding each line to
Unicode-aware IOTextBase instance.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Rewrite README

This large rewrite changes most of the text in the README. This
serves both as a way to test the code and to document how to use it
in various situations. More effort is placed on solving python3 problems
of decoding and re-encoding data between Unicode and bytes

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Fix license inconsistency

extcmd is licensed under LGPLv3+ but the python classifier was referring
to GPL, this can be now corrected. IIRC previously, when extcmd
was written, that classifiers simply did not exist.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Mark python3.2 and python3.3 as supported

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Sign uploaded source tarballs

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Add tox configuration file

Tox is a multi-python testing tool. This file indicates that we
want to support python2.6, python2.7 python3.2 and python3.3

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Add travis configuration file

Travis is a hosted multi-environment test infrastructure.
The .travis.yml file indicates that we want to run our tests
in all supported python versions

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>