le1t0-capistrano 2.5.18.016 → 2.5.18.017

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ == 2.5.18.017 / Aug 13, 2010
2
+
3
+ Support variables scopes (i.e. setting variables to different value for different servers)
4
+ Support manipulating data when :up scping/sftping
5
+
1
6
  == 2.5.18.016 / Aug 12, 2010
2
7
 
3
8
  Add uploading files with parameterized file name
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.5.18.016
1
+ 2.5.18.017
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{le1t0-capistrano}
8
- s.version = "2.5.18.016"
8
+ s.version = "2.5.18.017"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Le1t0"]
12
- s.date = %q{2010-08-12}
12
+ s.date = %q{2010-08-13}
13
13
  s.description = %q{Capistrano is a utility and framework for executing commands in parallel on multiple remote machines, via SSH.}
14
14
  s.email = ["dev@ewout.to"]
15
15
  s.executables = ["capify", "cap"]
@@ -63,10 +63,16 @@ module Capistrano
63
63
  # the roles as the remaining parameters:
64
64
  #
65
65
  # server "master.example.com", :web, :app
66
- def server(host, *roles)
66
+ def server(host, *roles, &block)
67
67
  options = roles.last.is_a?(Hash) ? roles.pop : {}
68
+ old_scope = @scope
69
+ @scope = host if block_given?
68
70
  raise ArgumentError, "you must associate a server with at least one role" if roles.empty?
69
71
  roles.each { |name| role(name, host, options) }
72
+ if block_given?
73
+ yield
74
+ @scope = old_scope
75
+ end
70
76
  end
71
77
  end
72
78
  end
@@ -16,6 +16,13 @@ module Capistrano
16
16
  # instance.
17
17
  attr_reader :variables
18
18
 
19
+ def scope(scope_name, &block)
20
+ old_scope = @scope
21
+ @scope = scope_name
22
+ yield
23
+ @scope = old_scope
24
+ end
25
+
19
26
  # Set a variable to the given value.
20
27
  def set(variable, *args, &block)
21
28
  if variable.to_s !~ /^[_a-z]/
@@ -32,7 +39,14 @@ module Capistrano
32
39
 
33
40
  value = args.empty? ? block : args.first
34
41
  sym = variable.to_sym
35
- protect(sym) { @variables[sym] = value }
42
+ protect(sym) {
43
+ if @scope
44
+ @variables[@scope] ||= {}
45
+ @variables[@scope][sym] = value
46
+ else
47
+ @variables[sym] = value
48
+ end
49
+ }
36
50
  end
37
51
 
38
52
  alias :[]= :set
@@ -41,14 +55,29 @@ module Capistrano
41
55
  def unset(variable)
42
56
  sym = variable.to_sym
43
57
  protect(sym) do
44
- @original_procs.delete(sym)
45
- @variables.delete(sym)
58
+ if @scope
59
+ if @original_procs[@scope] && @original_procs[@scope][sym]
60
+ @original_procs[@scope].delete(sym)
61
+ @original_procs.delete(@scope) if @original_procs[@scope].empty?
62
+ else
63
+ @original_procs.delete(sym)
64
+ end
65
+ if @variables[@scope] && @variables[@scope][sym]
66
+ @variables[@scope].delete(sym)
67
+ @variables.delete(@scope) if @variables[@scope].empty?
68
+ else
69
+ @variables.delete(sym)
70
+ end
71
+ else
72
+ @original_procs.delete(sym)
73
+ @variables.delete(sym)
74
+ end
46
75
  end
47
76
  end
48
77
 
49
78
  # Returns true if the variable has been defined, and false otherwise.
50
79
  def exists?(variable)
51
- @variables.key?(variable.to_sym)
80
+ (@scope && @variables[@scope] && @variables[@scope].key?(variable.to_sym)) || @variables.key?(variable.to_sym)
52
81
  end
53
82
 
54
83
  # If the variable was originally a proc value, it will be reset to it's
@@ -57,7 +86,11 @@ module Capistrano
57
86
  def reset!(variable)
58
87
  sym = variable.to_sym
59
88
  protect(sym) do
60
- if @original_procs.key?(sym)
89
+ if @scope && @original_procs[@scope] && @original_procs[@scope].key?(sym)
90
+ @variables[@scope] ||= {}
91
+ @variables[@scope][sym] = @original_procs[@scope].delete(sym)
92
+ true
93
+ elsif @original_procs.key?(sym)
61
94
  @variables[sym] = @original_procs.delete(sym)
62
95
  true
63
96
  else
@@ -76,29 +109,53 @@ module Capistrano
76
109
 
77
110
  sym = variable.to_sym
78
111
  protect(sym) do
79
- if !@variables.key?(sym)
80
- return args.first unless args.empty?
81
- return yield(variable) if block_given?
82
- raise IndexError, "`#{variable}' not found"
83
- end
84
-
85
- if @variables[sym].respond_to?(:call)
86
- @original_procs[sym] = @variables[sym]
87
- @variables[sym] = @variables[sym].call
112
+ if @scope
113
+ if !exists?(variable)
114
+ return args.first unless args.empty?
115
+ return yield(variable) if block_given?
116
+ raise IndexError, "`#{variable}' not found"
117
+ end
118
+
119
+ if @variables[@scope] && @variables[@scope].respond_to?(:call)
120
+ @original_procs[@scope] ||= {}
121
+ @variables[@scope] ||= {}
122
+ @original_procs[@scope][sym] = @variables[@scope][sym]
123
+ @variables[@scope][sym] = @variables[@scope][sym].call
124
+ elsif @variables[sym].respond_to?(:call)
125
+ @original_procs[sym] = @variables[sym]
126
+ @variables[sym] = @variables[sym].call
127
+ end
128
+ else
129
+ if !@variables.key?(sym)
130
+ return args.first unless args.empty?
131
+ return yield(variable) if block_given?
132
+ raise IndexError, "`#{variable}' not found"
133
+ end
134
+
135
+ if @variables[sym].respond_to?(:call)
136
+ @original_procs[sym] = @variables[sym]
137
+ @variables[sym] = @variables[sym].call
138
+ end
88
139
  end
89
140
  end
90
141
 
91
- @variables[sym]
142
+ (@scope && @variables[@scope] && @variables[@scope][sym]) || @variables[sym]
92
143
  end
93
144
 
94
145
  def [](variable)
95
146
  fetch(variable, nil)
96
147
  end
148
+
149
+ def variables_has_key?(key)
150
+ (@scope && @variables[@scope] && @variables[@scope].has_key?(key)) || @variables.has_key?(key)
151
+ end
97
152
 
98
153
  def initialize_with_variables(*args) #:nodoc:
99
154
  initialize_without_variables(*args)
155
+ @scope = nil
100
156
  @variables = {}
101
157
  @original_procs = {}
158
+ @scoped_variable_locks = {}
102
159
  @variable_locks = Hash.new { |h,k| h[k] = Mutex.new }
103
160
 
104
161
  set :ssh_options, {}
@@ -107,16 +164,21 @@ module Capistrano
107
164
  private :initialize_with_variables
108
165
 
109
166
  def protect(variable)
110
- @variable_locks[variable.to_sym].synchronize { yield }
167
+ if @scope && @scoped_variable_locks[@scope] && @scoped_variable_locks[@scope][variable.to_sym]
168
+ @scoped_variable_locks[@scope] ||= Hash.new { |h,k| h[k] = Mutex.new }
169
+ @scoped_variable_locks[@scope][variable.to_sym].synchronize { yield }
170
+ else
171
+ @variable_locks[variable.to_sym].synchronize { yield }
172
+ end
111
173
  end
112
174
  private :protect
113
175
 
114
176
  def respond_to_with_variables?(sym, include_priv=false) #:nodoc:
115
- @variables.has_key?(sym) || respond_to_without_variables?(sym, include_priv)
177
+ variables_has_key?(sym) || respond_to_without_variables?(sym, include_priv)
116
178
  end
117
179
 
118
180
  def method_missing_with_variables(sym, *args, &block) #:nodoc:
119
- if args.length == 0 && block.nil? && @variables.has_key?(sym)
181
+ if args.length == 0 && block.nil? && variables_has_key?(sym)
120
182
  self[sym]
121
183
  else
122
184
  method_missing_without_variables(sym, *args, &block)
@@ -28,6 +28,7 @@ module Capistrano
28
28
  @from = from
29
29
  @to = to
30
30
  @sessions = sessions
31
+ proc = options.delete(:proc)
31
32
  @options = options
32
33
  @callback = block
33
34
 
@@ -36,7 +37,7 @@ module Capistrano
36
37
 
37
38
  @session_map = {}
38
39
 
39
- prepare_transfers
40
+ prepare_transfers(proc)
40
41
  end
41
42
 
42
43
  def process!
@@ -97,7 +98,7 @@ module Capistrano
97
98
  @session_map
98
99
  end
99
100
 
100
- def prepare_transfers
101
+ def prepare_transfers(proc)
101
102
  logger.info "#{transport} #{operation} #{from} -> #{to}" if logger
102
103
 
103
104
  @transfers = sessions.map do |session|
@@ -106,21 +107,23 @@ module Capistrano
106
107
 
107
108
  session_map[session] = case transport
108
109
  when :sftp
109
- prepare_sftp_transfer(session_from, session_to, session)
110
+ prepare_sftp_transfer(session_from, session_to, session, proc)
110
111
  when :scp
111
- prepare_scp_transfer(session_from, session_to, session)
112
+ prepare_scp_transfer(session_from, session_to, session, proc)
112
113
  else
113
114
  raise ArgumentError, "unsupported transport type: #{transport.inspect}"
114
115
  end
115
116
  end
116
117
  end
117
118
 
118
- def prepare_scp_transfer(from, to, session)
119
+ def prepare_scp_transfer(from, to, session, proc)
119
120
  real_callback = callback || Proc.new do |channel, name, sent, total|
120
121
  logger.trace "[#{channel[:host]}] #{name}" if logger && sent == 0
121
122
  end
122
123
 
123
- if direction == :up && from.is_a?(StringIO) && from.string =~ /%\{host\}/
124
+ if proc.is_a?(Proc)
125
+ from = proc.call(from.is_a?(StringIO) ? from.string : from, session.xserver.host)
126
+ elsif direction == :up && from.is_a?(StringIO) && from.string =~ /%\{host\}/
124
127
  from_string = from.string.gsub(/%\{host\}/, session.xserver.host)
125
128
  from = File.exist?(from_string) ? from_string : StringIO.new(from_string)
126
129
  end
@@ -166,7 +169,7 @@ module Capistrano
166
169
  end
167
170
  end
168
171
 
169
- def prepare_sftp_transfer(from, to, session)
172
+ def prepare_sftp_transfer(from, to, session, proc)
170
173
  SFTPTransferWrapper.new(session) do |sftp|
171
174
  real_callback = Proc.new do |event, op, *args|
172
175
  if callback
@@ -183,7 +186,9 @@ module Capistrano
183
186
  :server => session.xserver,
184
187
  :host => session.xserver.host)
185
188
 
186
- if direction == :up && from.is_a?(StringIO) && from.string =~ /%\{host\}/
189
+ if proc.is_a?(Proc)
190
+ from = proc.call(from.is_a?(StringIO) ? from.string : from, session.xserver.host)
191
+ elsif direction == :up && from.is_a?(StringIO) && from.string =~ /%\{host\}/
187
192
  from_string = from.string.gsub(/%\{host\}/, session.xserver.host)
188
193
  from = File.exist?(from_string) ? from_string : StringIO.new(from_string)
189
194
  end
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 2
7
7
  - 5
8
8
  - 18
9
- - 16
10
- version: 2.5.18.016
9
+ - 17
10
+ version: 2.5.18.017
11
11
  platform: ruby
12
12
  authors:
13
13
  - Le1t0
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-12 00:00:00 +02:00
18
+ date: 2010-08-13 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency