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

include_recipe 'irrigate-python'

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

    packages = %w(
      python36u
      python36u-libs
      python36u-devel
      python36u-pip
    )

    packages.each do |name|
      package name do
        action :remove
      end
    end

    packages = %w(
      python36
      python36-libs
      python36-devel
      python36-pip
    )

    packages.each do |name|
      package name
    end

    python_packages = %w(
      awscli
      pyyaml
    )

    pip36_version = node['python']['3.6']['pip_version']

    execute 'upgrade_pip' do
      command "/usr/bin/pip3.6 install -U pip==#{pip36_version} && " \
              "touch /var/cache/.pip36_#{pip36_version}"
      creates "/var/cache/.pip36_#{pip36_version}"
    end

    python_packages.each do |name|
      execute 'install_package' do
        command "/usr/bin/pip3.6 install #{name}"
        not_if "/usr/bin/pip3.6 list | grep -i #{name}"
      end
    end
  end
end
