module Gauntlt::Support::PythonScriptHelper

Constants

DOWNLOAD_URLS

Public Instance Methods

ensure_python_script_installed(script_name, debug=false) click to toggle source
# File lib/gauntlt/attack_adapters/support/python_script_helper.rb, line 34
      def ensure_python_script_installed(script_name, debug=false)
        python_script_installed?(script_name) || begin
          shell_variable_name = '$' + shell_variable_name_for(script_name)

          msg = <<-EOS
    #{script_name}.py not installed or #{shell_variable_name} not set!

    1. Download #{script_name} from: #{DOWNLOAD_URLS[script_name]}
    2. In your .zshrc or .bash_profile (or whatever), set #{shell_variable_name}

       export #{shell_variable_name.gsub('$', '')}=/path/to/#{script_name}.py

    3. Make sure you have python installed:

       $ which python


EOS

          if debug
            msg += <<-EOS
            python installed : #{python_installed?}
            script_exists? : #{script_exists?(script_name)}
            shell_variable_name: #{shell_variable_name_for(script_name)}
            path:   #{path_to_python_script(script_name)}
            path_via_echo: #{`echo #{'$'+shell_variable_name_for(script_name)}`}
EOS
          end

          raise msg

        end
      end
path_to_python_script(script_name) click to toggle source
# File lib/gauntlt/attack_adapters/support/python_script_helper.rb, line 20
def path_to_python_script(script_name)
  shell_variable_name = shell_variable_name_for(script_name)
  ENV[shell_variable_name]
end
python_installed?() click to toggle source
# File lib/gauntlt/attack_adapters/support/python_script_helper.rb, line 12
def python_installed?
  cli_installed?('python')
end
python_script_installed?(script_name) click to toggle source
# File lib/gauntlt/attack_adapters/support/python_script_helper.rb, line 30
def python_script_installed?(script_name)
  python_installed? && script_exists?(script_name)
end
script_exists?(script_name) click to toggle source
# File lib/gauntlt/attack_adapters/support/python_script_helper.rb, line 25
def script_exists?(script_name)
  path = path_to_python_script(script_name)
  File.exists?(path) if path
end
shell_variable_name_for(script_name) click to toggle source
# File lib/gauntlt/attack_adapters/support/python_script_helper.rb, line 16
def shell_variable_name_for(script_name)
  script_name.upcase + '_PATH'
end