Class: AutomateIt::PackageManager::Egg

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

Overview

PackageManager::Egg

The Egg driver for the PackageManager provides a way to manage Python software packages with the PEAK easy_install tool.

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



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/automateit/package_manager/egg.rb', line 33

def install(*packages)
  return _install_helper(*packages) do |list, opts|
    # easy_install options:
    # -Z : install into a direcory rather than a file
    cmd = "easy_install -Z "+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)


14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/automateit/package_manager/egg.rb', line 14

def installed?(*packages)
  return _installed_helper?(*packages) do |list, opts|
    cmd = "python -c 'import sys; print(sys.path)' 2>&1"

    log.debug(PEXEC+cmd)
    data = `#{cmd}`
    # Extract array elements, turn them into basenames, and then split on
    # '-' because that's the separator for the name and version.
    found = data.scan(/'([^']+\.egg)'/).flatten.map{|t| File.basename(t).split('-', 2)[0]}
    available = found & list
  end
end

#not_installed?(*packages) ⇒ Boolean

See AutomateIt::PackageManager#not_installed?

Returns:

  • (Boolean)


28
29
30
# File 'lib/automateit/package_manager/egg.rb', line 28

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

#suitability(method, *args) ⇒ Object

:nodoc:



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

def suitability(method, *args) # :nodoc:
  # Never select as default driver
  return 0
end

#uninstall(*packages) ⇒ Object

See AutomateIt::PackageManager#uninstall



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/automateit/package_manager/egg.rb', line 46

def uninstall(*packages)
  return _uninstall_helper(*packages) do |list, opts|
    # easy_install options:
    # -m : removes package from the easy-install.pth
    cmd = "easy_install -m "+list.join(" ")+" < /dev/null"
    cmd << " > /dev/null" if opts[:quiet]
    cmd << " 2>&1"

    # Parse output for paths and remove the orphaned entries
    log.info(PEXEC+cmd)
    return packages if preview?
    data = `#{cmd}`
    paths = data.scan(/^Using ([^\n]+\.egg)$/m).flatten
    for path in paths
      interpreter.rm_rf(path)
    end
  end
end