Created
November 11, 2014 12:38
-
-
Save flyte/b010156776a470304ffb to your computer and use it in GitHub Desktop.
Find all Vagrantfiles and check their status
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
from subprocess import check_output | |
import argparse | |
import os | |
import re | |
BASE_DIR = os.path.abspath(".") | |
STATUS_LINE_RE = r"^(\w+?)\s+?(\w.+?)\s\((.+?)\)$" | |
if __name__ == "__main__": | |
p = argparse.ArgumentParser() | |
vagrantfiles = check_output("find . -type f -name Vagrantfile".split()).split("\n") | |
print "Found %d Vagrantfile(s):" % len(vagrantfiles) | |
for vf in vagrantfiles: | |
if not vf: | |
continue | |
directory = os.path.dirname(vf) | |
os.chdir(os.path.join(BASE_DIR, directory)) | |
try: | |
output = check_output("vagrant status".split()).split("\n") | |
except Exception, e: | |
print "Error checking vagrant status in dir %s: %s" % (directory, e) | |
continue | |
try: | |
match = re.match(STATUS_LINE_RE, output[2]) | |
name, status, handler = match.group(1, 2, 3) | |
except Exception, e: | |
print "Error parsing vagrant status in dir %s: %s" % (directory, output[2]) | |
print "%s: %s" % (directory, status) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or...
http://vagrantmanager.com/
😄