doo 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,21 +1,3 @@
1
- begin
2
- require 'jeweler'
3
- Jeweler::Tasks.new do |gem|
4
- gem.version
5
- gem.name = "doo"
6
- gem.summary = %Q{Doo - a stacked-context approach to deployment scripting }
7
- gem.description = %Q{Doo is a deployment scripting tool in the vein of capistrano and sprinkle that uses stacked contexts and a aspect-ish data model}
8
- gem.homepage = "http://github.com/mtrudel/doo"
9
- gem.authors = [ "Mat Trudel" ]
10
- gem.email = [ "mat@geeky.net" ]
11
- gem.executables = %W(doo)
12
- gem.files = FileList["[A-Z]*", "{bin,examples,lib,spec}/**/*", 'lib/jeweler/templates/.gitignore']
13
- gem.add_dependency "highline"
14
- end
15
- rescue LoadError
16
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
- end
18
-
19
1
  require 'rspec/core/rake_task'
20
2
  desc "Run all tests"
21
3
  RSpec::Core::RakeTask.new('spec') do |t|
data/lib/doo/base.rb CHANGED
@@ -30,7 +30,7 @@ module Doo
30
30
  obj.instance_eval &block if block_given?
31
31
  obj
32
32
  end
33
-
33
+
34
34
  private
35
35
  def singleton_class
36
36
  class << self
@@ -38,4 +38,4 @@ module Doo
38
38
  end
39
39
  end
40
40
  end
41
- end
41
+ end
@@ -1,12 +1,48 @@
1
+ require 'highline'
2
+ require 'colorize'
3
+
1
4
  Doo::Base.class_eval do
2
5
  SEPARATORS = %w( / @ : | _ - # ^ ? )
3
-
4
- def replace(file, src, replace, options = {})
6
+
7
+ def replace(file, src, replace, opts = {})
5
8
  sep = SEPARATORS.detect { |x| !src.include?(x) && !replace.include?(x) }
6
- sudo "sed -i -e 's#{sep}#{src}#{sep}#{replace}#{sep}g' #{file}"
9
+ run "sed -i -e 's#{sep}#{src}#{sep}#{replace}#{sep}g' #{file}", opts
10
+ end
11
+
12
+ def append(file, text, opts = {})
13
+ run "grep '#{text}' #{file} || echo '#{text}' >> #{file}", opts
14
+ end
15
+
16
+ def sudo(cmd, opts = {})
17
+ run(cmd, opts.merge(:sudo => true))
18
+ end
19
+
20
+ private
21
+ def sudoize(cmd)
22
+ "sudo sh -c \"#{cmd.gsub(/\"/, "\\\"")}\""
7
23
  end
8
24
 
9
- def append(file, text, options = {})
10
- sudo "grep '#{text}' #{file} || echo '#{text}' >> #{file}"
25
+ def run!(cmd, opts = {})
26
+ with_clone(opts) do
27
+ if confirm
28
+ return false unless HighLine.new.agree("Run \"#{cmd}\"? ")
29
+ elsif verbose
30
+ puts "Running \"#{cmd}\"".green
31
+ end
32
+ unless dry_run
33
+ if defined?(capture) && capture
34
+ return `#{cmd}`
35
+ else
36
+ system cmd
37
+ if $? != 0 && (!defined? just_return_failure || !just_return_failure)
38
+ puts "Error code #{$?} running #{cmd}".red
39
+ raise
40
+ end
41
+ return $?.exitstatus
42
+ end
43
+ else
44
+ true
45
+ end
46
+ end
11
47
  end
12
48
  end
@@ -1,9 +1,9 @@
1
1
  Doo::Base.class_eval do
2
2
  def if_passes(test, &block)
3
- yield if run "#{test}"
3
+ yield unless run "#{test}", :just_return_failure => true
4
4
  end
5
5
 
6
6
  def if_fails(test, &block)
7
- yield unless run "#{test}"
8
- end
7
+ yield if run "#{test}", :just_return_failure => true
8
+ end
9
9
  end
@@ -1,17 +1,11 @@
1
- require 'highline'
2
-
3
1
  Doo::Base.class_eval do
4
2
  def run_locally(variables = {}, &block)
5
3
  with_clone(variables) do
6
- def run(cmd)
7
- if confirm
8
- return false unless HighLine.new.agree("Run \"#{cmd}\"? ")
9
- elsif verbose
10
- puts "Running \"#{cmd}\""
11
- end
12
- system cmd unless dry_run
13
- $?
4
+ def run(cmd, opts = {})
5
+ cmd = sudoize(cmd) if opts[:sudo]
6
+ run! cmd, opts
14
7
  end
8
+
15
9
  instance_eval &block if block_given?
16
10
  end
17
11
  end
@@ -1,51 +1,47 @@
1
- require 'highline'
2
-
3
1
  Doo::Base.class_eval do
4
2
  def run_on_server(servers, variables = {}, &block)
5
3
  servers.each do |host, params|
6
4
  with_clone(variables.merge({:host => host}).merge(params || {})) do
7
- def run(remote_cmd, opt = {})
5
+ def run(remote_cmd, opts = {})
8
6
  cmdopts = ["-S \"~/.ssh/master-%l-%r@%h:%p\""]
9
- cmdopts << "-t" if !opt.include? :pty || opt[:pty]
7
+ cmdopts << "-t" if !opts.include? :pty || opts[:pty]
10
8
  cmdopts << "-p#{ssh_port}" if defined? ssh_port
11
- cmd = "ssh #{cmdopts.join(' ')} #{user}@#{host} \"#{remote_cmd.gsub(/\"/, "\\\"")}\""
12
- if confirm
13
- return false unless HighLine.new.agree("Run \"#{cmd}\"? ")
14
- elsif verbose
15
- puts "Running \"#{cmd}\""
16
- end
17
- system(cmd) || raise("SSH Error") unless dry_run
18
- $?
9
+ remote_cmd = sudoize(remote_cmd) if opts[:sudo]
10
+ run! "ssh #{cmdopts.join(' ')} #{user}@#{host} \"#{remote_cmd.gsub(/\"/, "\\\"")}\"", opts
19
11
  end
20
12
 
21
- def put(local, remote, opt = {})
13
+ def put(local, remote, opts = {})
14
+ if defined?(opts[:sudo]) && opts[:sudo]
15
+ tmp_loc = run("mktemp -d -t dooXXXXX", :capture => true).chomp
16
+ real_remote = remote
17
+ remote = File.join(tmp_loc, remote)
18
+ run "mkdir -p #{File.dirname(remote)}"
19
+ end
22
20
  cmdopts = ["-r"]
23
21
  cmdopts << "-oProxyCommand=\"ssh #{gateway} exec nc %h %p\"" if defined?(gateway) && gateway
24
- cmd = "scp #{cmdopts.join(' ')} #{local} #{user}@#{host}:#{remote}"
25
- if confirm
26
- return false unless HighLine.new.agree("Run \"#{cmd}\"? ")
27
- elsif verbose
28
- puts "Running \"#{cmd}\""
22
+ cmdopts << "-P#{ssh_port}" if defined? ssh_port
23
+ result = run! "scp #{cmdopts.join(' ')} #{local} #{user}@#{host}:#{remote}"
24
+ run "chmod #{opts[:mode]} #{remote}" if defined?(opts[:mode]) && opts[:mode]
25
+ sudo "chown -R #{opts[:owner]} #{remote}" if defined?(opts[:owner]) && opts[:owner]
26
+ sudo "chgrp -R #{opts[:group]} #{remote}" if defined?(opts[:group]) && opts[:group]
27
+ if defined?(opts[:sudo]) && opts[:sudo]
28
+ sudo "mv #{remote} #{real_remote}"
29
+ run "rm -rf #{tmp_loc}"
29
30
  end
30
- system(cmd) || raise("Scp Error") unless dry_run
31
- result = $?
32
- run("chmod #{opt[:mode]} #{remote}") if defined? opt[:mode]
33
31
  result
34
32
  end
35
33
 
36
34
  begin
37
35
  cmdopts = ["-MNf -S \"~/.ssh/master-%l-%r@%h:%p\""]
38
36
  cmdopts << "-oProxyCommand=\"ssh #{gateway} exec nc %h %p\"" if defined?(gateway) && gateway
39
- command = "ssh #{cmdopts.join(' ')} #{user}@#{host}"
40
- puts "Running #{command}" if verbose
41
- system(command) || raise("SSH Error") unless dry_run
42
-
37
+ cmdopts << "-p#{ssh_port}" if defined? ssh_port
38
+ run! "ssh #{cmdopts.join(' ')} #{user}@#{host}"
39
+
40
+ # Now run the actual commands
43
41
  instance_eval &block if block_given?
44
42
  ensure
45
43
  cmdopts = ["-Oexit -S \"~/.ssh/master-%l-%r@%h:%p\""]
46
- command = "ssh #{cmdopts.join(' ')} #{user}@#{host}"
47
- puts "Running #{command}" if verbose
48
- system(command) || raise("SSH Error") unless dry_run
44
+ run! "ssh #{cmdopts.join(' ')} #{user}@#{host}"
49
45
  end
50
46
  end
51
47
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doo
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 7
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
- - 5
8
+ - 6
8
9
  - 0
9
- version: 0.5.0
10
+ version: 0.6.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Mat Trudel
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-12-14 00:00:00 -05:00
18
+ date: 2010-12-16 00:00:00 -05:00
18
19
  default_executable: doo
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -25,11 +26,26 @@ dependencies:
25
26
  requirements:
26
27
  - - ">="
27
28
  - !ruby/object:Gem::Version
29
+ hash: 3
28
30
  segments:
29
31
  - 0
30
32
  version: "0"
31
33
  type: :runtime
32
34
  version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: colorize
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
33
49
  description: Doo is a deployment scripting tool in the vein of capistrano and sprinkle that uses stacked contexts and a aspect-ish data model
34
50
  email:
35
51
  - mat@geeky.net
@@ -42,7 +58,6 @@ extra_rdoc_files:
42
58
  files:
43
59
  - README.md
44
60
  - Rakefile
45
- - VERSION
46
61
  - bin/doo
47
62
  - examples/sample.rb
48
63
  - lib/doo.rb
@@ -69,6 +84,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
84
  requirements:
70
85
  - - ">="
71
86
  - !ruby/object:Gem::Version
87
+ hash: 3
72
88
  segments:
73
89
  - 0
74
90
  version: "0"
@@ -77,6 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
93
  requirements:
78
94
  - - ">="
79
95
  - !ruby/object:Gem::Version
96
+ hash: 3
80
97
  segments:
81
98
  - 0
82
99
  version: "0"
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.5.0