annotate python/directories.py @ 585:1e3b778be7e4

STUB: .emacs
author Jeff Hammel <k0scist@gmail.com>
date Thu, 23 Jan 2014 11:27:02 -0800
parents a8982ae84a9b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
407
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/env python
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 """
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 ls unique file paths
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 """
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 import optparse
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8 import os
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 import sys
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 here = os.path.dirname(os.path.realpath(__file__))
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 def main(args=sys.argv[1:]):
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 usage = '%prog [options]'
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16 parser = optparse.OptionParser(usage=usage, description=__doc__)
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17 parser.add_option('--strip', default='? ')
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 options, args = parser.parse_args(args)
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20 _input = sys.stdin.read()
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21 lines = [i.strip() for i in _input.splitlines()
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
22 if i.strip()]
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23 lines = [i[len(options.strip):] if i.startswith(options.strip) else i
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24 for i in lines]
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
25 paths = set([i.split(os.path.sep)[0] for i in lines])
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
26 for i in sorted(paths):
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
27 print i
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
28
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
29 if __name__ == '__main__':
a8982ae84a9b disaster recovery
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
30 main()