Class: Babushka::PkgHelper
Direct Known Subclasses
AptHelper, BinPkgSrcHelper, BinPortsHelper, BrewHelper, GemHelper, NpmHelper, PacmanHelper, PipHelper, SrcHelper, UnknownPkgHelper, YumHelper, ZypperHelper
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, :binpkgsrc, :binports, :brew, :pacman, :yum, :zypper]
end
|
48
49
50
|
# File 'lib/babushka/pkg_helper.rb', line 48
def bin_path
prefix / 'bin'
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
'core: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
52
53
54
|
# File 'lib/babushka/pkg_helper.rb', line 52
def should_sudo?
!File.writable_real?(bin_path)
end
|
.update_pkg_lists(message = "Updating #{manager_key} package lists") ⇒ Object
70
71
72
|
# File 'lib/babushka/pkg_helper.rb', line 70
def update_pkg_lists message = "Updating #{manager_key} package lists"
log_shell message, pkg_update_command, :sudo => should_sudo?
end
|
.update_pkg_lists_if_required ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/babushka/pkg_helper.rb', line 56
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 "The #{manager_key} package lists are #{list_age.round.xsecs} old. Updating"
else
debug "The #{manager_key} package lists are #{list_age.round.xsecs} old (up to date)."
true end
end
end
|