comparison makeitso/mkpydir.py @ 189:7d8f3660fabb

fix syntax error and use argparse
author Jeff Hammel <k0scist@gmail.com>
date Fri, 02 May 2014 10:38:12 -0700
parents f6474c7dfb39
children
comparison
equal deleted inserted replaced
188:1bcf60bcc455 189:7d8f3660fabb
2 2
3 """ 3 """
4 make a python module directory with an __init__.py 4 make a python module directory with an __init__.py
5 """ 5 """
6 6
7 import optparse 7 import argparse
8 import os 8 import os
9 import sys 9 import sys
10 10
11 def main(args=sys.argv[1:]): 11 def main(args=sys.argv[1:]):
12 """CLI"""
12 13
13 usage = '%prog [options] directory_name' 14 parser = argparse.ArgumentParser(description=__doc__)
14 parser = optparse.OptionParser(usage=usage, description=__doc__) 15 parser.add_argument('directory')
15 options, args = parser.parse_args(args) 16 options = parser.parse_args(args)
16 if len(args) != 1:
17 parser.print_usage()
18 parser.error()
19 17
20 os.makedirs(args[0]) 18 os.makedirs(options.directory)
21 init = os.path.join(args[0], '__init__.py') 19 init = os.path.join(options.directory, '__init__.py')
22 with f as open(init, 'w'): 20 with open(init, 'w') as f:
23 f.write('#\n') 21 f.write('#\n')
24 22
25 if __name__ == '__main__': 23 if __name__ == '__main__':
26 main() 24 main()