<commit_before>include_recipe "pgd::packages"
include_recipe "yum"
include_recipe "nginx"
include_recipe "python"
include_recipe "python::pip"
include_recipe "git"

user node['pgd']['user'] do
  home "/home/pgd"
  shell "/bin/bash"
end

# Check directory for cloning
directory node['pgd']['path'] do
  owner node['pgd']['owner']
  group node['pgd']['group']
  recursive true
  action :create
end

# clone the repo 
git node['pgd']['path'] do
  repository node['pgd']['repository']
  user node['pgd']['owner']
  group node['pgd']['group']
end

python_virtualenv node['pgd']['virtualenv'] do
  owner node['pgd']['owner']
  group node['pgd']['group']
  action :create
end

python_pip node['pgd']['requirements.txt'] do
  options "-r"
  virtualenv node['pgd']['virtualenv']
  action :install
end

settings = Chef::EncryptedDataBagItem.load("pgd", "settings")

database_engine = node['pgd']['database']['engine'] || settings['database_engine']
database_name = node['pgd']['database']['name'] || settings['database_name']
database_user = node['pgd']['database']['user'] || settings['database_user']
database_password = node['pgd']['database']['password'] || settings['database_password']
database_host = node['pgd']['database']['host'] || settings['database_host']
database_port = node['pgd']['database']['port'] || settings['database_port']

secret_key = node['pgd']['secret_key'] || settings['secret_key']
google_id = node['pgd']['google_id'] || settings['google_id']

config_file = ::File.join(node['pgd']['config_dir'], 'settings.py')
template config_file do
  source "settings.py.erb"
  owner node['pgd']['user']
  group node['pgd']['group']
  mode "0644"
  variables({
    :database_engine => database_engine,
    :database_name => database_name,
    :database_user => database_user,
    :database_password => <PASSWORD>,
    :database_host => database_host,
    :database_port => database_port,
    :secret_key =>  secret_key,
    :google_id => google_id
  })
end

django_admin = ::File.join(node['pgd']['virtualenv'], '/bin/django-admin.py')
django_version = nil # `#{django_admin} --version`

if django_version.chomp == "1.3.7"
  python_pip 'django-registration' do
    virtualenv node['pgd']['virtualenv']
    action :remove
  end<commit_msg>forcing django version<commit_after>include_recipe "pgd::packages"
include_recipe "yum"
include_recipe "nginx"
include_recipe "python"
include_recipe "python::pip"
include_recipe "git"

user node['pgd']['user'] do
  home "/home/pgd"
  shell "/bin/bash"
end

# Check directory for cloning
directory node['pgd']['path'] do
  owner node['pgd']['owner']
  group node['pgd']['group']
  recursive true
  action :create
end

# clone the repo 
git node['pgd']['path'] do
  repository node['pgd']['repository']
  user node['pgd']['owner']
  group node['pgd']['group']
end

python_virtualenv node['pgd']['virtualenv'] do
  owner node['pgd']['owner']
  group node['pgd']['group']
  action :create
end

python_pip node['pgd']['requirements.txt'] do
  options "-r"
  virtualenv node['pgd']['virtualenv']
  action :install
end

settings = Chef::EncryptedDataBagItem.load("pgd", "settings")

database_engine = node['pgd']['database']['engine'] || settings['database_engine']
database_name = node['pgd']['database']['name'] || settings['database_name']
database_user = node['pgd']['database']['user'] || settings['database_user']
database_password = node['pgd']['database']['password'] || settings['database_password']
database_host = node['pgd']['database']['host'] || settings['database_host']
database_port = node['pgd']['database']['port'] || settings['database_port']

secret_key = node['pgd']['secret_key'] || settings['secret_key']
google_id = node['pgd']['google_id'] || settings['google_id']

config_file = ::File.join(node['pgd']['config_dir'], 'settings.py')
template config_file do
  source "settings.py.erb"
  owner node['pgd']['user']
  group node['pgd']['group']
  mode "0644"
  variables({
    :database_engine => database_engine,
    :database_name => database_name,
    :database_user => database_user,
    :database_password => <PASSWORD>,
    :database_host => database_host,
    :database_port => database_port,
    :secret_key =>  secret_key,
    :google_id => google_id
  })
end

django_admin = ::File.join(node['pgd']['virtualenv'], '/bin/django-admin.py')
django_version = '1.3.7' # `#{django_admin} --version`

if django_version.chomp == '1.3.7'
  python_pip 'django-registration' do
    virtualenv node['pgd']['virtualenv']
    action :remove
  end
{'fraction_non_alphanumeric': 0.18779134295227526, 'fraction_numerical': 0.0037735849056603774, 'mean_word_length': 6.472636815920398, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '722335', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1452, 'n_words': 293}