Sha256: 68aff9e160adfda3f300c63a8696695c1545778534ab5a5d3d651838ef3b9b96

Contents?: true

Size: 1.98 KB

Versions: 2

Compression:

Stored size: 1.98 KB

Contents

require 'json'
require_relative 'app_config'
require_relative 'helper'
require_relative 'bundle'
require_relative 'linker'
require_relative 'pkgs'
require 'etc'

module Dply
  class Util

    include Helper

    def rake(task, args)
      cmd_arr = ["bundle", "exec", "rake", task, *args]
      cmd cmd_arr
    end

    def report_changes(previous_version, current_version)
      info = {}
      info[:current] = current_version
      info[:previous] = previous_version
      logger.remote "#{previous_version} => #{current_version}"
    end

    def install_pkgs(build_mode: false)
      return if not File.exists? "pkgs.yml"
      pkgs = Pkgs.new("pkgs.yml")
      return if pkgs.installed?(build_mode: build_mode)
      drake_install build_mode
    end

    def link(source, map)
      return if not map
      logger.bullet "symlinking #{source}"
      dest = Dir.pwd
      linker = Linker.new(source, dest, map: map)
      linker.create_symlinks
    end

    def run(task, render_config: false, optional: false)
      app_config = AppConfig.new
      logger.arrow task
      app_config.render_config if render_config
      app_config.run_task task, optional: optional
    end

    private

    def drake_install(build_mode)
      command = "#{drake_command} install-pkgs"
      command << " -b" if build_mode
      check_sudo_permission command
      cmd "sudo -n #{command}"
    end

    def drake_command
      @drake_command ||= (ENV["DRAKE_COMMAND"] || "/opt/ruby/bin/drake")
    end

    def check_sudo_permission(command)
      output = `sudo -n -l #{command}`
      if output.chomp.strip == command
        return true
      else
        msg = []
        user = Etc.getpwuid(Process.uid).name
        msg << %{unable to run "#{command}" with sudo permissions}
        msg << %{To resolve add the following line to sudoers: }
        msg << %{#{user} ALL=(ALL) NOPASSWD: /opt/ruby/bin/drake install-pkgs *, /opt/ruby/bin/drake install-pkgs}.yellow
        raise Error, msg.join("\n")
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dply-0.3.3 lib/dply/util.rb
dply-0.3.2 lib/dply/util.rb