annotate python/quotemail.py @ 582:0295141d9eeb

stub
author Jeff Hammel <k0scist@gmail.com>
date Tue, 21 Jan 2014 09:16:36 -0800
parents c78da6f7ca79
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
365
6bbc4867a795 begin porting from shell function
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/env python
6bbc4867a795 begin porting from shell function
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2
6bbc4867a795 begin porting from shell function
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 """
6bbc4867a795 begin porting from shell function
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 quote as per email
6bbc4867a795 begin porting from shell function
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 """
516
c78da6f7ca79 python/quotemail.py
Jeff Hammel <jhammel@mozilla.com>
parents: 365
diff changeset
6 # TODO -> textshaper
365
6bbc4867a795 begin porting from shell function
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7
6bbc4867a795 begin porting from shell function
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8 def prefix(text, quote='> '):
6bbc4867a795 begin porting from shell function
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 return '\n'.join(['%s%s' % (quote, line.rstrip())
6bbc4867a795 begin porting from shell function
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10 for line in text.strip().splitlines()])
6bbc4867a795 begin porting from shell function
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11
6bbc4867a795 begin porting from shell function
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 if __name__ == '__main__':
6bbc4867a795 begin porting from shell function
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 import sys
516
c78da6f7ca79 python/quotemail.py
Jeff Hammel <jhammel@mozilla.com>
parents: 365
diff changeset
14 import optparse
c78da6f7ca79 python/quotemail.py
Jeff Hammel <jhammel@mozilla.com>
parents: 365
diff changeset
15 usage = '%prog [options] [file] <file2> <...>'
c78da6f7ca79 python/quotemail.py
Jeff Hammel <jhammel@mozilla.com>
parents: 365
diff changeset
16 parser = optparse.OptionParser(usage=usage)
c78da6f7ca79 python/quotemail.py
Jeff Hammel <jhammel@mozilla.com>
parents: 365
diff changeset
17 parser.add_option('-i', '--in-place', dest='in_place',
c78da6f7ca79 python/quotemail.py
Jeff Hammel <jhammel@mozilla.com>
parents: 365
diff changeset
18 action='store_true', default=False,
c78da6f7ca79 python/quotemail.py
Jeff Hammel <jhammel@mozilla.com>
parents: 365
diff changeset
19 help="")
c78da6f7ca79 python/quotemail.py
Jeff Hammel <jhammel@mozilla.com>
parents: 365
diff changeset
20 options, args = parser.parse_args()
c78da6f7ca79 python/quotemail.py
Jeff Hammel <jhammel@mozilla.com>
parents: 365
diff changeset
21 if args:
c78da6f7ca79 python/quotemail.py
Jeff Hammel <jhammel@mozilla.com>
parents: 365
diff changeset
22 for arg in args:
c78da6f7ca79 python/quotemail.py
Jeff Hammel <jhammel@mozilla.com>
parents: 365
diff changeset
23 with file(arg) as f:
c78da6f7ca79 python/quotemail.py
Jeff Hammel <jhammel@mozilla.com>
parents: 365
diff changeset
24 contents = f.read()
c78da6f7ca79 python/quotemail.py
Jeff Hammel <jhammel@mozilla.com>
parents: 365
diff changeset
25 quoted = prefix(contents)
c78da6f7ca79 python/quotemail.py
Jeff Hammel <jhammel@mozilla.com>
parents: 365
diff changeset
26 if options.in_place:
c78da6f7ca79 python/quotemail.py
Jeff Hammel <jhammel@mozilla.com>
parents: 365
diff changeset
27 with file(arg, 'w') as f:
c78da6f7ca79 python/quotemail.py
Jeff Hammel <jhammel@mozilla.com>
parents: 365
diff changeset
28 f.write(quoted)
c78da6f7ca79 python/quotemail.py
Jeff Hammel <jhammel@mozilla.com>
parents: 365
diff changeset
29 else:
c78da6f7ca79 python/quotemail.py
Jeff Hammel <jhammel@mozilla.com>
parents: 365
diff changeset
30 print quoted
c78da6f7ca79 python/quotemail.py
Jeff Hammel <jhammel@mozilla.com>
parents: 365
diff changeset
31 else:
c78da6f7ca79 python/quotemail.py
Jeff Hammel <jhammel@mozilla.com>
parents: 365
diff changeset
32 print prefix(sys.stdin.read())