annotate textshaper/main.py @ 6:6e382347af17

cleanup
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 04 Oct 2013 13:58:45 -0700
parents 0a800613af9a
children 71fb16088d54
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/env python
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 """
4
26bb5e99f76c textshaper/main.py
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
5 package to shape text blocks
0
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6 """
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8 import optparse
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 import os
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10 import subprocess
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 import sys
3
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
12 import time
0
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13
5
0a800613af9a textshaper/main.py
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
14 def display(content):
4
26bb5e99f76c textshaper/main.py
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
15 print content
26bb5e99f76c textshaper/main.py
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
16 print '--'
26bb5e99f76c textshaper/main.py
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
17 nlines = len(content.splitlines())
26bb5e99f76c textshaper/main.py
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
18 print '%d lines' % nlines
26bb5e99f76c textshaper/main.py
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
19
0
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20 def add_options(parser):
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21 """add options to the OptionParser instance"""
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
22
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23 def main(args=sys.argv[1:]):
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
25 # parse command line options
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
26 usage = '%prog [options] ...'
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
27 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter):
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
28 """description formatter for console script entry point"""
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
29 def format_description(self, description):
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
30 if description:
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
31 return description.strip() + '\n'
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
32 else:
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
33 return ''
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
34 parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter())
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
35 options, args = parser.parse_args(args)
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
36
3
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
37 # read from stdin
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
38 content = sys.stdin.read()
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
39
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
40 # print formatted content
4
26bb5e99f76c textshaper/main.py
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
41 display(content)
3
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
42
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
43 while True:
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
44 time.sleep(1) # XXX
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
45
0
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
46 if __name__ == '__main__':
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
47 main()
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
48