Mercurial > hg > config
comparison python/tree2.py @ 390:9d02187611ae
make delimeters CLI switchable
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Sat, 27 Jul 2013 20:09:49 -0700 |
parents | 2d4dfe1dc632 |
children |
comparison
equal
deleted
inserted
replaced
389:2d4dfe1dc632 | 390:9d02187611ae |
---|---|
97 | 97 |
98 return '\n'.join(retval) | 98 return '\n'.join(retval) |
99 | 99 |
100 def main(args=sys.argv[1:]): | 100 def main(args=sys.argv[1:]): |
101 | 101 |
102 # parse command line options | |
102 usage = '%prog [options]' | 103 usage = '%prog [options]' |
103 parser = optparse.OptionParser(usage=usage, description=__doc__) | 104 parser = optparse.OptionParser(usage=usage, description=__doc__) |
105 parser.add_option('-a', '--ascii', dest='use_ascii', | |
106 action='store_true', default=False, | |
107 help="use ascii delimeters (%s)" % ascii_delimeters) | |
104 options, args = parser.parse_args(args) | 108 options, args = parser.parse_args(args) |
105 if not args: | 109 if not args: |
106 args = ['.'] | 110 args = ['.'] |
107 | 111 |
112 # sanity check | |
108 not_directory = [arg for arg in args | 113 not_directory = [arg for arg in args |
109 if not os.path.isdir(arg)] | 114 if not os.path.isdir(arg)] |
110 if not_directory: | 115 if not_directory: |
111 parser.error("Not a directory: %s" % (', '.join(not_directory))) | 116 parser.error("Not a directory: %s" % (', '.join(not_directory))) |
112 | 117 |
118 delimeters = unicode_delimeters | |
119 if options.use_ascii: | |
120 delimeters = ascii_delimeters | |
121 | |
122 # print the tree | |
113 for arg in args: | 123 for arg in args: |
114 print (tree(arg)) | 124 print (tree(arg, **delimeters)) |
115 | 125 |
116 if __name__ == '__main__': | 126 if __name__ == '__main__': |
117 main() | 127 main() |