Created
December 9, 2013 00:32
-
-
Save zed/7865666 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| """Print symlinks in the $PATH that point to `*.py` files.""" | |
| import os | |
| seen = set() | |
| for dirpath in os.environ.get('PATH', '').split(os.pathsep): | |
| if not os.path.isdir(dirpath): # this follows symlinks | |
| continue # visit only directories | |
| # visit "each" directory only once | |
| p = os.path.realpath(os.path.normcase(dirpath)) | |
| if p in seen: | |
| continue | |
| seen.add(p) | |
| for filename in os.listdir(dirpath): | |
| path = os.path.join(dirpath, filename) | |
| if os.path.islink(path): | |
| target = os.readlink(path) | |
| if target.endswith('.py'): | |
| print("%s -> %s" % (path, target)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment