Sha256: ac94f970e5c25fa3cecbce86678d25aeaa8e7616393210cd31a054c9d9310043

Contents?: true

Size: 1.18 KB

Versions: 13

Compression:

Stored size: 1.18 KB

Contents

module Context
  module CommandHelper
    def debug?
      ENV.key?('CONTEXTDEBUG') && ! ENV['CONTEXTDEBUG'].nil? && ENV['CONTEXTDEBUG']
    end

    def log(message)
      puts message
    end

    def debug_log(message)
      log message if debug?
    end

    def error_log(name, message)
      log "\n\n#{name} ERROR: #{message}\n\n"
    end

    def is_admin?
      Process::Sys.getuid != 0
    end

    def temp_dir
      @temp_dir = Dir.tmpdir() if @temp_dir.nil?
      @temp_dir
    end

    def get_data(command_line)
      debug_log "Get data from command #{command_line.join(' ')}"
      `#{command_line.join(' ')}`
    end

    def execute_command(command)
      command_status = system(command.join(' '))
      debug_log "executed command #{command.join(' ')}"
      command_status
    end

    def sudo_command(command)
      if ! Gem.win_platform? && Process::Sys.getuid != 0
        ['sudo'] + command
      else
        command
      end
    end

    def write_in_system_file(file, content)
      debug_log "write_in_system_file #{[file, content]}"
      system("touch #{file}")
      ::File.write(file, content)
      system("chmod 644 #{file}") unless Gem.win_platform?
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
deploy-context-2.2.0.3.gec16643.4.g20d2d42.4.g17e8559.12.g831d0a8.4.gbb2ab14.12.g0bc028d libraries/deploy-context/helpers/command.rb
deploy-context-2.2.0.3.gec16643.4.g20d2d42.4.g17e8559.12.g831d0a8.4.gbb2ab14.4.gb48499b libraries/deploy-context/helpers/command.rb
deploy-context-2.2.0.3.gec16643.4.g20d2d42.4.g17e8559.12.g831d0a8.4.gbb2ab14 libraries/deploy-context/helpers/command.rb
deploy-context-2.2.0.3.gec16643.4.g20d2d42.4.g17e8559.12.g831d0a8 libraries/deploy-context/helpers/command.rb
deploy-context-2.2.0.3.gec16643.4.g20d2d42.4.g17e8559.8.g299e50a libraries/deploy-context/helpers/command.rb
deploy-context-2.2.0.3.gec16643.4.g20d2d42.4.g17e8559 libraries/deploy-context/helpers/command.rb
deploy-context-2.2.0.3.gec16643.4.g20d2d42 libraries/deploy-context/helpers/command.rb
deploy-context-2.2.0.3.gec16643 libraries/deploy-context/helpers/command.rb
deploy-context-2.1.37.6.gec1e116.4.g6190201 libraries/deploy-context/helpers/command.rb
deploy-context-2.1.37.6.gec1e116 libraries/deploy-context/helpers/command.rb
deploy-context-2.1.35.3.g2abab85.16.g399fb24.9.g1523b69.8.ga24e5ef libraries/deploy-context/helpers/command.rb
deploy-context-2.1.35.3.g2abab85.16.g399fb24.9.g1523b69.3.g0fb07cc libraries/deploy-context/helpers/command.rb
deploy-context-2.1.35.3.g2abab85.16.g399fb24.9.g1523b69 libraries/deploy-context/helpers/command.rb