Sha256: 1174f00833b370b819be6b601a20de23013701f521213eda0f7aefd54cf035aa

Contents?: true

Size: 1.91 KB

Versions: 21

Compression:

Stored size: 1.91 KB

Contents

# == PackageManager::APT
#
# The APT driver for the PackageManager provides a way to manage software
# packages on Debian-style systems using <tt>apt-get</tt> and <tt>dpkg</tt>.
class AutomateIt::PackageManager::APT < AutomateIt::PackageManager::BaseDriver
  depends_on :programs => %w(apt-get dpkg)

  def suitability(method, *args) # :nodoc:
    return available? ? 1 : 0
  end

  # See AutomateIt::PackageManager#installed?
  def installed?(*packages)
    return _installed_helper?(*packages) do |list, opts|
      ### data = `dpkg --status nomarch apache2 not_a_real_package 2>&1`
      cmd = "dpkg --status "+list.join(" ")+" 2>&1"

      log.debug(PEXEC+cmd)
      data = `#{cmd}`
      matches = data.scan(/^Package: (.+)$\s*^Status: (.+)$/)
      available = matches.inject([]) do |sum, match|
        package, status = match
        sum << package if status.match(/(?:^|\s)installed\b/)
        sum
      end

      available
    end
  end

  # See AutomateIt::PackageManager#not_installed?
  def not_installed?(*packages)
    return _not_installed_helper?(*packages)
  end

  # See AutomateIt::PackageManager#install
  def install(*packages)
    return _install_helper(*packages) do |list, opts|
      # apt-get options:
      # -y : yes to all queries
      # -q : no interactive progress bars
      cmd = "export DEBIAN_FRONTEND=noninteractive; apt-get install -y -q "+list.join(" ")+" < /dev/null"
      cmd << " > /dev/null" if opts[:quiet]
      cmd << " 2>&1"

      interpreter.sh(cmd)
    end
  end

  # See AutomateIt::PackageManager#uninstall
  def uninstall(*packages)
    return _uninstall_helper(*packages) do |list, opts|
      # apt-get options:
      # -y : yes to all queries
      # -q : no interactive progress bars
      cmd = "export DEBIAN_FRONTEND=noninteractive; apt-get remove -y -q "+list.join(" ")+" < /dev/null"
      cmd << " > /dev/null" if opts[:quiet]
      cmd << " 2>&1"

      interpreter.sh(cmd)
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
automateit-0.70930 lib/automateit/package_manager/apt.rb
automateit-0.71003 lib/automateit/package_manager/apt.rb
automateit-0.70928 lib/automateit/package_manager/apt.rb
automateit-0.70923 lib/automateit/package_manager/apt.rb
automateit-0.71031.2 lib/automateit/package_manager/apt.rb
automateit-0.71006 lib/automateit/package_manager/apt.rb
automateit-0.71017 lib/automateit/package_manager/apt.rb
automateit-0.71012 lib/automateit/package_manager/apt.rb
automateit-0.71021 lib/automateit/package_manager/apt.rb
automateit-0.71031.1 lib/automateit/package_manager/apt.rb
automateit-0.71030 lib/automateit/package_manager/apt.rb
automateit-0.71102 lib/automateit/package_manager/apt.rb
automateit-0.71031 lib/automateit/package_manager/apt.rb
automateit-0.71101 lib/automateit/package_manager/apt.rb
automateit-0.71101.1 lib/automateit/package_manager/apt.rb
automateit-0.71101.2 lib/automateit/package_manager/apt.rb
automateit-0.71103 lib/automateit/package_manager/apt.rb
automateit-0.71219 lib/automateit/package_manager/apt.rb
automateit-0.71112 lib/automateit/package_manager/apt.rb
automateit-0.71111 lib/automateit/package_manager/apt.rb