Last active
December 14, 2015 22:29
-
-
Save dgrant/5159042 to your computer and use it in GitHub Desktop.
Find any VCS directories in the specified path (ie. git, mercurial, svn, CVS)
This file contains 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 python3 | |
""" | |
Find all the VCS controlled directories in a file path | |
""" | |
import argparse | |
import os | |
EXTS = ['.git', '.hg', '.svn', 'CVS'] | |
def find(path): | |
""" Find all VCS dirs in specified path """ | |
found_roots = [] | |
for root, dirs, _, in os.walk(path): | |
for folder in dirs: | |
if folder in EXTS: | |
# We've seen a matching dir | |
# See if we already found a parent | |
for found_root in found_roots: | |
if root.find(found_root) == 0: | |
break | |
else: | |
found_roots.append(root) | |
for root in found_roots: | |
print(root) | |
def main(): | |
"""Main function""" | |
parser = argparse.ArgumentParser() | |
parser.add_argument('path', help='path to search for VCS dirs') | |
args = parser.parse_args() | |
find(args.path) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment