<commit_before>#!/usr/bin/env ruby
#
# wrapper to chef or puppet - uses impl to get chef or puppet version and setup:
#  create Gemfile, bundle install if different
#
require 'rubygems'
require 'json'
require 'yaml'
require 'optparse'

log_level = "info"
formatter = "null"

options = {}
OptionParser.new do |opts|
  opts.banner = "Usage: exec-order.rb [options]"

  opts.on("-d", "--[no-]debug", "Run in debug") do |d|
    log_level = "debug"
    formatter = "doc"
  end
end.parse!

impl = ARGV[0]
json_context = ARGV[1]
cookbook_path = ARGV[2] || ''
service_cookbooks = ARGV[3] || ''

puts "RUBY_PLATFORM: #{RUBY_PLATFORM}" if log_level == "debug"
case RUBY_PLATFORM
when /mingw/
  ostype = 'windows'
when /linux/
  ostype = 'linux'
end

puts "os: #{ostype}" if log_level == "debug"

prefix_root = ''
file_cache_path = '/tmp'
ci = json_context.split("/").last.gsub(".json","")
if ostype =~ /windows/
  prefix_root = 'c:/cygwin64'
  impl = 'oo::chef-12.11.18'
  json_context = prefix_root + json_context
end

def gen_gemfile_and_install (gems, dsl, ostype, log_level)

    rubygems_proxy = ENV['rubygems_proxy']

    if rubygems_proxy.nil? && File.file?('/opt/oneops/rubygems_proxy')
      rubygems_proxy = File.read('/opt/oneops/rubygems_proxy').chomp
    end

    gemfile_content = "source 'https://rubygems.org'\n"
    if !rubygems_proxy.nil?
      gemfile_content = "source '#{rubygems_proxy}'\n"
    end
    gems.each do |gem_set|
      if gem_set.size > 1
        gemfile_content += "gem '#{gem_set[0]}', '#{gem_set[1]}'\n"
      else
        gemfile_content += "gem '#{gem_set[0]}'\n"
      end
    end

    current_dir = `pwd`.chomp
    puts "pwd: #{current_dir}"

    File.open('Gemfile', 'w') {|f| f.write(gemfile_content) }
    method = "install"
    result = ""
    if ostype =~ /windows/
      `c:\\opscode\\chef\\embedded\\bin\\gem list | grep #{dsl}`
    else
      `gem list | grep #{dsl}`
    end
    if $?.to_i == 0
      method = "update"
    end
    cmd = ""
    start_time = Time.now.to_i
    if ostype =~ /windows/
      cmd = "c:/opscode/chef/embedded/bin/bundle #{method}"
    else
      cmd = "bundle #{method} --full-index"
    end
    puts cmd  
    ec = system cmd
    
    if !ec || ec.nil?
      puts "bundle #{method} --full-index failed with, #{$?}"
      exit 1
    end
    duration = Time.now.to_i - start_time
    puts "took: #{duration} sec"

    puts "change gem source back to rubygems_proxy"
    rubygems_proxy = `cat /opt/oneops/rubygems_proxy`.chomp
    puts "rubygems_proxy: #{rubygems_proxy}" if log_level == "debug"
    if ostype =~ /windows/
      system("c:/opscode/chef/embedded/bin/gem source --add #{rubygems_proxy}")
      sources = `c:\\opscode\\chef\\embedded\\bin\\gem source | egrep -v "CURRENT SOURCES|#{rubygems_proxy}"`.split("\n")
      sources.each do |source|
        system("c:/opscode/chef/embedded/bin/gem source --remove #{source}")
      end
      system("c:/opscode/chef/embedded/bin/gem source")
    else
      `gem source --add #{rubygems_proxy}`
      sources = `gem source | egrep -v "CURRENT SOURCES|#{rubygems_proxy}"`.split("\n")
      sources.each do |source|
        `gem source --remove #{source}`
      end
      `gem source`
    end
    
    cmd_to_patch_azure_blob_sdk = "sed -i -e's/2012-02-12/2014-02-14/' \"$(dirname `gem which azure`)/azure/core/http/http_request.rb\""
    system cmd_to_patch_azure_blob_sdk
end

# set cwd to same dir as the exe-order.rb file
Dir.chdir File.dirname(__FILE__)
gem_config = YAML::load(File.read('exec-gems.yaml'))

# ex) oo::chef-10.16.6::optional_uri_for_cookbook_or_module
dsl, version = impl.split("::")[1].split("-")

case dsl
when "chef"
  Dir.chdir "cookbooks"

  if ostype =~ /windows/
    if !File.exists?('c:/opscode/chef/embedded/bin/chef-client')
      start_time = Time.now.to_i
      ec = system("c:/programdata/chocolatey/choco.exe install -y --no-progress --allow-downgrade --allowEmptyChecksums chef-client -version 12.11.18")
      if !ec || ec.nil?
        puts "choco install result #{$?}"
        exit 1
      end
      duration = Time.now.to_i - start_time<commit_msg>Remove azure patch that no longer needed. (#307)<commit_after>#!/usr/bin/env ruby
#
# wrapper to chef or puppet - uses impl to get chef or puppet version and setup:
#  create Gemfile, bundle install if different
#
require 'rubygems'
require 'json'
require 'yaml'
require 'optparse'

log_level = "info"
formatter = "null"

options = {}
OptionParser.new do |opts|
  opts.banner = "Usage: exec-order.rb [options]"

  opts.on("-d", "--[no-]debug", "Run in debug") do |d|
    log_level = "debug"
    formatter = "doc"
  end
end.parse!

impl = ARGV[0]
json_context = ARGV[1]
cookbook_path = ARGV[2] || ''
service_cookbooks = ARGV[3] || ''

puts "RUBY_PLATFORM: #{RUBY_PLATFORM}" if log_level == "debug"
case RUBY_PLATFORM
when /mingw/
  ostype = 'windows'
when /linux/
  ostype = 'linux'
end

puts "os: #{ostype}" if log_level == "debug"

prefix_root = ''
file_cache_path = '/tmp'
ci = json_context.split("/").last.gsub(".json","")
if ostype =~ /windows/
  prefix_root = 'c:/cygwin64'
  impl = 'oo::chef-12.11.18'
  json_context = prefix_root + json_context
end

def gen_gemfile_and_install (gems, dsl, ostype, log_level)

    rubygems_proxy = ENV['rubygems_proxy']

    if rubygems_proxy.nil? && File.file?('/opt/oneops/rubygems_proxy')
      rubygems_proxy = File.read('/opt/oneops/rubygems_proxy').chomp
    end

    gemfile_content = "source 'https://rubygems.org'\n"
    if !rubygems_proxy.nil?
      gemfile_content = "source '#{rubygems_proxy}'\n"
    end
    gems.each do |gem_set|
      if gem_set.size > 1
        gemfile_content += "gem '#{gem_set[0]}', '#{gem_set[1]}'\n"
      else
        gemfile_content += "gem '#{gem_set[0]}'\n"
      end
    end

    current_dir = `pwd`.chomp
    puts "pwd: #{current_dir}"

    File.open('Gemfile', 'w') {|f| f.write(gemfile_content) }
    method = "install"
    result = ""
    if ostype =~ /windows/
      `c:\\opscode\\chef\\embedded\\bin\\gem list | grep #{dsl}`
    else
      `gem list | grep #{dsl}`
    end
    if $?.to_i == 0
      method = "update"
    end
    cmd = ""
    start_time = Time.now.to_i
    if ostype =~ /windows/
      cmd = "c:/opscode/chef/embedded/bin/bundle #{method}"
    else
      cmd = "bundle #{method} --full-index"
    end
    puts cmd  
    ec = system cmd
    
    if !ec || ec.nil?
      puts "bundle #{method} --full-index failed with, #{$?}"
      exit 1
    end
    duration = Time.now.to_i - start_time
    puts "took: #{duration} sec"

    puts "change gem source back to rubygems_proxy"
    rubygems_proxy = `cat /opt/oneops/rubygems_proxy`.chomp
    puts "rubygems_proxy: #{rubygems_proxy}" if log_level == "debug"
    if ostype =~ /windows/
      system("c:/opscode/chef/embedded/bin/gem source --add #{rubygems_proxy}")
      sources = `c:\\opscode\\chef\\embedded\\bin\\gem source | egrep -v "CURRENT SOURCES|#{rubygems_proxy}"`.split("\n")
      sources.each do |source|
        system("c:/opscode/chef/embedded/bin/gem source --remove #{source}")
      end
      system("c:/opscode/chef/embedded/bin/gem source")
    else
      `gem source --add #{rubygems_proxy}`
      sources = `gem source | egrep -v "CURRENT SOURCES|#{rubygems_proxy}"`.split("\n")
      sources.each do |source|
        `gem source --remove #{source}`
      end
      `gem source`
    end
end

# set cwd to same dir as the exe-order.rb file
Dir.chdir File.dirname(__FILE__)
gem_config = YAML::load(File.read('exec-gems.yaml'))

# ex) oo::chef-10.16.6::optional_uri_for_cookbook_or_module
dsl, version = impl.split("::")[1].split("-")

case dsl
when "chef"
  Dir.chdir "cookbooks"

  if ostype =~ /windows/
    if !File.exists?('c:/opscode/chef/embedded/bin/chef-client')
      start_time = Time.now.to_i
      ec = system("c:/programdata/chocolatey/choco.exe install -y --no-progress --allow-downgrade --allowEmptyChecksums chef-client -version 12.11.18")
      if !ec || ec.nil?
        puts "choco install result #{$?}"
        exit 1
      end
      duration = Time.now.to_i - start_time
{'fraction_non_alphanumeric': 0.15844284651624102, 'fraction_numerical': 0.010042152243987107, 'mean_word_length': 2.9563511525257478, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '5920961', 'n_tokens_mistral': 3095, 'n_tokens_neox': 2989, 'n_words': 676}