<commit_before>TEST_DIR        = '/tmp/adva_cms'
TEST_ADVA_DIR   = TEST_DIR + '/vendor/adva'
CC_DIR          = '/srv/cruise/projects/adva-cms/work'
start_time      = Time.now # Just for fun :)

def patch_file(path, after, insert)
  content = File.open(path) { |f| f.read }
  content.gsub!(after, "#{after}\n#{insert}") unless content =~ /#{Regexp.escape(insert)}/mi
  File.open(path, 'w') { |f| f.write(content) }
end

File.unlink 'public/index.html' rescue Errno::ENOENT

rakefile("adva-cms.rake") do
  <<-src
    require 'tasks/rails'
    load 'vendor/adva/engines/adva_cms/lib/tasks/adva_cms.rake'
  src
end

file 'script/test-adva-cms', <<-src
  #!/usr/bin/env ruby
  paths = ARGV.clone
  load 'vendor/adva/script/test'
src

patch_file 'config/environment.rb',
  "require File.join(File.dirname(__FILE__), 'boot')",
  "require File.join(File.dirname(__FILE__), '../vendor/adva/engines/adva_cms/boot')"

run "cp -r #{CC_DIR} #{TEST_ADVA_DIR}"
run "patch -p0 < vendor/adva/patch-2.3/rails-2.3.patch"

rake "db:migrate:prepare"
run  "rake db:migrate"
rake "db:test:clone"

end_time = (Time.now - start_time).to_i
puts "Rails app setup, time elapsed #{end_time} seconds."<commit_msg>freeze rails to cc.template<commit_after>TEST_DIR        = '/tmp/adva_cms'
TEST_ADVA_DIR   = TEST_DIR + '/vendor/adva'
CC_DIR          = '/srv/cruise/projects/adva-cms/work'
start_time      = Time.now # Just for fun :)

def patch_file(path, after, insert)
  content = File.open(path) { |f| f.read }
  content.gsub!(after, "#{after}\n#{insert}") unless content =~ /#{Regexp.escape(insert)}/mi
  File.open(path, 'w') { |f| f.write(content) }
end

File.unlink 'public/index.html' rescue Errno::ENOENT

rakefile("adva-cms.rake") do
  <<-src
    require 'tasks/rails'
    load 'vendor/adva/engines/adva_cms/lib/tasks/adva_cms.rake'
  src
end

file 'script/test-adva-cms', <<-src
  #!/usr/bin/env ruby
  paths = ARGV.clone
  load 'vendor/adva/script/test'
src

patch_file 'config/environment.rb',
  "require File.join(File.dirname(__FILE__), 'boot')",
  "require File.join(File.dirname(__FILE__), '../vendor/adva/engines/adva_cms/boot')"

run "cp -r #{CC_DIR} #{TEST_ADVA_DIR}"

rake  "rails:freeze:gems"
run   "patch -p0 < vendor/adva/patch-2.3/rails-2.3.patch"

rake  "db:migrate:prepare"
run   "rake db:migrate"
rake  "db:test:clone"

end_time = (Time.now - start_time).to_i
puts  "Rails app setup, time elapsed #{end_time} seconds."
{'fraction_non_alphanumeric': 0.17364276833816825, 'fraction_numerical': 0.004144218814753419, 'mean_word_length': 3.9568788501026693, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6019913', 'n_tokens_mistral': 982, 'n_tokens_neox': 964, 'n_words': 180}