Skip to content

Instantly share code, notes, and snippets.

@gurix
Created March 3, 2020 15:25
Show Gist options
  • Save gurix/716c1b5e17851f6e9f3dbede62f34b37 to your computer and use it in GitHub Desktop.
Save gurix/716c1b5e17851f6e9f3dbede62f34b37 to your computer and use it in GitHub Desktop.
A script to determine what ruby versions for you use for different projects in a workspace.
#!/usr/bin/env python3
import glob, os, sys
from collections import Counter
# It is necessary to pass a directory in which we want to look for a ruby version.
if len(sys.argv) < 2:
sys.exit("usage: %s dir \n\n dir : Direcotry to look up for ruby version" % sys.argv[0])
# Validate the specified directory.
path_argument = sys.argv[1]
if os.path.isdir(path_argument):
base_directory = path_argument
else:
sys.exit("%s cannot be found or is not a directory" % path_argument)
ruby_versions = []
# Print specified ruby version for each directory
for file in glob.glob(base_directory + "/**/.ruby-version", recursive=True):
ruby_version = open(file, 'r').readline().strip()
print("%s: %s" % (file, ruby_version))
ruby_versions.append(ruby_version)
print('--------------- Count by version ---------------')
counted_versions = Counter(ruby_versions)
for i in sorted(counted_versions):
print("%s: %i" % (i, counted_versions[i]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment