Last active
December 19, 2016 07:10
-
-
Save jamiecook/559d49950e71b6586bc5d9b660f7d2f8 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
#!/usr/bin/ruby | |
# This script adds a new line to the start of each rb file in your jobs folder | |
# Store this outside your job folder (or it will try to convert itself) and then invoke it from the command line | |
# ruby convert_job_folder d:/16089/foo 918 | |
# I would advise you to make a backup of that folder before running :) | |
require 'fileutils' | |
def convert_folder(jobs_folder) | |
time_stamp = Time.now.strftime('%Y%m%d-%H%M') | |
puts "Converting folder #{jobs_folder} (timestamp: #{time_stamp})" | |
files = Dir.glob(File.join(jobs_folder, '**', '*.rb')).reject { |e| e =~ /setup_bedrock.rb/ || e =~ /startup.rb/i } | |
files.each { |file| | |
backup_file = "#{file}#{time_stamp}" | |
FileUtils.cp(file, backup_file) | |
data = IO.readlines(file) | |
next if data.any? { |line| line =~ /require.*setup_bedrock/ } | |
File.open(file, 'w') { |f| | |
f.puts('require "setup_bedrock"') | |
f.puts('') | |
data.each { |line| | |
f.puts(line) | |
} | |
} | |
} | |
end | |
def create_setup_file(jobs_folder, bedrock_version) | |
setup_file = File.join(jobs_folder, 'setup_bedrock.rb') | |
return if File.exist?(setup_file) | |
File.open(setup_file, 'w') { |f| | |
f.puts("use_bedrock(#{bedrock_version})"); | |
} | |
end | |
raise "USAGE: convert_job_folder job_folder bedrock_version" unless ARGV.size == 2 | |
jobs_folder = ARGV[0].gsub(/\\/, '/') | |
bedrock_version = ARGV[1] | |
create_setup_file(jobs_folder, bedrock_version) | |
convert_folder(jobs_folder) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script needs to be run from outside OT, and placed outside your jobs folder (so it doesn't try to convert itself). Call it from a cmd prompt, using the following syntax:
Someone help me tag Cameron and Louisa here.