<commit_before>#
# Cookbook Name:: galaxy
# Recipe:: default
#
# Copyright 2014, RIKEN ACCC
#
# All rights reserved - Do Not Redistribute
#
user "galaxy" do
    username node[:galaxy][:user]
    home     node[:galaxy][:home]
    shell    node[:galaxy][:shell]
    password node[:galaxy][:password]

    supports :manage_home => true
    action   :create
end
# set directory owner and permission mainly for shared file system
directory node[:galaxy][:home] do
    owner node[:galaxy][:user]
    group      node[:galaxy][:group]
    mode '0755'
end

include_recipe "python"

#include_recipe "mercurial"
#mercurial node[:galaxy][:path] do
#    repository node[:galaxy][:repository]
#    owner      node[:galaxy][:user]
#    group      node[:galaxy][:group]
#    reference  node[:galaxy][:reference]
#
#    action     :clone
#end

# galaxy main directory
directory node[:galaxy][:path] do
    owner node[:galaxy][:user]
    group      node[:galaxy][:group]
    mode '0755'
end

# galaxy for sed tools directory
directory node[:galaxy][:shedtools_path] do
    owner node[:galaxy][:user]
    group      node[:galaxy][:group]
    mode '0755'

    action   :create
end

include_recipe "python"

# virtualenv related variables
virtualenv_home  = node[:galaxy][:path]+"/.venv"
user_name        = node[:galaxy][:user]

# install
python_pip "virtualenv" do
    action :install
end
python_virtualenv virtualenv_home do
  action :create
  owner node[:galaxy][:user]
  group node[:galaxy][:group]
end

python_pip "drmaa" do
  action :install
  user node[:galaxy][:user]
  group node[:galaxy][:group]
  virtualenv virtualenv_home
end

#
sourcecodefile=node[:galaxy][:reference]+".tar.bz2"
remote_file node[:galaxy][:home]+"/"+sourcecodefile do
    source "https://bitbucket.org/galaxy/galaxy-dist/get/"+sourcecodefile
    action :create_if_missing
end

bash "extract file" do
    code   "tar jxvf #{node[:galaxy][:home]}/#{sourcecodefile} -C #{node[:galaxy][:path]} --strip=1"
    action :run
    user node[:galaxy][:user]
    group node[:galaxy][:group]
end

# backend database
galaxy_config_file = node[:galaxy][:config]
database_setting = node[:galaxy][:db][:databaseusername]+":"+node[:galaxy][:db][:databasepassword]+"@"+node[:galaxy][:db][:hostname]+"/"+node[:galaxy][:db][:databasename]
database_connection = ""
case node[:galaxy][:db][:type]
  when 'sqlite'
    include_recipe 'galaxy::sqlite'
  when 'mysql'
    include_recipe 'galaxy::mysql'
    database_connection = "mysql://"+database_setting
  when 'postgresql'
    include_recipe 'galaxy::postgresql'
    database_connection = "postgresql://"+database_setting
end
# create
bash "build galaxy config" do
  code   "cd #{node[:galaxy][:path]} ; python ./scripts/check_python.py ; ./scripts/common_startup.sh"
  action :run
  user node[:galaxy][:user]
  group node[:galaxy][:group]
  not_if { ::File.exist?(galaxy_config_file) }
end
# database connection setting update
case node[:galaxy][:db][:type]
  when 'mysql', 'postgresql'
    database_connection_line = /^database_connection/
    ruby_block "insert database_connection line" do<commit_msg>bug fix: create config full path<commit_after>#
# Cookbook Name:: galaxy
# Recipe:: default
#
# Copyright 2014, <NAME>
#
# All rights reserved - Do Not Redistribute
#
user "galaxy" do
    username node[:galaxy][:user]
    home     node[:galaxy][:home]
    shell    node[:galaxy][:shell]
    password node[:galaxy][:password]

    supports :manage_home => true
    action   :create
end
# set directory owner and permission mainly for shared file system
directory node[:galaxy][:home] do
    owner node[:galaxy][:user]
    group      node[:galaxy][:group]
    mode '0755'
end

include_recipe "python"

#include_recipe "mercurial"
#mercurial node[:galaxy][:path] do
#    repository node[:galaxy][:repository]
#    owner      node[:galaxy][:user]
#    group      node[:galaxy][:group]
#    reference  node[:galaxy][:reference]
#
#    action     :clone
#end

# galaxy main directory
directory node[:galaxy][:path] do
    owner node[:galaxy][:user]
    group      node[:galaxy][:group]
    mode '0755'
end

# galaxy for sed tools directory
directory node[:galaxy][:shedtools_path] do
    owner node[:galaxy][:user]
    group      node[:galaxy][:group]
    mode '0755'

    action   :create
end

include_recipe "python"

# virtualenv related variables
virtualenv_home  = node[:galaxy][:path]+"/.venv"
user_name        = node[:galaxy][:user]

# install
python_pip "virtualenv" do
    action :install
end
python_virtualenv virtualenv_home do
  action :create
  owner node[:galaxy][:user]
  group node[:galaxy][:group]
end

python_pip "drmaa" do
  action :install
  user node[:galaxy][:user]
  group node[:galaxy][:group]
  virtualenv virtualenv_home
end

#
sourcecodefile=node[:galaxy][:reference]+".tar.bz2"
remote_file node[:galaxy][:home]+"/"+sourcecodefile do
    source "https://bitbucket.org/galaxy/galaxy-dist/get/"+sourcecodefile
    action :create_if_missing
end

bash "extract file" do
    code   "tar jxvf #{node[:galaxy][:home]}/#{sourcecodefile} -C #{node[:galaxy][:path]} --strip=1"
    action :run
    user node[:galaxy][:user]
    group node[:galaxy][:group]
end

# backend database
galaxy_config_file = node[:galaxy][:path]+"/"+node[:galaxy][:config]
database_setting = node[:galaxy][:db][:databaseusername]+":"+node[:galaxy][:db][:databasepassword]+"@"+node[:galaxy][:db][:hostname]+"/"+node[:galaxy][:db][:databasename]
database_connection = ""
case node[:galaxy][:db][:type]
  when 'sqlite'
    include_recipe 'galaxy::sqlite'
  when 'mysql'
    include_recipe 'galaxy::mysql'
    database_connection = "mysql://"+database_setting
  when 'postgresql'
    include_recipe 'galaxy::postgresql'
    database_connection = "postgresql://"+database_setting
end
# create
bash "build galaxy config" do
  code   "cd #{node[:galaxy][:path]} ; python ./scripts/check_python.py ; ./scripts/common_startup.sh"
  action :run
  user node[:galaxy][:user]
  group node[:galaxy][:group]
  not_if { ::File.exist?(galaxy_config_file) }
end
# database connection setting update
case node[:galaxy][:db][:type]
  when 'mysql', 'postgresql'
    database_connection_line = /^database_connection/
    ruby_block "insert database_connection line" do
{'fraction_non_alphanumeric': 0.14974293059125965, 'fraction_numerical': 0.005784061696658098, 'mean_word_length': 4.817757009345795, 'pattern_counts': {'":': 2, '<': 4, '<?xml version=': 0, '>': 6, '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': '465280', 'n_tokens_mistral': 2127, 'n_tokens_neox': 2101, 'n_words': 461}