comparison textshaper/indent.py @ 10:466386702968

more stuff
author Jeff Hammel <k0scist@gmail.com>
date Sat, 18 Jan 2014 09:28:55 -0800
parents 71fb16088d54
children 0d0db0d79bfd
comparison
equal deleted inserted replaced
9:71fb16088d54 10:466386702968
37 break 37 break
38 else: 38 else:
39 index = indentation 39 index = indentation
40 retval.append(line[index:]) 40 retval.append(line[index:])
41 41
42 return retval
43
44
42 def main(args=sys.argv[1:]): 45 def main(args=sys.argv[1:]):
43 46
44 usage = '%prog [options]' 47 # parse command line
48 usage = '%prog [options] [file] [file2] [...]'
49 description = """indent files or stdin if no files given"""
45 parser = optparse.OptionParser(usage=usage, description=__doc__) 50 parser = optparse.OptionParser(usage=usage, description=__doc__)
46 options, args = parser.parse_args(args) 51 parser.add_option('-o', '--output', dest='output',
52 help="output file or stdout if not given")
53 options, files = parser.parse_args(args)
47 54
55 # input from files or stdin
56 if files:
57 missing = [not os.path.exists(filename) for filename in files]
58 if missing:
59 parser.error("File(s) not found: %s" % ', '.join(missing))
60 def _files():
61 for filename in files:
62 with open(f, 'r') as f:
63 yield f
64 else:
65 def _files():
66 yield sys.stdin
67
68 # process input
69 for f in _files():
70 print f
48 71
49 if __name__ == '__main__': 72 if __name__ == '__main__':
50 main() 73 main()