Class: Babushka::PkgHelper
Direct Known Subclasses
AptHelper, BinPkgSrcHelper, BinPortsHelper, BrewHelper, GemHelper, NpmHelper, PacmanHelper, PipHelper, SrcHelper, UnknownPkgHelper, YumHelper
Class Method Summary
collapse
cmd_dir, current_username, log_shell, login_shell, raw_shell, shell, shell!, shell?, shell_cmd, sudo, which
Methods included from LogHelpers
debug, deprecated!, log, log_block, log_error, log_ok, log_stderr, log_warn, removed!
Class Method Details
.all_manager_keys ⇒ Object
13
14
15
|
# File 'lib/babushka/pkg_helper.rb', line 13
def all_manager_keys
[:apt, :pacman, :brew, :macports, :yum, :binpkgsrc, :binports]
end
|
48
49
50
|
# File 'lib/babushka/pkg_helper.rb', line 48
def bin_path
prefix / 'bin'
end
|
.cmd_in_path?(cmd_name) ⇒ Boolean
52
53
54
55
56
57
58
|
# File 'lib/babushka/pkg_helper.rb', line 52
def cmd_in_path? cmd_name
if (_cmd_dir = cmd_dir(cmd_name)).nil?
log_error "The '#{cmd_name}' command is not available. You probably need to add #{bin_path} to your PATH."
else
_cmd_dir.starts_with?(prefix)
end
end
|
.handle_install!(pkgs, opts = nil) ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/babushka/pkg_helper.rb', line 35
def handle_install! pkgs, opts = nil
if [*pkgs].empty?
log "Nothing to install on #{manager_key}-based systems."
else
update_pkg_lists_if_required
install! pkgs, opts
end
end
|
.has?(pkg, opts = {}) ⇒ Boolean
21
22
23
24
25
26
27
28
29
|
# File 'lib/babushka/pkg_helper.rb', line 21
def has? pkg, opts = {}
pkg = Babushka.VersionOf(pkg)
has_pkg?(pkg).tap {|matching_version|
matching_pkg = Babushka.VersionOf(pkg.name, (matching_version if matching_version.is_a?(VersionStr)))
unless opts[:log] == false
log "system #{matching_version ? "has" : "doesn't have"} #{matching_pkg} #{pkg_type}", :as => (:ok if matching_version)
end
}
end
|
.install!(pkgs, opts = nil) ⇒ Object
31
32
33
|
# File 'lib/babushka/pkg_helper.rb', line 31
def install! pkgs, opts = nil
install_pkgs! [*pkgs].map {|pkg| Babushka.VersionOf(pkg) }, opts
end
|
.manager_dep ⇒ Object
9
10
11
|
# File 'lib/babushka/pkg_helper.rb', line 9
def manager_dep
'package manager'.with(pkg_binary)
end
|
.pkg_binary ⇒ Object
7
|
# File 'lib/babushka/pkg_helper.rb', line 7
def pkg_binary; pkg_cmd end
|
44
45
46
|
# File 'lib/babushka/pkg_helper.rb', line 44
def prefix
cmd_dir(pkg_binary).p.dir
end
|
.present? ⇒ Boolean
17
18
19
|
# File 'lib/babushka/pkg_helper.rb', line 17
def present?
which pkg_binary
end
|
.should_sudo? ⇒ Boolean
60
61
62
|
# File 'lib/babushka/pkg_helper.rb', line 60
def should_sudo?
!File.writable?(bin_path)
end
|
.update_pkg_lists(message = "Updating #{manager_dep.capitalize} package lists") ⇒ Object
78
79
80
|
# File 'lib/babushka/pkg_helper.rb', line 78
def update_pkg_lists message = "Updating #{manager_dep.capitalize} package lists"
log_shell message, pkg_update_command, :sudo => should_sudo?
end
|
.update_pkg_lists_if_required ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/babushka/pkg_helper.rb', line 64
def update_pkg_lists_if_required
if pkg_update_timeout.nil?
true else
list_age = Time.now - pkg_list_dir.mtime
if list_age > pkg_update_timeout
update_pkg_lists "#{manager_dep.capitalize} package lists are #{list_age.round.xsecs} old. Updating"
else
debug "#{manager_dep.capitalize} package lists are #{list_age.round.xsecs} old (up to date)."
true end
end
end
|