capsaicin 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 1
4
- :patch: 5
4
+ :patch: 6
data/lib/capsaicin.rb CHANGED
@@ -3,8 +3,16 @@ unless Capistrano::Configuration.respond_to?(:instance)
3
3
  end
4
4
  require 'capistrano'
5
5
 
6
+ module Capsaicin; end
7
+
6
8
  require File.join(File.dirname(__FILE__), %w(capsaicin sys))
7
9
  require File.join(File.dirname(__FILE__), %w(capsaicin invocation))
8
10
  require File.join(File.dirname(__FILE__), %w(capsaicin files))
9
11
  require File.join(File.dirname(__FILE__), %w(capsaicin service))
10
12
  require File.join(File.dirname(__FILE__), %w(capsaicin ui))
13
+
14
+ Capistrano::Configuration.send :include, Capsaicin::Invocation
15
+
16
+ Capistrano.plugin :files, Capsaicin::Files
17
+ Capistrano.plugin :local_files, Capsaicin::Files::Local
18
+ Capistrano.plugin :remote_files, Capsaicin::Files::Remote
@@ -44,5 +44,3 @@ module Capsaicin
44
44
  end
45
45
  end
46
46
  end
47
-
48
- Capistrano.plugin :files, Capsaicin::Files
@@ -70,6 +70,17 @@ module Capsaicin
70
70
  _lstar Zlib::GzipReader.new(File.open(src, 'rb')), options, &block
71
71
  end
72
72
 
73
+ def tar_x(src, options={}, &block)
74
+ logger and logger.trace "tar -xf #{src}"
75
+ _untar File.open(src, 'wb'), options, &block
76
+ end
77
+
78
+ def tar_xz(src, options={}, &block)
79
+ require 'zlib' unless defined? Zlib::GzipWriter
80
+ logger and logger.trace "tar -xzf #{src}"
81
+ _untar Zlib::GzipReader.new(File.open(src, 'rb')), options, &block
82
+ end
83
+
73
84
  private
74
85
 
75
86
  def _tar(os, src, options, &filter)
@@ -130,5 +141,3 @@ module Capsaicin
130
141
  end
131
142
  end
132
143
  end
133
-
134
- Capistrano.plugin :local_files, Capsaicin::Files::Local
@@ -56,12 +56,26 @@ module Capsaicin
56
56
  logger.trace "interrupted (Ctrl-C)" if logger
57
57
  end
58
58
 
59
- def upload(*args)
59
+ def upload(from, to, options={}, &block)
60
60
  case _via
61
61
  when :system, :local_run
62
- cp(*args)
62
+ cp from, to
63
63
  else
64
- @config.upload(*args)
64
+ if _via.to_s[0,4] == 'sudo'
65
+ if to[-1]==?/ || to[-1]==?\ || directory?(to)
66
+ tof = File.basename from
67
+ to2, to = "#{to}/#{tof}", "/tmp/#{tof}-#{Time.now.utc.to_i}"
68
+ else
69
+ tof = File.basename to
70
+ to2, to = to, "/tmp/#{tof}-#{Time.now.utc.to_i}"
71
+ end
72
+ end
73
+ @config.upload(from, to, options, &block)
74
+ if to2
75
+ run "chmod 0644 #{to}"
76
+ cp to, to2
77
+ run "rm -f #{to}"
78
+ end
65
79
  end
66
80
  end
67
81
 
@@ -74,12 +88,26 @@ module Capsaicin
74
88
  end
75
89
  end
76
90
 
77
- def put(from, to)
91
+ def put(data, path, options={})
78
92
  case _via
79
93
  when :system, :local_run
80
94
  FileUtils::Verbose.copy_stream StringIO.new(from), to
81
95
  else
82
- @config.put(from, to)
96
+ if _via.to_s[0,4] == 'sudo'
97
+ if path[-1]==?/ || path[-1]==?\ || directory?(path)
98
+ pathf = File.basename from
99
+ path2, path = "#{path}/#{pathf}", "/tmp/#{pathf}-#{Time.now.utc.to_i}"
100
+ else
101
+ pathf = File.basename path
102
+ path2, path = path, "/tmp/#{pathf}-#{Time.now.utc.to_i}"
103
+ end
104
+ end
105
+ @config.put(data, path, options)
106
+ if path2
107
+ run "chmod 0644 #{path}"
108
+ cp path, path2
109
+ run "rm -f #{path}"
110
+ end
83
111
  end
84
112
  end
85
113
 
@@ -111,6 +139,21 @@ module Capsaicin
111
139
  _r 'tar -cjf', Array(src).unshift(dest)
112
140
  end
113
141
 
142
+ def tar_x(dest, options={}, &filter)
143
+ filter and abort "tar_x: remote mode does not support a filtering proc"
144
+ _r 'tar -xf', [dest]
145
+ end
146
+
147
+ def tar_xz(dest, options={}, &filter)
148
+ filter and abort "tar_xz: remote mode does not support a filtering proc"
149
+ _r 'tar -xzf', [dest]
150
+ end
151
+
152
+ def tar_xj(dest, src, options={}, &filter)
153
+ filter and abort "tar_xj: remote mode does not support a filtering proc"
154
+ _r 'tar -xjf', Array(src).unshift(dest)
155
+ end
156
+
114
157
  def tar_t(src, options={}, &filter)
115
158
  filter and abort "tar_t: remote mode does not support a filtering proc"
116
159
  _t 'tar -tf', [src]
@@ -172,5 +215,3 @@ module Capsaicin
172
215
  end
173
216
  end
174
217
  end
175
-
176
- Capistrano.plugin :remote_files, Capsaicin::Files::Remote
@@ -2,6 +2,30 @@ module Capsaicin
2
2
 
3
3
  module Invocation
4
4
 
5
+ # Automatically uses the :run_method variable to run things.
6
+ # Equivalent to +invoke_command *args, :via=>fetch(:run_method, :run)+
7
+ def vrun(*args, &block)
8
+ options = Hash===args.last ? args.pop.dup : {}
9
+ options[:via] = fetch(:run_method, :run)
10
+ invoke_command *args.push(options), &block
11
+ end
12
+
13
+ # Automatically uses the :run_method variable to run things.
14
+ # Equivalent to +capture *args, :via=>fetch(:run_method, :run)+
15
+ def vcapture(*args, &block)
16
+ options = Hash===args.last ? args.pop.dup : {}
17
+ options[:via] = fetch(:run_method, :run)
18
+ capture *args.push(options), &block
19
+ end
20
+
21
+ # Automatically uses the :run_method variable to run things.
22
+ # Equivalent to +stream *args, :via=>fetch(:run_method, :run)+
23
+ def vstream(*args, &block)
24
+ options = Hash===args.last ? args.pop.dup : {}
25
+ options[:via] = fetch(:run_method, :run)
26
+ stream *args.push(options), &block
27
+ end
28
+
5
29
  # Capistrano's system() override is only available from the base deployment strategy.
6
30
  # Also, we could do with a few more windows checks.
7
31
  def local_run(*args, &block)
@@ -43,6 +67,4 @@ module Capsaicin
43
67
  run *args.push(options), &block
44
68
  end
45
69
  end
46
-
47
- Capistrano::Configuration.send :include, Invocation
48
70
  end
@@ -14,7 +14,7 @@ module Capsaicin
14
14
 
15
15
  svc_name = id.to_s
16
16
  svc_desc = next_description(:reset) || (svc_name.capitalize unless options.delete(:hide))
17
- extras = args.pop if Array === args.last
17
+ extras = options.delete(:extras) || {}
18
18
  via = options.delete(:via)
19
19
 
20
20
  namespace id do
@@ -29,10 +29,19 @@ module Capsaicin
29
29
  send(via || fetch(:run_method, :local_run), stop)
30
30
  end
31
31
 
32
- desc "#{svc_desc}: #{SVC_ACTION_CAPTIONS[:restart]}" if svc_desc
33
- task :restart, options do
34
- stop
35
- start
32
+ unless extras.key? :restart
33
+ desc "#{svc_desc}: #{SVC_ACTION_CAPTIONS[:restart]}" if svc_desc
34
+ task :restart, options do
35
+ stop
36
+ start
37
+ end
38
+ end
39
+
40
+ extras.each do |k,cmd|
41
+ desc "#{svc_desc}: #{SVC_ACTION_CAPTIONS[k]}" if svc_desc
42
+ task k, options do
43
+ send(via || fetch(:run_method, :local_run), cmd)
44
+ end
36
45
  end
37
46
 
38
47
  instance_eval { yield } if block_given?
data/test/helper.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'stringio'
2
+ require 'rubygems'
3
+ require 'capistrano/logger'
4
+
5
+ class CapistranoMock
6
+
7
+ def logbuf
8
+ @logbuf ||= StringIO.new
9
+ end
10
+
11
+ def logger
12
+ if @logger.nil?
13
+ @logger = Capistrano::Logger.new :output=>logbuf
14
+ @logger.level = Capistrano::Logger::MAX_LEVEL
15
+ end
16
+ @logger
17
+ end
18
+
19
+ end
@@ -0,0 +1,58 @@
1
+ require 'test/unit'
2
+ require 'helper'
3
+ require 'tmpdir'
4
+ require 'capsaicin/files'
5
+ require 'capsaicin/files/local'
6
+
7
+ class TestLocalFiles < Test::Unit::TestCase
8
+
9
+ def setup
10
+ @local = CapistranoMock.new
11
+ @local.extend Capsaicin::Files::Local
12
+ end
13
+
14
+ def test_exists
15
+ assert @local.exists?(__FILE__)
16
+ assert_equal "test -e #{__FILE__}", @local.logbuf.string.strip
17
+ end
18
+
19
+ def test_not_exists
20
+ assert ! @local.exists?(__FILE__+'/nope')
21
+ end
22
+
23
+ def test_readable
24
+ assert @local.readable?(__FILE__)
25
+ assert_equal "test -r #{__FILE__}", @local.logbuf.string.strip
26
+ end
27
+
28
+ def test_not_readable
29
+ assert ! @local.readable?(__FILE__+'/nope')
30
+ end
31
+
32
+ def test_writable
33
+ assert @local.writable?(Dir.tmpdir)
34
+ assert_equal "test -w #{Dir.tmpdir}", @local.logbuf.string.strip
35
+ end
36
+
37
+ def test_not_writable
38
+ assert ! @local.writable?(__FILE__+'/nope')
39
+ end
40
+
41
+ def test_file
42
+ assert @local.file?(__FILE__)
43
+ assert_equal "test -f #{__FILE__}", @local.logbuf.string.strip
44
+ end
45
+
46
+ def test_not_file
47
+ assert ! @local.file?(__FILE__+'/nope')
48
+ end
49
+
50
+ def test_directory
51
+ assert @local.directory?(File.dirname(__FILE__))
52
+ assert_equal "test -d #{File.dirname __FILE__}", @local.logbuf.string.strip
53
+ end
54
+
55
+ def test_not_directory
56
+ assert ! @local.directory?(__FILE__)
57
+ end
58
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capsaicin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Khoobyar
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-03 00:00:00 -04:00
12
+ date: 2009-06-06 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -59,6 +59,8 @@ files:
59
59
  - lib/capsaicin/service/windows.rb
60
60
  - lib/capsaicin/sys.rb
61
61
  - lib/capsaicin/ui.rb
62
+ - test/helper.rb
63
+ - test/test_local_files.rb
62
64
  has_rdoc: true
63
65
  homepage: http://github.com/joekhoobyar/capsaicin
64
66
  licenses: []
@@ -87,5 +89,6 @@ rubygems_version: 1.3.4
87
89
  signing_key:
88
90
  specification_version: 3
89
91
  summary: Joe Khoobyar's spicy capistrano extensions
90
- test_files: []
91
-
92
+ test_files:
93
+ - test/helper.rb
94
+ - test/test_local_files.rb