annotate textshaper/onelineit.py @ 47:6c7ca72777af

add a test all convenience
author Jeff Hammel <k0scist@gmail.com>
date Sat, 16 May 2015 19:02:03 -0700
parents 21b6a9569f21
children
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
43
21b6a9569f21 onelineit
Jeff Hammel <k0scist@gmail.com>
parents: 42
diff changeset
8 from .decorator import lines
42
1a80204bd562 basic cli
Jeff Hammel <k0scist@gmail.com>
parents: 41
diff changeset
9
43
21b6a9569f21 onelineit
Jeff Hammel <k0scist@gmail.com>
parents: 42
diff changeset
10 @lines
40
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11 def onelineit(string):
42
1a80204bd562 basic cli
Jeff Hammel <k0scist@gmail.com>
parents: 41
diff changeset
12 """make a string one line"""
1a80204bd562 basic cli
Jeff Hammel <k0scist@gmail.com>
parents: 41
diff changeset
13
40
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14 string = [ i.strip() or '\n' for i in string ]
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15 string = ' '.join(string)
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16 string = string.split('\n')
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17 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
18
43
21b6a9569f21 onelineit
Jeff Hammel <k0scist@gmail.com>
parents: 42
diff changeset
19 return '\n\n'.join(string).splitlines()
40
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
20
42
1a80204bd562 basic cli
Jeff Hammel <k0scist@gmail.com>
parents: 41
diff changeset
21 def main(args=sys.argv[1:]):
1a80204bd562 basic cli
Jeff Hammel <k0scist@gmail.com>
parents: 41
diff changeset
22 """CLI"""
1a80204bd562 basic cli
Jeff Hammel <k0scist@gmail.com>
parents: 41
diff changeset
23 print (onelineit(sys.stdin.read()))
1a80204bd562 basic cli
Jeff Hammel <k0scist@gmail.com>
parents: 41
diff changeset
24
40
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
25 if __name__ == '__main__':
42
1a80204bd562 basic cli
Jeff Hammel <k0scist@gmail.com>
parents: 41
diff changeset
26 main()