# HG changeset patch # User Jeff Hammel # Date 1393184497 28800 # Node ID c23782a7b7ba6115d1fc8e764eafb9bd8c046b83 # Parent a43d0ad17c295b1414a6b8c25f3acd1d263f5952 more hookups, yo diff -r a43d0ad17c29 -r c23782a7b7ba setup.py --- a/setup.py Sun Feb 23 10:59:10 2014 -0800 +++ b/setup.py Sun Feb 23 11:41:37 2014 -0800 @@ -13,8 +13,9 @@ from setuptools import setup kw['entry_points'] = """ [console_scripts] + indent = textshaper.indent:main + quote = textshaper.quote:main textshaper = textshaper.main:main - indent = textshaper.indent:main url2txt = textshaper.url2txt:main """ kw['install_requires'] = dependencies diff -r a43d0ad17c29 -r c23782a7b7ba textshaper/indent.py --- a/textshaper/indent.py Sun Feb 23 10:59:10 2014 -0800 +++ b/textshaper/indent.py Sun Feb 23 11:41:37 2014 -0800 @@ -48,6 +48,7 @@ parser.add_argument('-o', '--output', dest='output', help="output file or stdout if not given") + def main(args=sys.argv[1:]): # parse command line @@ -60,7 +61,7 @@ for f in _files(): # indent the text - indented = indent(f) + indented = '\n'.join(indent(f)) # append to output if options.output: diff -r a43d0ad17c29 -r c23782a7b7ba textshaper/quote.py --- a/textshaper/quote.py Sun Feb 23 10:59:10 2014 -0800 +++ b/textshaper/quote.py Sun Feb 23 11:41:37 2014 -0800 @@ -2,28 +2,36 @@ # -*- coding: utf-8 -*- """ -split some lines +quote some lines """ import argparse import os import sys +def quotelines(text, quote="'", close_quote=None): + """ + individually quote each line of text + + quote -- quote character to use + close_quote -- closing quote character, if different from opening quote + """ + + if close_quote is None: + close_quote = quote + return ["{}{}{}".format(quote, line, close_quote) for line in lines] + + def main(args=sys.argv[1:]): + """CLI""" parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('input', nargs='?', type=argparse.FileType('r'), default=sys.stdin, help='input file, or read from stdin if ommitted') - parser.add_argument('--quote', dest='quote', - action='store_true', default=False) options = parser.parse_args(args) - read = options.input.read() - - lines = read.strip().split() - if options.quote: - lines = ["'{}'".format(line) for line in lines] + lines = quotelines(options.input) print '\n'.join(lines) diff -r a43d0ad17c29 -r c23782a7b7ba textshaper/whitespace.py --- a/textshaper/whitespace.py Sun Feb 23 10:59:10 2014 -0800 +++ b/textshaper/whitespace.py Sun Feb 23 11:41:37 2014 -0800 @@ -17,6 +17,7 @@ joiner = ' ' if separator is None else separator return joiner.join(text.strip().split(separator)) + def filename2name(text, whitespace=('_',), replacement=' '): """ convert filename to name