annotate textshaper/main.py @ 0:53cfd6e1ad0f

initial commit, from http://k0s.org/portfolio/ideas/textshaper.py , see also http://k0s.org/portfolio/ideas/cleanuptext.py So you have a block of text ... What do you want to do with it?!? == Desired Functionality == == Previous work == /corpus of past programs -> consolidate/ - onelineit - quoting - dequoting (including e.g. +/-, diff-ish shit) - removing timestamps - removing/adding irc quote tags Interface: - library code - (n)curses - javascript/REST Consider the pattern: * things that add and/or remove a thing * things that alter spacing == Reference == Previous k0s.ware (big and small): - http://k0s.org/hg/config/rev/5e0b4ec36013 Highly related (~> identity): http://k0s.org/portfolio/ideas/cleanuptext.py Ubuntu packages: - par (paragraph reformatter)
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 10 Aug 2013 15:47:30 -0700
parents
children 925a7959cd0b
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 """
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 package to shape text blocks
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
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 def add_options(parser):
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14 """add options to the OptionParser instance"""
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16 def main(args=sys.argv[1:]):
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 # parse command line options
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19 usage = '%prog [options] ...'
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter):
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21 """description formatter for console script entry point"""
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
22 def format_description(self, description):
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23 if description:
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24 return description.strip() + '\n'
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
25 else:
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
26 return ''
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
27 parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter())
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
28 options, args = parser.parse_args(args)
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
29
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
30 if __name__ == '__main__':
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
31 main()
53cfd6e1ad0f initial commit,
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
32