annotate textshaper/quote.py @ 26:c23782a7b7ba

more hookups, yo
author Jeff Hammel <k0scist@gmail.com>
date Sun, 23 Feb 2014 11:41:37 -0800
parents a43d0ad17c29
children 4aba57a33376
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
30f1781024a4 add splitline functionality
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
30f1781024a4 add splitline functionality
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
30f1781024a4 add splitline functionality
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3
30f1781024a4 add splitline functionality
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 """
26
c23782a7b7ba more hookups, yo
Jeff Hammel <k0scist@gmail.com>
parents: 25
diff changeset
5 quote some lines
14
30f1781024a4 add splitline functionality
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6 """
30f1781024a4 add splitline functionality
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7
30f1781024a4 add splitline functionality
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 import argparse
30f1781024a4 add splitline functionality
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 import os
30f1781024a4 add splitline functionality
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10 import sys
30f1781024a4 add splitline functionality
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11
26
c23782a7b7ba more hookups, yo
Jeff Hammel <k0scist@gmail.com>
parents: 25
diff changeset
12 def quotelines(text, quote="'", close_quote=None):
c23782a7b7ba more hookups, yo
Jeff Hammel <k0scist@gmail.com>
parents: 25
diff changeset
13 """
c23782a7b7ba more hookups, yo
Jeff Hammel <k0scist@gmail.com>
parents: 25
diff changeset
14 individually quote each line of text
c23782a7b7ba more hookups, yo
Jeff Hammel <k0scist@gmail.com>
parents: 25
diff changeset
15
c23782a7b7ba more hookups, yo
Jeff Hammel <k0scist@gmail.com>
parents: 25
diff changeset
16 quote -- quote character to use
c23782a7b7ba more hookups, yo
Jeff Hammel <k0scist@gmail.com>
parents: 25
diff changeset
17 close_quote -- closing quote character, if different from opening quote
c23782a7b7ba more hookups, yo
Jeff Hammel <k0scist@gmail.com>
parents: 25
diff changeset
18 """
c23782a7b7ba more hookups, yo
Jeff Hammel <k0scist@gmail.com>
parents: 25
diff changeset
19
c23782a7b7ba more hookups, yo
Jeff Hammel <k0scist@gmail.com>
parents: 25
diff changeset
20 if close_quote is None:
c23782a7b7ba more hookups, yo
Jeff Hammel <k0scist@gmail.com>
parents: 25
diff changeset
21 close_quote = quote
c23782a7b7ba more hookups, yo
Jeff Hammel <k0scist@gmail.com>
parents: 25
diff changeset
22 return ["{}{}{}".format(quote, line, close_quote) for line in lines]
c23782a7b7ba more hookups, yo
Jeff Hammel <k0scist@gmail.com>
parents: 25
diff changeset
23
c23782a7b7ba more hookups, yo
Jeff Hammel <k0scist@gmail.com>
parents: 25
diff changeset
24
14
30f1781024a4 add splitline functionality
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
25 def main(args=sys.argv[1:]):
26
c23782a7b7ba more hookups, yo
Jeff Hammel <k0scist@gmail.com>
parents: 25
diff changeset
26 """CLI"""
14
30f1781024a4 add splitline functionality
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
27
30f1781024a4 add splitline functionality
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
28 parser = argparse.ArgumentParser(description=__doc__)
30f1781024a4 add splitline functionality
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
29 parser.add_argument('input', nargs='?',
30f1781024a4 add splitline functionality
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
30 type=argparse.FileType('r'), default=sys.stdin,
30f1781024a4 add splitline functionality
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
31 help='input file, or read from stdin if ommitted')
30f1781024a4 add splitline functionality
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
32 options = parser.parse_args(args)
30f1781024a4 add splitline functionality
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
33
26
c23782a7b7ba more hookups, yo
Jeff Hammel <k0scist@gmail.com>
parents: 25
diff changeset
34 lines = quotelines(options.input)
14
30f1781024a4 add splitline functionality
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
35
30f1781024a4 add splitline functionality
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
36 print '\n'.join(lines)
30f1781024a4 add splitline functionality
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
37
30f1781024a4 add splitline functionality
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
38 if __name__ == '__main__':
30f1781024a4 add splitline functionality
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
39 main()