Last active
May 17, 2017 16:47
-
-
Save jjam3774/b6510218e4a281849b16 to your computer and use it in GitHub Desktop.
Screening Script
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
#!/usr/bin/ruby | |
################## | |
# Copy files | |
################## | |
require 'fileutils' | |
################### | |
# To Generate UUID | |
################### | |
require "securerandom" | |
class FileConf | |
class << self | |
################### | |
# Method to create working dir | |
################### | |
def setup_dir | |
begin | |
if File.directory?("test_dir") | |
puts "Dir already exists" | |
else | |
Dir.mkdir('test_dir') | |
end | |
end | |
end | |
def json_template(id) | |
################### | |
# Method to create the json templates | |
################### | |
File.open("test_dir/temp_#{id}.json", 'w'){|i| | |
templ = %Q<{ | |
"id": "#{Random.rand(20)}#{Random.rand(20)}", | |
"version": 1.0.1.1, | |
"service": "ftp", | |
"os": "linux" | |
} | |
> | |
i.write(templ) | |
} | |
end | |
def copy_json | |
################## | |
# Method that will copy from test_dir to uuid | |
################## | |
if File.directory?("uuid_") | |
puts "uuid exists" | |
else | |
Dir.mkdir("uuid_") | |
build_files = Dir.glob("test_dir/**") | |
build_files.each{|file| | |
FileUtils.copy(file,"uuid_/") | |
} | |
end | |
end | |
def rename_json | |
################## | |
# Method that will rename the templates to UUID | |
################## | |
uuid_files = Dir.glob("uuid_/**") | |
uuid_files.each{|file| | |
File.rename(file,"uuid_/#{SecureRandom.uuid}.json") | |
} | |
end | |
def set_value(file) | |
################# | |
# Setting Value to be incremented by +1 | |
################# | |
File.foreach(file) do |f| | |
if f =~ /version/ | |
reg = f | |
build_no = f.chomp(',').split('.')[3].to_i + 1 | |
yield reg, build_no | |
end | |
end | |
end | |
def change_build | |
################ | |
# Changing the build number | |
################ | |
uuid_file = Dir.glob("uuid_/**") | |
uuid_file.each{|file| | |
set_value(file){|reg,build_no| | |
spec = File.open(file, "r+") | |
e = spec.read() | |
spec.close | |
e.gsub!(/#{reg}/, %{ "version": 1.0.1.#{build_no},\n}) | |
File.open(file, "r+") { |f| f << e } | |
} | |
} | |
end | |
end | |
end | |
FileConf.setup_dir | |
(1..50).each{|i| | |
FileConf.json_template(i) | |
} | |
################ | |
FileConf.copy_json | |
FileConf.rename_json | |
FileConf.change_build |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment