Created
October 30, 2016 18:12
-
-
Save isle2983/79535a443caf5cce26d5b56eb0bf56ee to your computer and use it in GitHub Desktop.
invoke a command for every directory in a git repo
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/python3 | |
import os | |
import sys | |
USAGE = """ | |
$ ./walk.py <repo> <outputdir> | |
""" | |
if len(sys.argv) != 3: | |
print(USAGE) | |
sys.exit() | |
if not (os.path.isdir(sys.argv[1])): | |
print(USAGE) | |
sys.exit() | |
repo = os.path.abspath(sys.argv[1]) | |
if not (os.path.isdir(sys.argv[2])): | |
print(USAGE) | |
sys.exit() | |
outputDir = os.path.abspath(sys.argv[2]) | |
os.chdir(repo) | |
files = [line.rstrip() for line in os.popen("git ls-files").readlines()] | |
paths = sorted(list(set([os.path.dirname(f) for f in files]))) | |
def writeOutput(path, output): | |
filename = os.path.join(outputDir, path.replace("/", "-") + '.txt') | |
outputfile = open(filename, "w") | |
outputfile.write(output) | |
outputfile.close() | |
def doFame(path): | |
print(path) | |
output = os.popen('find .').read() | |
print(output) | |
writeOutput(path, output) | |
for p in paths: | |
os.chdir(os.path.abspath(os.path.join(repo, p))) | |
doFame(p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment