joekhoobyar-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 +1 -1
- data/lib/capsaicin/files/local.rb +11 -2
- data/lib/capsaicin/files/remote.rb +32 -7
- data/lib/capsaicin/files.rb +0 -2
- data/lib/capsaicin/invocation.rb +8 -2
- data/lib/capsaicin/service/command.rb +14 -5
- data/lib/capsaicin/service/lsb.rb +10 -9
- data/lib/capsaicin.rb +6 -0
- data/test/helper.rb +19 -0
- data/test/test_local_files.rb +58 -0
- metadata +7 -4
data/VERSION.yml
CHANGED
@@ -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,18 @@ module Capsaicin
|
|
56
56
|
logger.trace "interrupted (Ctrl-C)" if logger
|
57
57
|
end
|
58
58
|
|
59
|
-
def upload(
|
59
|
+
def upload(from, to, options={}, &block)
|
60
60
|
case _via
|
61
61
|
when :system, :local_run
|
62
|
-
cp
|
62
|
+
cp from, to
|
63
63
|
else
|
64
|
-
|
64
|
+
to2, to = to, "/tmp/#{File.basename to}-#{Time.now.utc.to_i}" if _via.to_s[0,4] == 'sudo'
|
65
|
+
@config.upload(from, to, options, &block)
|
66
|
+
if to2
|
67
|
+
run "chmod 0644 #{to}"
|
68
|
+
cp to, to2
|
69
|
+
run "rm -f #{to}"
|
70
|
+
end
|
65
71
|
end
|
66
72
|
end
|
67
73
|
|
@@ -74,12 +80,18 @@ module Capsaicin
|
|
74
80
|
end
|
75
81
|
end
|
76
82
|
|
77
|
-
def put(
|
83
|
+
def put(data, path, options={})
|
78
84
|
case _via
|
79
85
|
when :system, :local_run
|
80
86
|
FileUtils::Verbose.copy_stream StringIO.new(from), to
|
81
87
|
else
|
82
|
-
|
88
|
+
path2, path = path, "/tmp/#{File.basename path}-#{Time.now.utc.to_i}" if _via.to_s[0,4] == 'sudo'
|
89
|
+
@config.put(data, path, options)
|
90
|
+
if path2
|
91
|
+
run "chmod 0644 #{path}"
|
92
|
+
cp path, path2
|
93
|
+
run "rm -f #{path}"
|
94
|
+
end
|
83
95
|
end
|
84
96
|
end
|
85
97
|
|
@@ -111,6 +123,21 @@ module Capsaicin
|
|
111
123
|
_r 'tar -cjf', Array(src).unshift(dest)
|
112
124
|
end
|
113
125
|
|
126
|
+
def tar_x(dest, options={}, &filter)
|
127
|
+
filter and abort "tar_x: remote mode does not support a filtering proc"
|
128
|
+
_r 'tar -xf', [dest]
|
129
|
+
end
|
130
|
+
|
131
|
+
def tar_xz(dest, options={}, &filter)
|
132
|
+
filter and abort "tar_xz: remote mode does not support a filtering proc"
|
133
|
+
_r 'tar -xzf', [dest]
|
134
|
+
end
|
135
|
+
|
136
|
+
def tar_xj(dest, src, options={}, &filter)
|
137
|
+
filter and abort "tar_xj: remote mode does not support a filtering proc"
|
138
|
+
_r 'tar -xjf', Array(src).unshift(dest)
|
139
|
+
end
|
140
|
+
|
114
141
|
def tar_t(src, options={}, &filter)
|
115
142
|
filter and abort "tar_t: remote mode does not support a filtering proc"
|
116
143
|
_t 'tar -tf', [src]
|
@@ -172,5 +199,3 @@ module Capsaicin
|
|
172
199
|
end
|
173
200
|
end
|
174
201
|
end
|
175
|
-
|
176
|
-
Capistrano.plugin :remote_files, Capsaicin::Files::Remote
|
data/lib/capsaicin/files.rb
CHANGED
data/lib/capsaicin/invocation.rb
CHANGED
@@ -2,6 +2,14 @@ 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
|
+
|
5
13
|
# Capistrano's system() override is only available from the base deployment strategy.
|
6
14
|
# Also, we could do with a few more windows checks.
|
7
15
|
def local_run(*args, &block)
|
@@ -43,6 +51,4 @@ module Capsaicin
|
|
43
51
|
run *args.push(options), &block
|
44
52
|
end
|
45
53
|
end
|
46
|
-
|
47
|
-
Capistrano::Configuration.send :include, Invocation
|
48
54
|
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 =
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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?
|
@@ -22,24 +22,25 @@ module Capsaicin
|
|
22
22
|
|
23
23
|
namespace id do
|
24
24
|
svc_id = Symbol === id ? id.to_s : id.split(':').last
|
25
|
-
svc_cmd = case basedir
|
26
|
-
when String; basedir + '/' + svc_id
|
27
|
-
when NilClass; '/etc/init.d' + svc_id
|
28
|
-
when Symbol; fetch(basedir) + '/' + svc_id
|
29
|
-
when Proc; basedir.call + '/' + svc_id
|
30
|
-
end
|
31
25
|
|
32
26
|
desc "#{svc_desc}: #{SVC_ACTION_CAPTIONS[:status]}" if svc_desc
|
33
27
|
task :default, options do
|
34
28
|
status
|
35
29
|
end
|
36
|
-
|
30
|
+
svc_cmd = Proc.new do
|
31
|
+
case basedir
|
32
|
+
when String; basedir + '/' + svc_id
|
33
|
+
when NilClass; '/etc/init.d/' + svc_id
|
34
|
+
when Symbol; fetch(basedir) + '/' + svc_id
|
35
|
+
when Proc; basedir.call(svc_id)
|
36
|
+
end
|
37
|
+
end
|
37
38
|
svc_actions.each do |svc_action|
|
38
39
|
svc_action = svc_action.intern if String === svc_action
|
39
40
|
desc "#{svc_desc}: #{SVC_ACTION_CAPTIONS[svc_action]}" if svc_desc
|
40
41
|
task svc_action, options do
|
41
|
-
_run_method = basedir ? fetch(:run_method, :
|
42
|
-
send(_run_method, "#{svc_cmd} #{svc_action}")
|
42
|
+
_run_method = basedir ? fetch(:run_method, :run) : :sudo
|
43
|
+
send(_run_method, "#{svc_cmd.call} #{svc_action}")
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
data/lib/capsaicin.rb
CHANGED
@@ -8,3 +8,9 @@ require File.join(File.dirname(__FILE__), %w(capsaicin invocation))
|
|
8
8
|
require File.join(File.dirname(__FILE__), %w(capsaicin files))
|
9
9
|
require File.join(File.dirname(__FILE__), %w(capsaicin service))
|
10
10
|
require File.join(File.dirname(__FILE__), %w(capsaicin ui))
|
11
|
+
|
12
|
+
Capistrano::Configuration.send :include, Invocation
|
13
|
+
|
14
|
+
Capistrano.plugin :files, Capsaicin::Files
|
15
|
+
Capistrano.plugin :local_files, Capsaicin::Files::Local
|
16
|
+
Capistrano.plugin :remote_files, Capsaicin::Files::Remote
|
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: joekhoobyar-capsaicin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
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-
|
12
|
+
date: 2009-06-06 00:00:00 -07: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: false
|
63
65
|
homepage: http://github.com/joekhoobyar/capsaicin
|
64
66
|
post_install_message:
|
@@ -85,5 +87,6 @@ rubygems_version: 1.2.0
|
|
85
87
|
signing_key:
|
86
88
|
specification_version: 3
|
87
89
|
summary: Joe Khoobyar's spicy capistrano extensions
|
88
|
-
test_files:
|
89
|
-
|
90
|
+
test_files:
|
91
|
+
- test/helper.rb
|
92
|
+
- test/test_local_files.rb
|