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
@@ -0,0 +1,16 @@
1
+ {
2
+ 'curl.managed' => 'curl.bin',
3
+ 'gettext.managed' => 'gettext.lib',
4
+ 'git.managed' => 'git.bin',
5
+ 'pip.managed' => 'pip.bin',
6
+ 'ruby.managed' => 'ruby',
7
+ 'sudo.managed' => 'sudo.bin',
8
+ 'sudo' => 'sudo.bin'
9
+ }.each_pair {|old_name, new_name|
10
+
11
+ dep old_name do
12
+ deprecated! "2012-11-14", :method_name => "'#{name}'", :callpoint => false, :instead => "the '#{new_name}' dep"
13
+ requires new_name
14
+ end
15
+
16
+ }
data/deps/dev.rb CHANGED
@@ -1,12 +1,37 @@
1
1
  dep 'build tools' do
2
2
  requires {
3
3
  on :osx, 'xcode commandline tools'
4
- on :snow_leopard, 'llvm in path'
5
- on :yum, dep('gcc'), dep('gcc-c++'), dep('autoconf.managed'), dep('automake.managed'), dep('libtool.managed')
6
- on :linux, 'build-essential', dep('autoconf.managed'), dep('automake.managed'), dep('libtool.managed')
4
+ on :yum, dep('gcc'), dep('gcc-c++'), dep('autoconf.bin'), dep('automake.bin'), dep('libtool.bin')
5
+ on :linux, 'build-essential', dep('autoconf.bin'), dep('automake.bin'), dep('libtool.bin')
7
6
  }
8
7
  end
9
8
 
10
9
  dep 'build-essential', :template => 'managed' do
11
10
  provides 'gcc', 'g++', 'make', 'ld'
12
11
  end
12
+
13
+ dep 'xcode tools', :template => 'external' do
14
+ expects 'gcc', 'g++', 'autoconf', 'make', 'ld'
15
+ otherwise {
16
+ log "Install Xcode, and then run Babushka again."
17
+ log "Official download at http://developer.apple.com/technology/xcode.html"
18
+ confirm "Open in browser now" do
19
+ shell "open http://developer.apple.com/technology/xcode.html"
20
+ end
21
+ }
22
+ end
23
+
24
+ dep 'xcode commandline tools', :template => 'external' do
25
+ # See http://kennethreitz.com/xcode-gcc-and-homebrew.html
26
+ expects %w[cc gcc c++ g++ llvm-gcc llvm-g++ clang] # compilers
27
+ expects %w[ld libtool] # linkety link
28
+ expects %w[make] # configure and build tools
29
+ expects %w[cpp m4 nasm yacc bison] # misc - the preprocessor, assembler, grammar stuff
30
+ otherwise {
31
+ log "Install Command Line Tools for Xcode, and then run Babushka again."
32
+ log "Official pacakge at http://developer.apple.com/downloads"
33
+ confirm "Open in browser now" do
34
+ shell "open http://developer.apple.com/downloads"
35
+ end
36
+ }
37
+ end
data/deps/git.rb CHANGED
@@ -1,29 +1,44 @@
1
- dep 'git' do
2
- requires {
1
+ dep 'git', :version do
2
+ # Accept a rather old git by default, so the installation process
3
+ # doesn't unnecessarily upgrade it.
4
+ version.default!('1.6')
5
+
6
+ requires_when_unmet {
3
7
  # Use the binary installer on OS X, so installing babushka
4
8
  # (which pulls in git) doesn't require a compiler.
5
- on :osx, 'git.installer'
6
- otherwise 'git.managed'
9
+ on :osx, 'git.installer'.with(owner.version)
10
+ # git-1.5 can't clone https:// repos properly. Let's build
11
+ # our own rather than monkeying with unstable debs.
12
+ on :lenny, 'git.src'.with(owner.version)
13
+ otherwise 'git.bin'.with(owner.version)
7
14
  }
8
- met? { in_path? 'git >= 1.5' }
15
+ met? { in_path? "git >= #{version}" }
9
16
  end
10
17
 
11
- dep 'git.managed' do
18
+ dep 'git.bin', :version do
19
+ # Accept any packaged git that's new enough to have proper https:// support.
20
+ version.default!('1.6')
12
21
  installs {
13
- via :macports, 'git-core +svn +bash_completion'
14
22
  via :apt, 'git-core'
15
23
  via :binpkgsrc, 'scmgit'
16
24
  otherwise 'git'
17
25
  }
26
+ provides "git >= #{version}"
18
27
  end
19
28
 
20
29
  dep 'git.installer', :version do
21
- version.default!('1.7.7')
22
- source "http://git-osx-installer.googlecode.com/files/git-#{version}-intel-universal-snow-leopard.dmg"
30
+ version.default!('1.8.0')
31
+ requires 'layout.fhs'.with('/usr/local')
32
+ source "https://git-osx-installer.googlecode.com/files/git-#{version}-intel-universal-snow-leopard.dmg"
23
33
  provides "git >= #{version}"
24
34
  after {
25
- cd '/usr/local/bin', :create => true, :sudo => true do
26
- sudo "ln -sf /usr/local/git/bin/git* ."
27
- end
35
+ sudo "ln -sf /usr/local/git/bin/git* /usr/local/bin"
28
36
  }
29
37
  end
38
+
39
+ dep 'git.src', :version do
40
+ version.default!('1.8.0')
41
+ requires 'gettext.lib'
42
+ source "http://git-core.googlecode.com/files/git-#{version}.tar.gz"
43
+ provides "git >= #{version}"
44
+ end
data/deps/homebrew.rb CHANGED
@@ -9,7 +9,7 @@ end
9
9
 
10
10
  dep 'binary.homebrew' do
11
11
  requires 'repo.homebrew'
12
- met? { which 'brew' }
12
+ met? { in_path? 'brew' }
13
13
  meet { log_shell "Resetting to HEAD", "git reset --hard", :cd => path }
14
14
  end
15
15
 
@@ -17,7 +17,7 @@ dep 'repo.homebrew' do
17
17
  requires_when_unmet 'writable.fhs'.with(path), 'git'
18
18
  met? {
19
19
  if repo.exists? && !repo.include?('29d85578e75170a6c0eaebda4d701b46f1acf446')
20
- unmeetable "There is a non-homebrew repo at #{path}."
20
+ unmeetable! "There is a non-homebrew repo at #{path}."
21
21
  else
22
22
  repo.exists?
23
23
  end
data/deps/packages.rb CHANGED
@@ -1,22 +1,21 @@
1
- dep 'curl.managed' do
2
- installs {
3
- via :apt, 'curl', 'libcurl4-openssl-dev'
4
- via :yum, 'curl'
5
- }
6
- end
1
+ dep 'curl.bin'
7
2
 
8
- dep 'sudo' do
9
- requires {
10
- on :osx, 'sudo.external'
11
- otherwise 'sudo.managed'
3
+ dep 'gettext.lib'
4
+
5
+ dep 'nodejs.src', :version do
6
+ deprecated! "2013-03-10", :method_name => "'#{name}'", :callpoint => false, :instead => "the 'nodejs.bin' dep"
7
+ requires 'nodejs.bin'
8
+ met? {
9
+ in_path? 'node >= 0.6.12'
12
10
  }
13
11
  end
14
12
 
15
- dep 'sudo.external' do
16
- expects 'sudo'
17
- otherwise {
18
- log_error "Your system seems to be missing sudo."
13
+ dep 'nodejs.bin' do
14
+ installs {
15
+ via :apt, 'nodejs', 'nodejs-dev'
16
+ otherwise 'node'
19
17
  }
18
+ provides 'node >= 0.6.12'
20
19
  end
21
20
 
22
- dep 'sudo.managed'
21
+ dep 'sudo.bin'
data/deps/pkg_managers.rb CHANGED
@@ -1,90 +1,50 @@
1
- dep 'macports.src' do
2
- requires 'build tools'
3
- provides 'port'
4
- prefix '/opt/local'
5
- source "http://distfiles.macports.org/MacPorts/MacPorts-1.8.0.tar.gz"
6
- after { log_shell "Running port selfupdate", "port selfupdate", :sudo => true }
7
- end
8
-
9
- dep 'apt', :template => 'external' do
10
- requires {
11
- on :ubuntu, 'main.apt_source', 'universe.apt_source'
12
- on :debian, 'main.apt_source'
13
- }
14
- expects 'apt-get'
15
- otherwise {
16
- log "Your system doesn't seem to have Apt installed. Is it Debian-based?"
17
- }
18
- end
19
-
20
- dep 'pacman', :template => 'external' do
21
- expects 'pacman'
22
- otherwise {
23
- log "You seem to be running Arch Linux, but are missing the Pacman package manager. Something is very, very wrong here."
24
- }
25
- end
26
-
27
- meta :apt_source do
28
- accepts_list_for :source_name
29
- template {
30
- met? {
31
- source_name.all? {|name|
32
- grep(/^deb .* #{Babushka::Base.host.name} (\w+ )*#{Regexp.escape(name.to_s)}/, '/etc/apt/sources.list')
33
- }
1
+ dep 'package manager', :cmd do
2
+ met? {
3
+ in_path?(cmd).tap {|result|
4
+ unmeetable! "The package manager's binary, #{cmd}, isn't in the $PATH." unless result
34
5
  }
35
- before {
36
- # Don't edit sources.list unless we know how to edit it for this debian flavour and version.
37
- Babushka::AptHelper.source_for_system and Babushka::Base.host.name
38
- }
39
- meet {
40
- source_name.each {|name|
41
- append_to_file "deb #{Babushka::AptHelper.source_for_system} #{Babushka::Base.host.name} #{name}", '/etc/apt/sources.list', :sudo => true
42
- }
43
- }
44
- after { Babushka::AptHelper.update_pkg_lists }
45
6
  }
46
7
  end
47
8
 
48
- dep 'main.apt_source' do
49
- source_name 'main'
50
- end
51
-
52
- dep 'universe.apt_source' do
53
- source_name 'universe'
9
+ dep 'apt' do
10
+ requires 'package manager'.with('apt-get')
11
+ requires {
12
+ on :ubuntu, 'apt source'.with(:repo => 'main'), 'apt source'.with(:repo => 'universe')
13
+ on :debian, 'apt source'.with(:repo => 'main')
14
+ }
54
15
  end
55
16
 
56
17
  dep 'homebrew' do
57
18
  requires 'binary.homebrew', 'build tools'
58
19
  end
59
20
 
60
- dep 'yum', :template => 'external' do
61
- expects 'yum'
62
- otherwise {
63
- log "Your system doesn't seem to have Yum installed. Is it Redhat-based?"
21
+ dep 'npm' do
22
+ requires {
23
+ on :osx, 'npm.src'
24
+ otherwise 'npm.bin'
64
25
  }
65
26
  end
66
27
 
67
- dep 'npm' do
68
- requires 'nodejs.src'
28
+ dep 'npm.src' do
29
+ requires 'nodejs.bin'
69
30
  met? { which 'npm' }
70
31
  meet {
71
- log_shell "Installing npm", "curl http://npmjs.org/install.sh | #{'sudo' unless which('node').p.writable?} sh"
32
+ log_shell "Installing npm", "curl https://npmjs.org/install.sh | #{'sudo' unless which('node').p.writable?} sh"
72
33
  }
73
34
  end
74
35
 
75
- dep 'nodejs.src' do
76
- source 'https://github.com/joyent/node.git'
77
- provides 'node >= 0.4', 'node-waf'
36
+ dep 'npm.bin' do
37
+ provides 'npm >= 1.1'
78
38
  end
79
39
 
80
40
  dep 'pip' do
81
41
  requires {
82
42
  on :osx, 'pip.src'
83
- otherwise 'pip.managed'
43
+ otherwise 'pip.bin'
84
44
  }
85
45
  end
86
46
 
87
- dep 'pip.managed' do
47
+ dep 'pip.bin' do
88
48
  installs 'python-pip'
89
49
  end
90
50
 
@@ -94,17 +54,3 @@ dep 'pip.src' do
94
54
  log_shell "Installing pip", "python setup.py install", :sudo => !which('python').p.writable?
95
55
  }
96
56
  end
97
-
98
- dep 'binpkgsrc', :template => 'external' do
99
- expects 'pkg_radd'
100
- otherwise {
101
- log "You seem to be running DragonflyBSD or NETBSD, but are missing the pkgsrc package manager. Something is very, very wrong here."
102
- }
103
- end
104
-
105
- dep 'binports', :template => 'external' do
106
- expects 'pkg_add'
107
- otherwise {
108
- log "You seem to be running FreeBSD, but are missing the ports package manager. Something is very, very wrong here."
109
- }
110
- end
data/deps/ruby.rb CHANGED
@@ -1,23 +1,9 @@
1
- dep 'ruby' do
2
- met? {
3
- in_path? ['ruby >= 1.8.6', 'irb']
4
- }
5
- requires_when_unmet {
6
- on :osx, 'ruby.external'
7
- otherwise 'ruby.managed'
8
- }
9
- end
10
-
11
- dep 'ruby.managed' do
1
+ dep 'ruby', :template => 'bin' do
12
2
  installs {
13
- via :maverick, %w[ruby ruby1.8-dev]
14
- via :apt, %w[ruby irb ruby1.8-dev libopenssl-ruby]
3
+ via [:lenny, :hardy, :lucid], %w[ruby irb ruby1.8-dev libopenssl-ruby]
4
+ via :apt, %w[ruby ruby1.8-dev]
15
5
  via :yum, %w[ruby ruby-irb]
6
+ otherwise 'ruby'
16
7
  }
17
- provides %w[ruby irb]
18
- end
19
-
20
- dep 'ruby.external' do
21
- expects 'ruby >= 1.8.6', 'irb'
22
- otherwise { log_error "This system should already have ruby on it." }
8
+ provides 'ruby >= 1.8.6', 'irb'
23
9
  end
data/deps/rubygems.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  dep 'rubygems', :version do
2
- version.default!('1.8.10')
2
+ version.default!('1.8.23')
3
3
  requires 'ruby'
4
- requires_when_unmet 'curl.managed'
4
+ requires_when_unmet 'curl.bin'
5
5
  met? {
6
6
  # We check for ruby here too to make sure `ruby` and `gem` run from the same place.
7
7
  in_path? ["gem >= #{version}", 'ruby']
8
8
  }
9
9
  meet {
10
- handle_source "http://production.cf.rubygems.org/rubygems/rubygems-#{version}.tgz" do
10
+ Babushka::Resource.extract "http://production.cf.rubygems.org/rubygems/rubygems-#{version}.tgz" do
11
11
  log_shell "Installing rubygems-#{version}", "ruby setup.rb", :spinner => true, :sudo => !File.writable?(which('ruby'))
12
12
  end
13
13
  }
data/deps/system.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  dep 'admins can sudo' do
2
- requires 'admin group', 'sudo'
2
+ requires 'admin group', 'sudo.bin'
3
3
  met? { !sudo('cat /etc/sudoers').split("\n").grep(/^%admin/).empty? }
4
4
  meet { append_to_file '%admin ALL=(ALL) ALL', '/etc/sudoers', :sudo => true }
5
5
  end
6
6
 
7
7
  dep 'admin group' do
8
- met? { grep(/^admin\:/, '/etc/group') }
8
+ met? { '/etc/group'.p.grep(/^admin\:/) }
9
9
  meet { sudo 'groupadd admin' }
10
10
  end
@@ -1,66 +1,85 @@
1
1
  meta :app do
2
2
  accepts_list_for :source
3
3
  accepts_list_for :prefix, %w[~/Applications /Applications]
4
- accepts_list_for :extra_source
5
- accepts_list_for :provides, :name
4
+ accepts_value_for :provides, :name
5
+ accepts_value_for :version, nil
6
6
  accepts_block_for :current_version do |path| nil end
7
- accepts_block_for :latest_version
7
+ accepts_list_for :sparkle
8
8
 
9
- def app_name_match
10
- provides.first.to_s.sub(/\.app$/, '*.app')
9
+ def app
10
+ Babushka.VersionOf(provides, version)
11
11
  end
12
12
 
13
- def check_version path
14
- current = current_version.call(path)
15
- if current.nil? || version.nil?
16
- debug "Can't check versions without both current and latest."
17
- true
18
- elsif current >= version
19
- log_ok "#{name} is up to date at #{current}."
20
- else
21
- log "#{name} could be updated from #{current} to #{version}."
22
- end
13
+ def app_name_matcher
14
+ app.name.sub(/\.app$/, '*.app')
23
15
  end
24
16
 
25
- def prefix_to_use
26
- prefix.map(&:p).find {|pre|
27
- pre.directory?
28
- } || '/Applications'.p
17
+ def app_location
18
+ prefix.find {|p|
19
+ (p.to_s / app_name_matcher).glob.select {|entry|
20
+ (entry / 'Contents/MacOS').exists?
21
+ }.first
22
+ }
29
23
  end
30
24
 
31
- def discover_latest_version
32
- latest_value = latest_version.call
33
- # TODO this is just to detect the default block and ignore it. Yuck :)
34
- set_version latest_value unless latest_value == true
25
+ def prefix_to_use
26
+ prefix.map(&:p).find(&:directory?) || '/Applications'.p
35
27
  end
36
28
 
37
- template {
38
- prepare {
39
- setup_source_uris
29
+ def app_in_path?
30
+ app_location.tap {|path|
31
+ if path
32
+ log "Found #{app.name} in #{path}."
33
+ else
34
+ log "Couldn't find #{provides}."
35
+ end
40
36
  }
37
+ end
38
+
39
+ def get_source_from_sparkle
40
+ require 'rexml/document'
41
+ require 'net/http'
41
42
 
43
+ log_block 'Querying sparkle' do
44
+ sparkle.map {|uri|
45
+ Net::HTTP.get(URI.parse(uri))
46
+ }.map {|response|
47
+ REXML::Document.new(response)
48
+ }.map {|doc|
49
+ doc.elements['rss/channel/item/enclosure'].attributes['url']
50
+ }
51
+ end
52
+ end
53
+
54
+ template {
42
55
  met? {
43
- discover_latest_version
44
- installed = app_dir app_name_match
45
- (installed && check_version(installed)).tap {|result|
46
- log "Found at #{installed}." if result
56
+ app_in_path? and
57
+ Babushka::PathChecker.matching_versions?([app]) {|cmd|
58
+ current_version.call(app_location / provides)
47
59
  }
48
60
  }
49
61
 
62
+ prepare {
63
+ # Append any sparkle URLs found to the list of sources to process.
64
+ source get_source_from_sparkle
65
+ }
66
+
50
67
  meet {
51
- process_sources {|archive|
52
- Dir.glob("**/#{app_name_match}").select {|entry|
53
- (entry / 'Contents/MacOS').exists? # must be an app bundle itself
54
- }.reject {|entry|
55
- entry['.app/'] # mustn't be inside another app bundle
56
- }.map {|entry|
57
- pre = prefix_to_use
58
- target_path = pre / File.basename(entry)
59
- if !target_path.exists? || confirm("Overwrite #{target_path}?") { target_path.rm }
68
+ source.each {|uri|
69
+ Babushka::Resource.extract(uri) {|archive|
70
+ Dir.glob("**/#{app_name_matcher}").select {|entry|
71
+ (entry / 'Contents/MacOS').exists? # must be an app bundle itself
72
+ }.reject {|entry|
73
+ entry['.app/'] # mustn't be inside another app bundle
74
+ }.map {|entry|
75
+ pre = prefix_to_use
76
+ target_path = pre / File.basename(entry)
60
77
  log_block("Found #{entry}, copying to #{pre}") {
61
- entry.p.copy target_path
78
+ if !target_path.exists? || confirm("Overwrite #{target_path}?") { target_path.rm }
79
+ entry.p.copy target_path
80
+ end
62
81
  }
63
- end
82
+ }
64
83
  }
65
84
  }
66
85
  }