Class: AutomateIt::PackageManager::Portage

Inherits:
BaseDriver show all
Defined in:
lib/automateit/package_manager/portage.rb

Overview

PackageManager::Portage

The Portage driver for the PackageManager provides a way to manage software packages on Gentoo systems using.

Constant Summary

Constants inherited from AutomateIt::Plugin::Driver

AutomateIt::Plugin::Driver::BASE_DRIVER_NAME

Constants included from Constants

Constants::HELPERS_DIR, Constants::INSTALL_DIR, Constants::PERROR, Constants::PEXEC, Constants::PNOTE, Constants::WARNING_BOILERPLATE

Instance Attribute Summary

Attributes inherited from AutomateIt::Plugin::Driver

#manager

Attributes inherited from Common

#interpreter

Instance Method Summary collapse

Methods inherited from AutomateIt::Plugin::Driver

abstract_driver, #available?, base_driver, base_driver?, depends_on, inherited, manager_token, #setup

Methods inherited from AutomateIt::Plugin::Base

#setup, #token, token

Methods inherited from Common

#initialize, #log, #nitpick, #noop, #noop=, #noop?, #preview, #preview=, #preview?, #preview_for, #setup, #superuser?, #writing, #writing=, #writing?

Constructor Details

This class inherits a constructor from AutomateIt::Common

Instance Method Details

#install(*packages) ⇒ Object

See AutomateIt::PackageManager#install



48
49
50
51
52
53
54
55
56
# File 'lib/automateit/package_manager/portage.rb', line 48

def install(*packages)
  return _install_helper(*packages) do |list, opts|
    cmd = "emerge --color n --nospinner --tree --usepkg --quiet #{list.join(' ')} < /dev/null"
    cmd << " > /dev/null" if opts[:quiet]
    cmd << " 2>&1"

    interpreter.sh(cmd)
  end
end

#installed?(*packages) ⇒ Boolean

See AutomateIt::PackageManager#installed?

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/automateit/package_manager/portage.rb', line 13

def installed?(*packages)
  return _installed_helper?(*packages) do |list, opts|
    # Emerge throws an error when called with invalid packages, so it's
    # necessary to find the invalid packages and re-run the command without
    # them to find out what is actually installed.
    missing = []
    available = []
    while true
      cmd = "emerge --color n --nospinner --tree --usepkg --quiet --pretend " + \
        (list-missing).join(' ') + " < /dev/null 2>&1"
      log.debug(PEXEC+cmd)
      output = `#{cmd}`

      if output.match(/no ebuilds to satisfy "(.+)"/)
        invalid = $1
        log.debug(PNOTE+"PackageManager::Portage.installed? skipping invalid package '#{invalid}'")
        missing << invalid
        break if (list-missing).size.zero?
      else
        matches = output.scan(%r{^\[\w+\s+R\s*\] .+/(\w+?)-.+$}).flatten
        available = list & matches
        break
      end
    end

    available
  end
end

#not_installed?(*packages) ⇒ Boolean

See AutomateIt::PackageManager#not_installed?

Returns:

  • (Boolean)


43
44
45
# File 'lib/automateit/package_manager/portage.rb', line 43

def not_installed?(*packages)
  return _not_installed_helper?(*packages)
end

#suitability(method, *args) ⇒ Object

:nodoc:



8
9
10
# File 'lib/automateit/package_manager/portage.rb', line 8

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

#uninstall(*packages) ⇒ Object

See AutomateIt::PackageManager#uninstall



59
60
61
62
63
64
65
66
67
# File 'lib/automateit/package_manager/portage.rb', line 59

def uninstall(*packages)
  return _uninstall_helper(*packages) do |list, opts|
    cmd = "emerge --color n --nospinner --tree --unmerge --quiet #{list.join(' ')} < /dev/null"
    cmd << " > /dev/null" if opts[:quiet]
    cmd << " 2>&1"

    interpreter.sh(cmd)
  end
end