annotate textshaper/onelineit.py @ 42:1a80204bd562

basic cli
author Jeff Hammel <k0scist@gmail.com>
date Mon, 25 Aug 2014 19:31:16 -0700
parents 56199789d2a0
children 21b6a9569f21
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2
42
1a80204bd562 basic cli
Jeff Hammel <k0scist@gmail.com>
parents: 41
diff changeset
3 """
1a80204bd562 basic cli
Jeff Hammel <k0scist@gmail.com>
parents: 41
diff changeset
4 make a string one line
1a80204bd562 basic cli
Jeff Hammel <k0scist@gmail.com>
parents: 41
diff changeset
5 """
1a80204bd562 basic cli
Jeff Hammel <k0scist@gmail.com>
parents: 41
diff changeset
6
1a80204bd562 basic cli
Jeff Hammel <k0scist@gmail.com>
parents: 41
diff changeset
7 import sys
1a80204bd562 basic cli
Jeff Hammel <k0scist@gmail.com>
parents: 41
diff changeset
8
40
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 def onelineit(string):
42
1a80204bd562 basic cli
Jeff Hammel <k0scist@gmail.com>
parents: 41
diff changeset
10 """make a string one line"""
1a80204bd562 basic cli
Jeff Hammel <k0scist@gmail.com>
parents: 41
diff changeset
11
40
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12 string = string.split('\n')
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13 string = [ i.strip() or '\n' for i in string ]
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14 string = ' '.join(string)
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15 string = string.split('\n')
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16 string = [ i.strip() for i in string if i.strip() ]
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18 return '\n\n'.join(string)
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19
42
1a80204bd562 basic cli
Jeff Hammel <k0scist@gmail.com>
parents: 41
diff changeset
20 def main(args=sys.argv[1:]):
1a80204bd562 basic cli
Jeff Hammel <k0scist@gmail.com>
parents: 41
diff changeset
21 """CLI"""
1a80204bd562 basic cli
Jeff Hammel <k0scist@gmail.com>
parents: 41
diff changeset
22 print (onelineit(sys.stdin.read()))
1a80204bd562 basic cli
Jeff Hammel <k0scist@gmail.com>
parents: 41
diff changeset
23
40
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
24 if __name__ == '__main__':
42
1a80204bd562 basic cli
Jeff Hammel <k0scist@gmail.com>
parents: 41
diff changeset
25 main()