<commit_before># Multistage
require 'capistrano/ext/multistage'
# Load bundler-capistrano gem
require "bundler/capistrano"
# Load rvm-capistrano gem
require "rvm/capistrano"
# Include New Relic recipes
require 'new_relic/recipes'

set :ssh_options, {:forward_agent => true}
set :app_title, "getit"
set :application, "#{app_title}_repos"

# RVM  vars
set :rvm_ruby_string, "1.9.3-p448"
set :rvm_type, :user

# Bundle vars
set :bundle_without, [:development, :test]

# Git vars
set :repository, "<EMAIL>@github.com:NYULibraries/getit.git" 
set :scm, :git
set :deploy_via, :remote_cache
set(:branch, 'development') unless exists?(:branch)
set :git_enable_submodules, 1

# Environments
set :stages, ["staging", "qa", "production"]
set :default_stage, "staging"
set :keep_releases, 5
set :use_sudo, false

# Configure app_settings from rails_config
# Defer processing until we have rails environment
set(:app_settings) { eval(run_locally("rails runner -e #{rails_env} 'p Settings.capistrano.to_hash'")) }
set(:scm_username) { app_settings[:scm_username] }
set(:app_path) { app_settings[:path] }
set(:user) { app_settings[:user] }
set(:deploy_to) {"#{app_path}#{application}"}

# Rake variables
set :rake, "#{rake} --trace"

namespace :rails_config do
  desc "Set RailsConfig servers"
  task :set_servers do
    server "#{app_settings[:servers].first}", :app, :web, :db, :primary => true
    app_settings[:servers].slice(1, app_settings[:servers].length-1).each do |host|
      server "#{host}", :app, :web
    end
  end

  namespace :newrelic do
    desc "Write New Relic file without ERB for processing by New Relic rpm recipe"
    task :set do
      run_locally "bundle exec rake nyu:newrelic:set RAILS_ENV=#{rails_env}"
    end

    desc "Reset the New Relic file"
    task :reset do
      run_locally "bundle exec rake nyu:newrelic:reset RAILS_ENV=#{rails_env}"
    end
  end

  desc "See RailsConfig settings"
  task :see do
    p "Settings: #{app_settings}"
    p "Servers: #{find_servers}"
    p "SCM Username: #{scm_username}"
    p "App Path: #{app_path}"
    p "User: #{user}"
    p "Deploy To: #{deploy_to}"
  end
end

# Rails specific vars
# set :normalize_asset_timestamps, false

# Rake variables
# set :rake, "#{rake} --trace"

namespace :deploy do
  desc "Start Application"
  task :start, :roles => :app do
    run "touch #{current_path}/tmp/restart.txt"
  end
  desc "Restart Application"
  task :restart, :roles => :app do
    run "touch #{current_path}/tmp/restart.txt"
  end
  task :stop, :roles => :app do
    # Do nothing.
  end
  task :passenger_symlink do
    run "rm -rf /apps/#{app_title} && ln -s #{current_path}/public /apps/#{app_title}"
  end
end

namespace :cache do
  desc "Clear rails cache"
  task :tmp_clear, :roles => :app do
    run "cd #{current_release} && rake tmp:clear RAILS_ENV=#{rails_env}"
  end
end

namespace :exlibris do
  namespace :aleph do
    desc "Refresh Aleph tables"
    task :refresh, :roles => :app do
      run "cd #{current_release} && RAILS_ENV=#{rails_env} bundle exec rake exlibris:aleph:refresh"
    end
  end
end

# Set the servers from rails config before we see
# what's in the rails config environment
before "rails_config:see", "rails_config:set_servers"
# After multistage is set, load up the rails config environment
after "multistage:ensure", "rails_config:see"
# After your bundle has installed, do any migrations
after "bundle:install", "deploy:migrate"
after "deploy", "deploy:cleanup", "deploy:passenger_symlink", "cache:tmp_clear"
# Before newrelic runs, set up its yaml file
before "newrelic:notice_deployment", "rails_config:newrelic:set"
# After newrelic runs, reset up its yaml file
after "newrelic:notice_deployment", "rails_config:newrelic:reset"
after "deploy:update", "newrelic:notice_deployment"<commit_msg>Update deploy script to work with latest capistrano version :scream:<commit_after># Multistage
require 'capistrano/ext/multistage'
# Load bundler-capistrano gem
require "bundler/capistrano"
# Load rvm-capistrano gem
require "rvm/capistrano"
# Include New Relic recipes
require 'new_relic/recipes'

set :ssh_options, {:forward_agent => true}
set :app_title, "getit"
set :application, "#{app_title}_repos"

# RVM  vars
set :rvm_ruby_string, "1.9.3-p448"
set :rvm_type, :user

# Bundle vars
set :bundle_without, [:development, :test]

# Git vars
set :repository, "<EMAIL>:NYULibraries/getit.git" 
set :scm, :git
set :deploy_via, :remote_cache
set(:branch, 'development') unless exists?(:branch)
set :git_enable_submodules, 1

# Environments
set :stages, ["staging", "qa", "production"]
set :default_stage, "staging"
set :keep_releases, 5
set :use_sudo, false

# Rake variables
# set :rake, "#{rake} --trace"

namespace :rails_config do
  desc "Set stage variables"
  task :set_variables do
    # Configure app_settings from rails_config
    # Defer processing until we have rails environment
    set(:app_settings) { eval(run_locally("rails runner -e #{rails_env} 'p Settings.capistrano.to_hash'")) }
    set(:scm_username) { app_settings[:scm_username] }
    set(:app_path) { app_settings[:path] }
    set(:user) { app_settings[:user] }
    set(:deploy_to) {"#{app_path}#{application}"}
  end

  desc "Set RailsConfig servers"
  task :set_servers do
    server "#{app_settings[:servers].first}", :app, :web, :db, :primary => true
    app_settings[:servers].slice(1, app_settings[:servers].length-1).each do |host|
      server "#{host}", :app, :web
    end
  end

  namespace :newrelic do
    desc "Write New Relic file without ERB for processing by New Relic rpm recipe"
    task :set do
      run_locally "bundle exec rake nyu:newrelic:set RAILS_ENV=#{rails_env}"
    end

    desc "Reset the New Relic file"
    task :reset do
      run_locally "bundle exec rake nyu:newrelic:reset RAILS_ENV=#{rails_env}"
    end
  end

  desc "See RailsConfig settings"
  task :see do
    p "Settings: #{app_settings}"
    p "Servers: #{find_servers}"
    p "SCM Username: #{scm_username}"
    p "App Path: #{app_path}"
    p "User: #{user}"
    p "Deploy To: #{deploy_to}"
  end
end

# Rails specific vars
# set :normalize_asset_timestamps, false

# Rake variables
# set :rake, "#{rake} --trace"

namespace :deploy do
  desc "Start Application"
  task :start, :roles => :app do
    run "touch #{current_path}/tmp/restart.txt"
  end
  desc "Restart Application"
  task :restart, :roles => :app do
    run "touch #{current_path}/tmp/restart.txt"
  end
  task :stop, :roles => :app do
    # Do nothing.
  end
  task :passenger_symlink do
    run "rm -rf /apps/#{app_title} && ln -s #{current_path}/public /apps/#{app_title}"
  end
end

namespace :cache do
  desc "Clear rails cache"
  task :tmp_clear, :roles => :app do
    run "cd #{current_release} && rake tmp:clear RAILS_ENV=#{rails_env}"
  end
end

namespace :exlibris do
  namespace :aleph do
    desc "Refresh Aleph tables"
    task :refresh, :roles => :app do
      run "cd #{current_release} && RAILS_ENV=#{rails_env} bundle exec rake exlibris:aleph:refresh"
    end
  end
end

# Set the servers from rails config before we see
# what's in the rails config environment
before "rails_config:set_servers", "rails_config:set_variables"
before "rails_config:see", "rails_config:set_servers"
# After multistage is set, load up the rails config environment
after "multistage:ensure", "rails_config:see"
# After your bundle has installed, do any migrations
after "bundle:install", "deploy:migrate"
after "deploy", "deploy:cleanup", "deploy:passenger_symlink", "cache:tmp_clear"
# Before newrelic runs, set up its yaml file
before "newrelic:notice_deployment", "rails_config:newrelic:set"
# After newrelic runs, reset up its yaml file
after "newrelic:notice_deployment", "rails_config:newrelic:reset"
after "deploy:update", "newrelic:notice_deployment"
{'fraction_non_alphanumeric': 0.12409979423868313, 'fraction_numerical': 0.00257201646090535, 'mean_word_length': 4.773570898292502, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '2434777', 'n_tokens_mistral': 2764, 'n_tokens_neox': 2674, 'n_words': 795}