Mercurial > hg > config
annotate python/quotemail.py @ 701:de7bf9523e21
-
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Wed, 13 Aug 2014 13:16:56 -0700 |
parents | c78da6f7ca79 |
children |
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 | 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 | 14 import optparse |
15 usage = '%prog [options] [file] <file2> <...>' | |
16 parser = optparse.OptionParser(usage=usage) | |
17 parser.add_option('-i', '--in-place', dest='in_place', | |
18 action='store_true', default=False, | |
19 help="") | |
20 options, args = parser.parse_args() | |
21 if args: | |
22 for arg in args: | |
23 with file(arg) as f: | |
24 contents = f.read() | |
25 quoted = prefix(contents) | |
26 if options.in_place: | |
27 with file(arg, 'w') as f: | |
28 f.write(quoted) | |
29 else: | |
30 print quoted | |
31 else: | |
32 print prefix(sys.stdin.read()) |