#
# Cookbook:: irrigate-python
# Recipe:: python37
#
# Copyright:: (C) 2019 The Orchard
#
# All rights reserved - Do Not Redistribute
#

if platform_family?('rhel')
  if node['platform_version'].start_with?('7')

    packages = %w(
      bzip2-devel
      gcc
      libffi-devel
      make
      openssl-devel
      wget
    )

    packages.each do |name|
      package name
    end

    patch_version = node['python']['3.7']['patch_version']

    # Name of resource must match downloaded file name, thus start with capital letter.
    remote_install 'Python' do
      source "https://www.python.org/ftp/python/#{patch_version}/Python-#{patch_version}.tgz"
      version node['python']['3.7']['patch_version']
      checksum node['python']['3.7']['checksum']
      build_command './configure'
      compile_command 'make'
      install_command 'make altinstall'
      not_if { ::File.exist?('/usr/local/bin/python3.7') }
    end

    python_packages = %w(
      awscli
      pyyaml
    )

    python_packages.each do |name|
      execute "install_#{name}" do
        command "/usr/local/bin/pip3.7 install #{name}"
        not_if "/usr/local/bin/pip3.7 list | grep -iq #{name}"
      end
    end

  end

end
