Mercurial > hg > config
changeset 516:c78da6f7ca79
python/quotemail.py
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Thu, 19 Sep 2013 11:21:07 -0700 |
parents | 9ddab670f8c4 |
children | a075f8a93183 |
files | python/quotemail.py |
diffstat | 1 files changed, 20 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/python/quotemail.py Wed Sep 18 12:45:13 2013 -0700 +++ b/python/quotemail.py Thu Sep 19 11:21:07 2013 -0700 @@ -3,6 +3,7 @@ """ quote as per email """ +# TODO -> textshaper def prefix(text, quote='> '): return '\n'.join(['%s%s' % (quote, line.rstrip()) @@ -10,4 +11,22 @@ if __name__ == '__main__': import sys - print prefix(sys.stdin.read()) + import optparse + usage = '%prog [options] [file] <file2> <...>' + parser = optparse.OptionParser(usage=usage) + parser.add_option('-i', '--in-place', dest='in_place', + action='store_true', default=False, + help="") + options, args = parser.parse_args() + if args: + for arg in args: + with file(arg) as f: + contents = f.read() + quoted = prefix(contents) + if options.in_place: + with file(arg, 'w') as f: + f.write(quoted) + else: + print quoted + else: + print prefix(sys.stdin.read())