Mercurial > hg > decoupage
comparison decoupage/index.py @ 107:450aff4c97e3
py35 compat
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Fri, 31 Mar 2017 17:06:59 -0700 |
parents | 4a9c5cf9fec9 |
children |
comparison
equal
deleted
inserted
replaced
106:1f84c6def8bd | 107:450aff4c97e3 |
---|---|
5 index.ini | 5 index.ini |
6 """ | 6 """ |
7 | 7 |
8 import argparse | 8 import argparse |
9 import os | 9 import os |
10 import subprocess | |
11 import sys | 10 import sys |
12 | 11 |
13 here = os.path.dirname(os.path.realpath(__file__)) | 12 here = os.path.dirname(os.path.realpath(__file__)) |
14 string = (str, unicode) | |
15 | 13 |
16 def index(directory): | 14 def index(directory): |
15 """ | |
16 returns string representation of directory | |
17 """ | |
18 | |
17 return '\n'.join(['{name} = {name}'.format(name=name) | 19 return '\n'.join(['{name} = {name}'.format(name=name) |
18 for name in sorted(os.listdir(directory), key=lambda name: name.lower()) | 20 for name in sorted(os.listdir(directory), |
21 key=lambda name: name.lower()) | |
19 if not name.startswith('.')]) | 22 if not name.startswith('.')]) |
20 | 23 |
24 | |
21 def main(args=sys.argv[1:]): | 25 def main(args=sys.argv[1:]): |
26 """CLI""" | |
22 | 27 |
28 # parse command line | |
23 parser = argparse.ArgumentParser(description=__doc__) | 29 parser = argparse.ArgumentParser(description=__doc__) |
24 parser.add_argument('directory', help='directory') | 30 parser.add_argument('directory', help='directory') |
25 parser.add_argument('-o', '--output', dest='output', | 31 parser.add_argument('-o', '--output', dest='output', |
26 type=argparse.FileType('w'), default=sys.stdout, | 32 type=argparse.FileType('w'), default=sys.stdout, |
27 help='output') | 33 help='output') |
28 options = parser.parse_args(args) | 34 options = parser.parse_args(args) |
29 | 35 |
36 # sanity | |
37 if not os.path.isdir(options.directory): | |
38 parser.error("Not a directory: '{}'".format(options.directory)) | |
39 | |
40 # output | |
41 options.output.write(index(options.directory)) | |
42 | |
43 | |
30 if __name__ == '__main__': | 44 if __name__ == '__main__': |
31 main() | 45 main() |