Created
April 26, 2010 17:20
-
-
Save patroza/379609 to your computer and use it in GitHub Desktop.
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
# by Sickboy | |
# Rename any folder or file in the given path, if it has uppercase characters, to lowercase | |
# If the filename is .repository.yml, update the :pack and :remote hashes with lowercase keys | |
require 'fileutils' | |
require 'yaml' | |
dir = ARGV[0] | |
ARGV.shift | |
def check_dir(dir) | |
if File.directory?(dir) | |
entry = File.join(dir, ".repository.yml") | |
if File.exists?(entry) | |
puts "Processing: #{entry}" | |
config = YAML::load_file(entry) | |
[:pack, :wd].each do |typ| | |
ar = [] | |
config[typ].each { |e| ar << [e[0].downcase, e[1]] } | |
config[typ] = ar | |
end | |
File.open(entry, 'w') {|f| f.puts config.to_yaml }#.to_s | |
end | |
Dir.glob(File.join(dir, "**", "*")).each do |e| | |
cleanup(e) | |
end | |
end | |
end | |
def cleanup(entry) | |
dirname = File.dirname(entry) | |
base = File.basename(entry) | |
if base =~ /[A-Z]/ | |
newentry = File.join(dirname, base.downcase) | |
FileUtils.mv(entry, "#{entry}_tmp") | |
FileUtils.mv("#{entry}_tmp", newentry) | |
entry = newentry | |
base = File.basename(entry) | |
end | |
if File.directory?(entry) | |
check_dir(File.join(entry, ".rsync")) | |
check_dir(File.join(entry, ".rsync/.pack")) | |
end | |
end | |
Dir.glob(File.join(dir, '**', '*')).each do |entry| | |
cleanup(entry) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment