rubycut-babushka 0.10.8 → 0.15.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. data/Gemfile +1 -0
  2. data/Gemfile.lock +17 -15
  3. data/README.markdown +163 -41
  4. data/Rakefile +1 -1
  5. data/bin/babushka +1 -1
  6. data/deps/apt.rb +44 -0
  7. data/deps/babushka.rb +54 -42
  8. data/deps/deprecated.rb +16 -0
  9. data/deps/dev.rb +28 -3
  10. data/deps/git.rb +27 -12
  11. data/deps/homebrew.rb +2 -2
  12. data/deps/packages.rb +14 -15
  13. data/deps/pkg_managers.rb +21 -75
  14. data/deps/ruby.rb +5 -19
  15. data/deps/rubygems.rb +3 -3
  16. data/deps/system.rb +2 -2
  17. data/deps/templates/app.rb +60 -41
  18. data/deps/templates/bin.rb +16 -0
  19. data/deps/templates/installer.rb +9 -9
  20. data/deps/templates/lib.rb +17 -0
  21. data/deps/templates/managed.rb +1 -38
  22. data/deps/templates/src.rb +16 -8
  23. data/deps/templates/task.rb +11 -0
  24. data/deps/templates/tmbundle.rb +16 -2
  25. data/lib/babushka.rb +2 -3
  26. data/lib/babushka/accepts_block_for.rb +5 -3
  27. data/lib/babushka/asset.rb +172 -0
  28. data/lib/babushka/base.rb +37 -8
  29. data/lib/babushka/bug_reporter.rb +6 -6
  30. data/lib/babushka/cmdline.rb +11 -10
  31. data/lib/babushka/cmdline/handler.rb +7 -3
  32. data/lib/babushka/cmdline/helpers.rb +15 -23
  33. data/lib/babushka/cmdline/parser.rb +1 -1
  34. data/lib/babushka/core_patches/object.rb +1 -1
  35. data/lib/babushka/core_patches/string.rb +8 -3
  36. data/lib/babushka/current_ruby.rb +44 -0
  37. data/lib/babushka/dep.rb +111 -185
  38. data/lib/babushka/dep_context.rb +8 -3
  39. data/lib/babushka/dep_definer.rb +45 -15
  40. data/lib/babushka/dep_pool.rb +5 -8
  41. data/lib/babushka/{meta_dep.rb → dep_template.rb} +21 -2
  42. data/lib/babushka/dsl.rb +3 -0
  43. data/lib/babushka/git_repo.rb +143 -49
  44. data/lib/babushka/helpers/git_helpers.rb +7 -6
  45. data/lib/babushka/helpers/log_helpers.rb +51 -13
  46. data/lib/babushka/helpers/path_helpers.rb +5 -7
  47. data/lib/babushka/helpers/run_helpers.rb +15 -55
  48. data/lib/babushka/helpers/shell_helpers.rb +18 -26
  49. data/lib/babushka/helpers/uri_helpers.rb +9 -18
  50. data/lib/babushka/lambda_chooser.rb +20 -13
  51. data/lib/babushka/parameter.rb +20 -4
  52. data/lib/babushka/path_checker.rb +72 -0
  53. data/lib/babushka/pkg_helper.rb +38 -13
  54. data/lib/babushka/pkg_helpers/apt_helper.rb +15 -8
  55. data/lib/babushka/pkg_helpers/binpkgsrc_helper.rb +15 -14
  56. data/lib/babushka/pkg_helpers/binports_helper.rb +7 -7
  57. data/lib/babushka/pkg_helpers/brew_helper.rb +17 -25
  58. data/lib/babushka/pkg_helpers/gem_helper.rb +36 -27
  59. data/lib/babushka/pkg_helpers/npm_helper.rb +9 -9
  60. data/lib/babushka/pkg_helpers/pacman_helper.rb +5 -4
  61. data/lib/babushka/pkg_helpers/pip_helper.rb +14 -10
  62. data/lib/babushka/pkg_helpers/unknown_pkg_helper.rb +19 -0
  63. data/lib/babushka/pkg_helpers/yum_helper.rb +1 -1
  64. data/lib/babushka/popen.rb +13 -10
  65. data/lib/babushka/prompt.rb +14 -1
  66. data/lib/babushka/renderable.rb +11 -9
  67. data/lib/babushka/resource.rb +5 -166
  68. data/lib/babushka/run_reporter.rb +12 -3
  69. data/lib/babushka/shell.rb +54 -44
  70. data/lib/babushka/source.rb +41 -20
  71. data/lib/babushka/source_pool.rb +20 -13
  72. data/lib/babushka/system_definitions.rb +11 -3
  73. data/lib/babushka/system_detector.rb +31 -0
  74. data/lib/babushka/system_matcher.rb +53 -0
  75. data/lib/babushka/system_profile.rb +67 -89
  76. data/lib/babushka/task.rb +36 -8
  77. data/lib/babushka/{meta_dep_context.rb → templated_dep_context.rb} +1 -1
  78. data/lib/babushka/vars.rb +46 -4
  79. data/lib/babushka/version_of.rb +35 -17
  80. data/lib/babushka/version_str.rb +12 -8
  81. data/lib/components.rb +9 -8
  82. data/lib/fancypath/fancypath.rb +109 -83
  83. data/lib/inkan/inkan.rb +14 -14
  84. data/lib/{babushka → levenshtein}/levenshtein.rb +0 -0
  85. data/spec/acceptance/acceptance.rb +4 -4
  86. data/spec/acceptance_helper.rb +10 -6
  87. data/spec/babushka/accepts_for_spec.rb +137 -142
  88. data/spec/babushka/accepts_for_support.rb +13 -6
  89. data/spec/babushka/asset_spec.rb +165 -0
  90. data/spec/babushka/cmdline/help_spec.rb +11 -9
  91. data/spec/babushka/cmdline/meet_spec.rb +15 -0
  92. data/spec/babushka/cmdline/version_spec.rb +1 -1
  93. data/spec/babushka/core_patches_spec.rb +9 -0
  94. data/spec/babushka/current_ruby_spec.rb +73 -0
  95. data/spec/babushka/dep_context_spec.rb +27 -13
  96. data/spec/babushka/dep_definer_spec.rb +108 -16
  97. data/spec/babushka/dep_spec.rb +87 -104
  98. data/spec/babushka/dep_template_spec.rb +176 -0
  99. data/spec/babushka/deps_spec.rb +48 -19
  100. data/spec/babushka/gem_helper_spec.rb +46 -59
  101. data/spec/babushka/git_repo_spec.rb +242 -51
  102. data/spec/babushka/ip_spec.rb +11 -11
  103. data/spec/babushka/lambda_chooser_spec.rb +47 -9
  104. data/spec/babushka/parameter_spec.rb +21 -0
  105. data/spec/babushka/path_checker_spec.rb +35 -0
  106. data/spec/babushka/path_helpers_spec.rb +51 -50
  107. data/spec/babushka/prompt_spec.rb +4 -4
  108. data/spec/babushka/renderable_spec.rb +61 -28
  109. data/spec/babushka/shell_helpers_spec.rb +110 -85
  110. data/spec/babushka/shell_spec.rb +15 -0
  111. data/spec/babushka/source_pool_spec.rb +204 -210
  112. data/spec/babushka/source_spec.rb +125 -42
  113. data/spec/babushka/source_support.rb +1 -1
  114. data/spec/babushka/system_profile_spec.rb +86 -49
  115. data/spec/babushka/task_spec.rb +80 -13
  116. data/spec/babushka/vars_spec.rb +2 -1
  117. data/spec/babushka/version_of_spec.rb +29 -2
  118. data/spec/babushka/version_str_spec.rb +91 -65
  119. data/spec/babushka/xml_string_spec.rb +1 -1
  120. data/spec/deps/bad/broken.rb +2 -2
  121. data/spec/deps/bad/working.rb +0 -1
  122. data/spec/deps/good/{meta.rb → template.rb} +0 -0
  123. data/spec/deps/good/test.rb +0 -3
  124. data/spec/deps/outer/deps.rb +0 -2
  125. data/spec/fancypath/fancypath_spec.rb +30 -0
  126. data/spec/inkan/inkan_spec.rb +34 -32
  127. data/spec/spec_helper.rb +7 -50
  128. data/spec/system_detector_spec.rb +70 -0
  129. metadata +163 -177
  130. data/deps/os_x.rb +0 -33
  131. data/deps/templates/ppa.rb +0 -24
  132. data/lib/babushka/core_patches/io.rb +0 -8
  133. data/lib/babushka/dep_runner.rb +0 -85
  134. data/lib/babushka/helpers/suggest_helpers.rb +0 -16
  135. data/lib/babushka/pkg_helpers/base_helper.rb +0 -19
  136. data/lib/babushka/pkg_helpers/macports_helper.rb +0 -22
  137. data/spec/babushka/dep_definer_support.rb +0 -36
  138. data/spec/babushka/meta_dep_definer_spec.rb +0 -127
  139. data/spec/babushka/meta_dep_wrapper_spec.rb +0 -32
  140. data/spec/babushka/resource_spec.rb +0 -141
  141. data/spec/babushka/run_helpers_spec.rb +0 -26
  142. data/spec/babushka/source_pool_support.rb +0 -31
@@ -2,13 +2,7 @@ module Babushka
2
2
  module UriHelpers
3
3
 
4
4
  def setup_source_uris
5
- parse_uris
6
- requires_when_unmet(@uris.map(&:scheme).uniq & %w[ git ])
7
- end
8
-
9
- def parse_uris
10
- @uris = source.map(&uri_processor(:escape)).map(&uri_processor(:parse))
11
- @extra_uris = extra_source.map(&uri_processor(:escape)).map(&uri_processor(:parse)) if respond_to?(:extra_source)
5
+ deprecated! '2013-04-21', :method_name => "#setup_source_uris isn't required anymore and now has no effect, and so"
12
6
  end
13
7
 
14
8
  def uri_processor(method_name)
@@ -16,20 +10,17 @@ module Babushka
16
10
  end
17
11
 
18
12
  def process_sources &block
19
- @extra_uris.each {|uri| handle_source uri } unless @extra_uris.nil?
20
- @uris.all? {|uri| handle_source uri, &block } unless @uris.nil?
13
+ deprecated! '2013-04-21', :instead => 'sources.each {|uri| Resource.extract(uri) { ... } }'
14
+ uris = source.map(&uri_processor(:escape)).map(&uri_processor(:parse))
15
+ extra_uris = extra_source.map(&uri_processor(:escape)).map(&uri_processor(:parse)) if respond_to?(:extra_source)
16
+
17
+ extra_uris.each {|uri| Resource.extract(uri) } unless extra_uris.nil?
18
+ uris.all? {|uri| Resource.extract(uri, &block) } unless uris.nil?
21
19
  end
22
20
 
23
21
  def handle_source uri, &block
24
- uri = uri_processor(:parse).call(uri) unless uri.is_a?(URI)
25
- case uri.scheme
26
- when 'git'
27
- git uri, &block
28
- when 'http', 'https', 'ftp', nil # We let `curl` work out the protocol if it's nil.
29
- Resource.extract uri, &block
30
- else
31
- log_error "Babushka can't handle #{uri.scheme}:// URLs yet. But it can if you write a patch! :)"
32
- end
22
+ deprecated! '2013-04-21', :instead => 'Resource.extract(uri) { ... }'
23
+ Resource.extract uri, &block
33
24
  end
34
25
 
35
26
  end
@@ -1,5 +1,8 @@
1
1
  module Babushka
2
2
  class LambdaChooser
3
+ DEPRECATED_CHOICES = {
4
+ :macports => ['2012-12-13', :brew]
5
+ }
3
6
 
4
7
  attr_reader :owner
5
8
 
@@ -14,26 +17,30 @@ module Babushka
14
17
  end
15
18
 
16
19
  def choose choices, method_name = nil
17
- self.class.send :alias_method, (method_name || :on), :process_choice
20
+ self.metaclass.send :alias_method, method_name, :on unless method_name.nil?
18
21
  block_result = instance_eval(&@block)
19
- @results.empty? ? block_result : [*choices].push(:otherwise).pick {|c| @results[c] }
22
+ @results.empty? ? block_result : [choices].flatten(1).push(:otherwise).pick {|c| @results[c] }
20
23
  end
21
24
 
22
25
  def otherwise first = nil, *rest, &block
23
- process_choice :otherwise, first, *rest, &block
26
+ on :otherwise, first, *rest, &block
24
27
  end
25
28
 
26
- def process_choice choice, first = nil, *rest, &block
29
+ def on choices, first = nil, *rest, &block
27
30
  raise "You can supply values or a block, but not both." if first && block
28
- raise "The choice '#{choice}' isn't valid." unless @possible_choices.include?(choice)
29
-
30
- @results[choice] = if block
31
- block
32
- elsif first.is_a? Hash
33
- first
34
- else
35
- [*first].concat(rest)
36
- end
31
+
32
+ [choices].flatten(1).each {|choice|
33
+ raise "The choice '#{choice}' isn't valid." unless @possible_choices.include?(choice)
34
+ LogHelpers.log_warn "The #{choice.inspect} choice has been deprecated and will be removed on #{DEPRECATED_CHOICES[choice].first}. Use #{DEPRECATED_CHOICES[choice].last.inspect} instead." if DEPRECATED_CHOICES.keys.include?(choice)
35
+
36
+ @results[choice] = if block
37
+ block
38
+ elsif first.is_a? Hash
39
+ first
40
+ else
41
+ [first].flatten(1).concat(rest)
42
+ end
43
+ }
37
44
  end
38
45
 
39
46
  end
@@ -102,6 +102,10 @@ module Babushka
102
102
  value.to_s
103
103
  end
104
104
 
105
+ def to_a
106
+ value.to_a
107
+ end
108
+
105
109
  def to_str
106
110
  if !value.respond_to?(:to_str)
107
111
  raise TypeError, "Can't coerce #{value}:#{value.class.name} into a String"
@@ -110,17 +114,21 @@ module Babushka
110
114
  end
111
115
  end
112
116
 
117
+ def current_value
118
+ @value
119
+ end
120
+
113
121
  def inspect
114
122
  "#<Babushka::Parameter:#{object_id} #{description}>"
115
123
  end
116
124
 
117
125
  def description
118
126
  if @value
119
- "#{name}: #{@value.inspect}"
127
+ "#{name}: #{inspect_truncated(@value)}"
120
128
  elsif @default_bang
121
- "#{name}: [default!: #{@default_bang.inspect}]"
129
+ "#{name}: [default!: #{inspect_truncated(@default_bang)}]"
122
130
  elsif @default
123
- "#{name}: [default: #{@default.inspect}]"
131
+ "#{name}: [default: #{inspect_truncated(@default)}]"
124
132
  else
125
133
  "#{name}: [unset]"
126
134
  end
@@ -129,7 +137,15 @@ module Babushka
129
137
  private
130
138
 
131
139
  def value
132
- @value ||= @default_bang || Prompt.get_value((@ask || name).to_s, prompt_opts)
140
+ @value || @default_bang || prompted_value
141
+ end
142
+
143
+ def prompted_value
144
+ @prompted_value ||= Prompt.get_value((@ask || name).to_s, prompt_opts)
145
+ end
146
+
147
+ def inspect_truncated value
148
+ value.inspect.sub(/^(.{50})(.{3}).*/m, '\1...')
133
149
  end
134
150
 
135
151
  def prompt_opts
@@ -0,0 +1,72 @@
1
+ module Babushka
2
+ class PathChecker
3
+ extend ShellHelpers
4
+
5
+ def self.in_path? provided_list
6
+ commands = [provided_list].flatten(1).versions
7
+
8
+ cmds_in_path?(commands) and matching_versions?(commands) {|cmd|
9
+ shell("#{cmd.name} --version 2>&1")
10
+ }
11
+ end
12
+
13
+ private
14
+
15
+ def self.cmds_in_path? commands
16
+ dir_hash = [*commands].group_by {|cmd| cmd_dir(cmd.name) }
17
+
18
+ if dir_hash.keys.compact.length > 1
19
+ log_error "These commands run from more than one place."
20
+ log_error dir_hash.values.map {|cmds|
21
+ cmd_location_str_for cmds
22
+ }.to_list(:oxford => true, :conj => 'but').end_with('.')
23
+ unmeetable! unless Prompt.confirm("Multiple installations might indicate a problem. Meet anyway?", :default => 'n')
24
+ else
25
+ dir_hash[nil].blank?.tap {|result|
26
+ if result
27
+ cmds = dir_hash.values.first
28
+ log cmd_location_str_for(cmds).end_with('.') unless cmds.blank?
29
+ else
30
+ log "#{dir_hash[nil].map {|i| "'#{i}'" }.to_list} #{dir_hash[nil].length == 1 ? 'is' : 'are'} missing."
31
+ end
32
+ }
33
+ end
34
+ end
35
+
36
+ def self.matching_versions? commands
37
+ versions = commands.select {|cmd|
38
+ !cmd.version.nil?
39
+ }.inject({}) {|hsh,cmd|
40
+ potential_versions = match_potential_versions(yield(cmd), cmd.version)
41
+ if potential_versions.empty?
42
+ # No potential versions to check against.
43
+ else
44
+ hsh[cmd] = potential_versions.detect {|piece| cmd.matches?(piece) }
45
+ if hsh[cmd] == cmd.version
46
+ log_ok "#{cmd.name} is #{cmd.version}."
47
+ else
48
+ log "#{cmd.name} is #{hsh[cmd] || potential_versions.first}, which is#{"n't" unless hsh[cmd]} #{cmd.version}.", :as => (:ok if hsh[cmd])
49
+ end
50
+ end
51
+ hsh
52
+ }
53
+ versions.values.all?
54
+ end
55
+
56
+ def self.match_potential_versions str, example = ''
57
+ (str || '').split(/[^\w\.\-]+/).map {|piece|
58
+ begin
59
+ piece.to_version
60
+ rescue VersionStrError
61
+ nil
62
+ end
63
+ }.compact.reject {|piece|
64
+ piece.to_s['.'].nil? if example.to_s['.']
65
+ }
66
+ end
67
+
68
+ def self.cmd_location_str_for cmds
69
+ "#{cmds.map {|i| "'#{i.name}'" }.to_list(:conj => '&')} run#{'s' if cmds.length == 1} from #{cmd_dir(cmds.first.name)}"
70
+ end
71
+ end
72
+ end
@@ -3,42 +3,52 @@ module Babushka
3
3
  class << self
4
4
  include LogHelpers
5
5
  include ShellHelpers
6
- include VersionOf::Helpers
7
6
 
8
7
  def pkg_binary; pkg_cmd end
9
8
 
9
+ def manager_dep
10
+ 'package manager'.with(pkg_binary)
11
+ end
12
+
10
13
  def all_manager_keys
11
- [:apt, :brew, :macports, :yum, :binpkgsrc, :binports]
14
+ [:apt, :pacman, :brew, :macports, :yum, :binpkgsrc, :binports]
12
15
  end
13
16
 
14
- def manager_dep
15
- manager_key.to_s
17
+ def present?
18
+ which pkg_binary
16
19
  end
17
20
 
18
21
  def has? pkg, opts = {}
19
- pkg = VersionOf(pkg)
20
- _has?(pkg).tap {|matching_version|
21
- matching_pkg = VersionOf(pkg.name, (matching_version if matching_version.is_a?(VersionStr)))
22
+ pkg = Babushka.VersionOf(pkg)
23
+ has_pkg?(pkg).tap {|matching_version|
24
+ matching_pkg = Babushka.VersionOf(pkg.name, (matching_version if matching_version.is_a?(VersionStr)))
22
25
  unless opts[:log] == false
23
26
  log "system #{matching_version ? "has" : "doesn't have"} #{matching_pkg} #{pkg_type}", :as => (:ok if matching_version)
24
27
  end
25
28
  }
26
29
  end
30
+
27
31
  def install! pkgs, opts = nil
28
- _install! [*pkgs].map {|pkg| VersionOf(pkg) }, opts
32
+ install_pkgs! [*pkgs].map {|pkg| Babushka.VersionOf(pkg) }, opts
29
33
  end
30
- def _install! pkgs, opts
31
- log_shell "Installing #{pkgs.to_list} via #{manager_key}", "#{pkg_cmd} -y install #{pkgs.join(' ')} #{opts}", :sudo => should_sudo?
34
+
35
+ def handle_install! pkgs, opts = nil
36
+ if [*pkgs].empty?
37
+ log "Nothing to install on #{manager_key}-based systems."
38
+ else
39
+ update_pkg_lists_if_required
40
+ install! pkgs, opts
41
+ end
32
42
  end
43
+
33
44
  def prefix
34
45
  cmd_dir(pkg_binary).p.dir
35
46
  end
47
+
36
48
  def bin_path
37
49
  prefix / 'bin'
38
50
  end
39
- def present?
40
- which pkg_binary
41
- end
51
+
42
52
  def cmd_in_path? cmd_name
43
53
  if (_cmd_dir = cmd_dir(cmd_name)).nil?
44
54
  log_error "The '#{cmd_name}' command is not available. You probably need to add #{bin_path} to your PATH."
@@ -46,6 +56,7 @@ module Babushka
46
56
  _cmd_dir.starts_with?(prefix)
47
57
  end
48
58
  end
59
+
49
60
  def should_sudo?
50
61
  !File.writable?(bin_path)
51
62
  end
@@ -63,12 +74,25 @@ module Babushka
63
74
  end
64
75
  end
65
76
  end
77
+
66
78
  def update_pkg_lists message = "Updating #{manager_dep.capitalize} package lists"
67
79
  log_shell message, pkg_update_command, :sudo => should_sudo?
68
80
  end
81
+
82
+ private
83
+
84
+ def has_pkg? pkg_name
85
+ raise RuntimeError, "#{self.class.name}#has_pkg? is unimplemeneted."
86
+ end
87
+
88
+ def install_pkgs! pkgs, opts
89
+ log_shell "Installing #{pkgs.to_list} via #{manager_key}", "#{pkg_cmd} -y install #{pkgs.join(' ')} #{opts}", :sudo => should_sudo?
90
+ end
91
+
69
92
  def pkg_update_timeout
70
93
  nil # not required by default
71
94
  end
95
+
72
96
  def pkg_update_command
73
97
  "#{pkg_cmd} update"
74
98
  end
@@ -76,6 +100,7 @@ module Babushka
76
100
  def cmdline_spec_for pkg
77
101
  "#{pkg.name}#{" --version '#{pkg.version}'" unless pkg.version.nil?}"
78
102
  end
103
+
79
104
  end
80
105
  end
81
106
  end
@@ -3,15 +3,14 @@ module Babushka
3
3
  class << self
4
4
  def pkg_type; :deb end
5
5
  def pkg_cmd; "env DEBCONF_TERSE='yes' DEBIAN_PRIORITY='critical' DEBIAN_FRONTEND='noninteractive' #{pkg_binary}" end
6
+ def manager_key; :apt end
7
+
6
8
  def pkg_binary
7
9
  @_cached_pkg_binary ||= which('aptitude') ? 'aptitude' : 'apt-get'
8
10
  end
9
- def manager_key; :apt end
10
11
 
11
- def _install! pkgs, opts
12
- wait_for_dpkg
13
- log_shell "Downloading", "#{pkg_cmd} -y -d install #{pkgs.join(' ')}", :sudo => should_sudo?
14
- super
12
+ def manager_dep
13
+ 'apt'
15
14
  end
16
15
 
17
16
  def update_pkg_lists_if_required
@@ -25,21 +24,29 @@ module Babushka
25
24
 
26
25
  def source_for_system
27
26
  {
28
- :debian => 'http://archive.debian.org/debian',
27
+ :debian => 'http://ftp.debian.org/debian',
29
28
  :ubuntu => 'http://archive.ubuntu.com/ubuntu'
30
- }[Base.host.flavour]
29
+ }[Babushka.host.flavour]
31
30
  end
32
31
 
33
32
  private
34
- def _has? pkg_name
33
+
34
+ def has_pkg? pkg
35
+ pkg_name = pkg.name.sub(/\=.*$/, '') # Strip versions like git=1.7.11
35
36
  wait_for_dpkg
36
37
  status = raw_shell("dpkg -s #{pkg_name}").stdout.val_for('Status')
37
38
  status && status.split(' ').include?('installed')
38
39
  end
39
40
 
41
+ def install_pkgs! pkgs, opts
42
+ wait_for_dpkg
43
+ super
44
+ end
45
+
40
46
  def pkg_update_timeout
41
47
  3600 * 24 # 1 day
42
48
  end
49
+
43
50
  def pkg_list_dir
44
51
  '/var/lib/apt/lists'.p
45
52
  end
@@ -1,10 +1,6 @@
1
1
  module Babushka
2
2
  class BinPkgSrcHelper < PkgHelper
3
3
  class << self
4
- def existing_packages
5
- shell("pkg_info -a").lines.to_a.map {|i| i.split(/\s+/)[0] }
6
- end
7
-
8
4
  # Note that with pkg_radd it is possible to override the default
9
5
  # repository using PKG_PATH environment variable. See man 1 pkg_add.
10
6
 
@@ -13,6 +9,7 @@ module Babushka
13
9
  def pkg_type; :pkg end
14
10
  def manager_key; :binpkgsrc end
15
11
 
12
+ # TODO can this be removed?
16
13
  def update_pkg_lists_if_required
17
14
  if !File.exists? pkg_list_dir
18
15
  update_pkg_lists "Looks like pkg summary hasn't been fetched on this system yet. Updating"
@@ -21,6 +18,20 @@ module Babushka
21
18
  end
22
19
  end
23
20
 
21
+ private
22
+
23
+ def has_pkg? pkg
24
+ existing_packages.any? {|i| i.match(/#{pkg}/)}
25
+ end
26
+
27
+ def install_pkgs! pkgs, opts
28
+ log_shell "Installing #{pkgs.join(', ')}", "pkg_radd #{pkgs.join(' ')}", :sudo => should_sudo?
29
+ end
30
+
31
+ def existing_packages
32
+ shell("pkg_info -a").lines.to_a.map {|i| i.split(/\s+/)[0] }
33
+ end
34
+
24
35
  def pkg_update_timeout
25
36
  3600 * 24 * 14 # 2 weeks
26
37
  end
@@ -33,16 +44,6 @@ module Babushka
33
44
  "pkg_search -d"
34
45
  end
35
46
 
36
- def _install! pkgs, opts
37
- log_shell "Installing #{pkgs.join(', ')}", "pkg_radd #{pkgs.join(' ')}", :sudo => should_sudo?
38
- end
39
-
40
- private
41
-
42
- def _has? pkg
43
- existing_packages.any? {|i| i.match(/#{pkg}/)}
44
- end
45
-
46
47
  end
47
48
  end
48
49
  end
@@ -1,10 +1,6 @@
1
1
  module Babushka
2
2
  class BinPortsHelper < PkgHelper
3
3
  class << self
4
- def existing_packages
5
- shell("pkg_info").lines.to_a.map {|i| i.split(/\s+/)[0] }
6
- end
7
-
8
4
  # Regarding FreeBSD binary packages the following should be noted:
9
5
  # pkg_add uses PACKAGESITE and PACKAGEROOT environment variables
10
6
  # to calculate the URL to download packages from.
@@ -21,12 +17,16 @@ module Babushka
21
17
 
22
18
  private
23
19
 
24
- def _install! pkgs, opts
20
+ def has_pkg? pkg
21
+ existing_packages.any? {|i| i.match(/#{pkg}/)}
22
+ end
23
+
24
+ def install_pkgs! pkgs, opts
25
25
  log_shell "Installing #{pkgs.join(', ')}", "#{pkg_cmd} #{pkgs.join(' ')}", :sudo => should_sudo?
26
26
  end
27
27
 
28
- def _has? pkg
29
- existing_packages.any? {|i| i.match(/#{pkg}/)}
28
+ def existing_packages
29
+ shell("pkg_info").lines.to_a.map {|i| i.split(/\s+/)[0] }
30
30
  end
31
31
 
32
32
  end