engineyard-serverside 1.5.23.ruby19.8 → 1.5.23.ruby19.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/lib/engineyard-serverside.rb +3 -1
  2. data/lib/engineyard-serverside/cli.rb +11 -19
  3. data/lib/engineyard-serverside/deploy.rb +3 -3
  4. data/lib/engineyard-serverside/future.rb +33 -0
  5. data/lib/engineyard-serverside/futures/celluloid.rb +25 -0
  6. data/lib/engineyard-serverside/futures/dataflow.rb +25 -0
  7. data/lib/engineyard-serverside/logged_output.rb +8 -3
  8. data/lib/engineyard-serverside/task.rb +9 -12
  9. data/lib/engineyard-serverside/version.rb +1 -1
  10. data/lib/vendor/celluloid/lib/celluloid.rb +261 -0
  11. data/lib/vendor/celluloid/lib/celluloid/actor.rb +242 -0
  12. data/lib/vendor/celluloid/lib/celluloid/actor_pool.rb +54 -0
  13. data/lib/vendor/celluloid/lib/celluloid/actor_proxy.rb +75 -0
  14. data/lib/vendor/celluloid/lib/celluloid/application.rb +78 -0
  15. data/lib/vendor/celluloid/lib/celluloid/calls.rb +94 -0
  16. data/lib/vendor/celluloid/lib/celluloid/core_ext.rb +14 -0
  17. data/lib/vendor/celluloid/lib/celluloid/events.rb +14 -0
  18. data/lib/vendor/celluloid/lib/celluloid/fiber.rb +33 -0
  19. data/lib/vendor/celluloid/lib/celluloid/fsm.rb +141 -0
  20. data/lib/vendor/celluloid/lib/celluloid/future.rb +60 -0
  21. data/lib/vendor/celluloid/lib/celluloid/links.rb +61 -0
  22. data/lib/vendor/celluloid/lib/celluloid/logger.rb +32 -0
  23. data/lib/vendor/celluloid/lib/celluloid/mailbox.rb +124 -0
  24. data/lib/vendor/celluloid/lib/celluloid/receivers.rb +66 -0
  25. data/lib/vendor/celluloid/lib/celluloid/registry.rb +33 -0
  26. data/lib/vendor/celluloid/lib/celluloid/responses.rb +26 -0
  27. data/lib/vendor/celluloid/lib/celluloid/rspec.rb +2 -0
  28. data/lib/vendor/celluloid/lib/celluloid/signals.rb +50 -0
  29. data/lib/vendor/celluloid/lib/celluloid/supervisor.rb +57 -0
  30. data/lib/vendor/celluloid/lib/celluloid/task.rb +73 -0
  31. data/lib/vendor/celluloid/lib/celluloid/tcp_server.rb +33 -0
  32. data/lib/vendor/celluloid/lib/celluloid/timers.rb +109 -0
  33. data/lib/vendor/celluloid/lib/celluloid/version.rb +4 -0
  34. data/lib/vendor/dataflow/dataflow.rb +124 -0
  35. data/lib/vendor/dataflow/dataflow/actor.rb +22 -0
  36. data/lib/vendor/dataflow/dataflow/equality.rb +44 -0
  37. data/lib/vendor/dataflow/dataflow/future_queue.rb +24 -0
  38. data/lib/vendor/dataflow/dataflow/port.rb +54 -0
  39. data/lib/vendor/open4/lib/open4.rb +432 -0
  40. data/lib/vendor/thor/lib/thor.rb +244 -0
  41. data/lib/vendor/thor/lib/thor/actions.rb +275 -0
  42. data/lib/vendor/thor/lib/thor/actions/create_file.rb +103 -0
  43. data/lib/vendor/thor/lib/thor/actions/directory.rb +91 -0
  44. data/lib/vendor/thor/lib/thor/actions/empty_directory.rb +134 -0
  45. data/lib/vendor/thor/lib/thor/actions/file_manipulation.rb +223 -0
  46. data/lib/vendor/thor/lib/thor/actions/inject_into_file.rb +104 -0
  47. data/lib/vendor/thor/lib/thor/base.rb +540 -0
  48. data/lib/vendor/thor/lib/thor/core_ext/file_binary_read.rb +9 -0
  49. data/lib/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +75 -0
  50. data/lib/vendor/thor/lib/thor/core_ext/ordered_hash.rb +100 -0
  51. data/lib/vendor/thor/lib/thor/error.rb +30 -0
  52. data/lib/vendor/thor/lib/thor/group.rb +271 -0
  53. data/lib/vendor/thor/lib/thor/invocation.rb +180 -0
  54. data/lib/vendor/thor/lib/thor/parser.rb +4 -0
  55. data/lib/vendor/thor/lib/thor/parser/argument.rb +67 -0
  56. data/lib/vendor/thor/lib/thor/parser/arguments.rb +150 -0
  57. data/lib/vendor/thor/lib/thor/parser/option.rb +128 -0
  58. data/lib/vendor/thor/lib/thor/parser/options.rb +169 -0
  59. data/lib/vendor/thor/lib/thor/rake_compat.rb +66 -0
  60. data/lib/vendor/thor/lib/thor/runner.rb +314 -0
  61. data/lib/vendor/thor/lib/thor/shell.rb +83 -0
  62. data/lib/vendor/thor/lib/thor/shell/basic.rb +239 -0
  63. data/lib/vendor/thor/lib/thor/shell/color.rb +108 -0
  64. data/lib/vendor/thor/lib/thor/task.rb +102 -0
  65. data/lib/vendor/thor/lib/thor/util.rb +230 -0
  66. data/lib/vendor/thor/lib/thor/version.rb +3 -0
  67. metadata +70 -10
@@ -0,0 +1,244 @@
1
+ require 'thor/base'
2
+
3
+ # TODO: Update thor to allow for git-style CLI (git bisect run)
4
+ class Thor
5
+ class << self
6
+ # Sets the default task when thor is executed without an explicit task to be called.
7
+ #
8
+ # ==== Parameters
9
+ # meth<Symbol>:: name of the defaut task
10
+ #
11
+ def default_task(meth=nil)
12
+ case meth
13
+ when :none
14
+ @default_task = 'help'
15
+ when nil
16
+ @default_task ||= from_superclass(:default_task, 'help')
17
+ else
18
+ @default_task = meth.to_s
19
+ end
20
+ end
21
+
22
+ # Defines the usage and the description of the next task.
23
+ #
24
+ # ==== Parameters
25
+ # usage<String>
26
+ # description<String>
27
+ #
28
+ def desc(usage, description, options={})
29
+ if options[:for]
30
+ task = find_and_refresh_task(options[:for])
31
+ task.usage = usage if usage
32
+ task.description = description if description
33
+ else
34
+ @usage, @desc = usage, description
35
+ end
36
+ end
37
+
38
+ # Maps an input to a task. If you define:
39
+ #
40
+ # map "-T" => "list"
41
+ #
42
+ # Running:
43
+ #
44
+ # thor -T
45
+ #
46
+ # Will invoke the list task.
47
+ #
48
+ # ==== Parameters
49
+ # Hash[String|Array => Symbol]:: Maps the string or the strings in the array to the given task.
50
+ #
51
+ def map(mappings=nil)
52
+ @map ||= from_superclass(:map, {})
53
+
54
+ if mappings
55
+ mappings.each do |key, value|
56
+ if key.respond_to?(:each)
57
+ key.each {|subkey| @map[subkey] = value}
58
+ else
59
+ @map[key] = value
60
+ end
61
+ end
62
+ end
63
+
64
+ @map
65
+ end
66
+
67
+ # Declares the options for the next task to be declared.
68
+ #
69
+ # ==== Parameters
70
+ # Hash[Symbol => Object]:: The hash key is the name of the option and the value
71
+ # is the type of the option. Can be :string, :array, :hash, :boolean, :numeric
72
+ # or :required (string). If you give a value, the type of the value is used.
73
+ #
74
+ def method_options(options=nil)
75
+ @method_options ||= {}
76
+ build_options(options, @method_options) if options
77
+ @method_options
78
+ end
79
+
80
+ # Adds an option to the set of method options. If :for is given as option,
81
+ # it allows you to change the options from a previous defined task.
82
+ #
83
+ # def previous_task
84
+ # # magic
85
+ # end
86
+ #
87
+ # method_option :foo => :bar, :for => :previous_task
88
+ #
89
+ # def next_task
90
+ # # magic
91
+ # end
92
+ #
93
+ # ==== Parameters
94
+ # name<Symbol>:: The name of the argument.
95
+ # options<Hash>:: Described below.
96
+ #
97
+ # ==== Options
98
+ # :desc - Description for the argument.
99
+ # :required - If the argument is required or not.
100
+ # :default - Default value for this argument. It cannot be required and have default values.
101
+ # :aliases - Aliases for this option.
102
+ # :type - The type of the argument, can be :string, :hash, :array, :numeric or :boolean.
103
+ # :banner - String to show on usage notes.
104
+ #
105
+ def method_option(name, options={})
106
+ scope = if options[:for]
107
+ find_and_refresh_task(options[:for]).options
108
+ else
109
+ method_options
110
+ end
111
+
112
+ build_option(name, options, scope)
113
+ end
114
+
115
+ # Parses the task and options from the given args, instantiate the class
116
+ # and invoke the task. This method is used when the arguments must be parsed
117
+ # from an array. If you are inside Ruby and want to use a Thor class, you
118
+ # can simply initialize it:
119
+ #
120
+ # script = MyScript.new(args, options, config)
121
+ # script.invoke(:task, first_arg, second_arg, third_arg)
122
+ #
123
+ def start(original_args=ARGV, config={})
124
+ super do |given_args|
125
+ meth = normalize_task_name(given_args.shift)
126
+ task = all_tasks[meth]
127
+
128
+ if task
129
+ args, opts = Thor::Options.split(given_args)
130
+ config.merge!(:task_options => task.options)
131
+ else
132
+ args, opts = given_args, {}
133
+ end
134
+
135
+ task ||= Thor::Task::Dynamic.new(meth)
136
+ trailing = args[Range.new(arguments.size, -1)]
137
+ new(args, opts, config).invoke(task, trailing || [])
138
+ end
139
+ end
140
+
141
+ # Prints help information for the given task.
142
+ #
143
+ # ==== Parameters
144
+ # shell<Thor::Shell>
145
+ # task_name<String>
146
+ #
147
+ def task_help(shell, task_name)
148
+ meth = normalize_task_name(task_name)
149
+ task = all_tasks[meth]
150
+ handle_no_task_error(meth) unless task
151
+
152
+ shell.say "Usage:"
153
+ shell.say " #{banner(task)}"
154
+ shell.say
155
+ class_options_help(shell, nil => task.options.map { |_, o| o })
156
+ shell.say task.description
157
+ end
158
+
159
+ # Prints help information for this class.
160
+ #
161
+ # ==== Parameters
162
+ # shell<Thor::Shell>
163
+ #
164
+ def help(shell)
165
+ list = printable_tasks
166
+ Thor::Util.thor_classes_in(self).each do |klass|
167
+ list += klass.printable_tasks(false)
168
+ end
169
+ list.sort!{ |a,b| a[0] <=> b[0] }
170
+
171
+ shell.say "Tasks:"
172
+ shell.print_table(list, :ident => 2, :truncate => true)
173
+ shell.say
174
+ class_options_help(shell)
175
+ end
176
+
177
+ # Returns tasks ready to be printed.
178
+ def printable_tasks(all=true)
179
+ (all ? all_tasks : tasks).map do |_, task|
180
+ item = []
181
+ item << banner(task)
182
+ item << (task.description ? "# #{task.description.gsub(/\s+/m,' ')}" : "")
183
+ item
184
+ end
185
+ end
186
+
187
+ def handle_argument_error(task, error) #:nodoc:
188
+ raise InvocationError, "#{task.name.inspect} was called incorrectly. Call as #{task.formatted_usage(self, banner_base == "thor").inspect}."
189
+ end
190
+
191
+ protected
192
+
193
+ # The banner for this class. You can customize it if you are invoking the
194
+ # thor class by another ways which is not the Thor::Runner. It receives
195
+ # the task that is going to be invoked and a boolean which indicates if
196
+ # the namespace should be displayed as arguments.
197
+ #
198
+ def banner(task)
199
+ "#{banner_base} #{task.formatted_usage(self, banner_base == "thor")}"
200
+ end
201
+
202
+ def baseclass #:nodoc:
203
+ Thor
204
+ end
205
+
206
+ def create_task(meth) #:nodoc:
207
+ if @usage && @desc
208
+ tasks[meth.to_s] = Thor::Task.new(meth, @desc, @usage, method_options)
209
+ @usage, @desc, @method_options = nil
210
+ true
211
+ elsif self.all_tasks[meth.to_s] || meth.to_sym == :method_missing
212
+ true
213
+ else
214
+ puts "[WARNING] Attempted to create task #{meth.inspect} without usage or description. " <<
215
+ "Call desc if you want this method to be available as task or declare it inside a " <<
216
+ "no_tasks{} block. Invoked from #{caller[1].inspect}."
217
+ false
218
+ end
219
+ end
220
+
221
+ def initialize_added #:nodoc:
222
+ class_options.merge!(method_options)
223
+ @method_options = nil
224
+ end
225
+
226
+ # Receives a task name (can be nil), and try to get a map from it.
227
+ # If a map can't be found use the sent name or the default task.
228
+ #
229
+ def normalize_task_name(meth) #:nodoc:
230
+ mapping = map[meth.to_s]
231
+ meth = mapping || meth || default_task
232
+ meth.to_s.gsub('-','_') # treat foo-bar > foo_bar
233
+ end
234
+ end
235
+
236
+ include Thor::Base
237
+
238
+ map HELP_MAPPINGS => :help
239
+
240
+ desc "help [TASK]", "Describe available tasks or one specific task"
241
+ def help(task=nil)
242
+ task ? self.class.task_help(shell, task) : self.class.help(shell)
243
+ end
244
+ end
@@ -0,0 +1,275 @@
1
+ require 'fileutils'
2
+ require 'thor/core_ext/file_binary_read'
3
+
4
+ Dir[File.join(File.dirname(__FILE__), "actions", "*.rb")].each do |action|
5
+ require action
6
+ end
7
+
8
+ class Thor
9
+ module Actions
10
+ attr_accessor :behavior
11
+
12
+ def self.included(base) #:nodoc:
13
+ base.extend ClassMethods
14
+ end
15
+
16
+ module ClassMethods
17
+ # Hold source paths for one Thor instance. source_paths_for_search is the
18
+ # method responsible to gather source_paths from this current class,
19
+ # inherited paths and the source root.
20
+ #
21
+ def source_paths
22
+ @source_paths ||= []
23
+ end
24
+
25
+ # Returns the source paths in the following order:
26
+ #
27
+ # 1) This class source paths
28
+ # 2) Source root
29
+ # 3) Parents source paths
30
+ #
31
+ def source_paths_for_search
32
+ paths = []
33
+ paths += self.source_paths
34
+ paths << self.source_root if self.respond_to?(:source_root)
35
+ paths += from_superclass(:source_paths, [])
36
+ paths
37
+ end
38
+
39
+ # Add runtime options that help actions execution.
40
+ #
41
+ def add_runtime_options!
42
+ class_option :force, :type => :boolean, :aliases => "-f", :group => :runtime,
43
+ :desc => "Overwrite files that already exist"
44
+
45
+ class_option :pretend, :type => :boolean, :aliases => "-p", :group => :runtime,
46
+ :desc => "Run but do not make any changes"
47
+
48
+ class_option :quiet, :type => :boolean, :aliases => "-q", :group => :runtime,
49
+ :desc => "Supress status output"
50
+
51
+ class_option :skip, :type => :boolean, :aliases => "-s", :group => :runtime,
52
+ :desc => "Skip files that already exist"
53
+ end
54
+ end
55
+
56
+ # Extends initializer to add more configuration options.
57
+ #
58
+ # ==== Configuration
59
+ # behavior<Symbol>:: The actions default behavior. Can be :invoke or :revoke.
60
+ # It also accepts :force, :skip and :pretend to set the behavior
61
+ # and the respective option.
62
+ #
63
+ # destination_root<String>:: The root directory needed for some actions.
64
+ #
65
+ def initialize(args=[], options={}, config={})
66
+ self.behavior = case config[:behavior].to_s
67
+ when "force", "skip"
68
+ _cleanup_options_and_set(options, config[:behavior])
69
+ :invoke
70
+ when "revoke"
71
+ :revoke
72
+ else
73
+ :invoke
74
+ end
75
+
76
+ super
77
+ self.destination_root = config[:destination_root]
78
+ end
79
+
80
+ # Wraps an action object and call it accordingly to the thor class behavior.
81
+ #
82
+ def action(instance) #:nodoc:
83
+ if behavior == :revoke
84
+ instance.revoke!
85
+ else
86
+ instance.invoke!
87
+ end
88
+ end
89
+
90
+ # Returns the root for this thor class (also aliased as destination root).
91
+ #
92
+ def destination_root
93
+ @destination_stack.last
94
+ end
95
+
96
+ # Sets the root for this thor class. Relatives path are added to the
97
+ # directory where the script was invoked and expanded.
98
+ #
99
+ def destination_root=(root)
100
+ @destination_stack ||= []
101
+ @destination_stack[0] = File.expand_path(root || '')
102
+ end
103
+
104
+ # Returns the given path relative to the absolute root (ie, root where
105
+ # the script started).
106
+ #
107
+ def relative_to_original_destination_root(path, remove_dot=true)
108
+ path = path.gsub(@destination_stack[0], '.')
109
+ remove_dot ? (path[2..-1] || '') : path
110
+ end
111
+
112
+ # Holds source paths in instance so they can be manipulated.
113
+ #
114
+ def source_paths
115
+ @source_paths ||= self.class.source_paths_for_search
116
+ end
117
+
118
+ # Receives a file or directory and search for it in the source paths.
119
+ #
120
+ def find_in_source_paths(file)
121
+ relative_root = relative_to_original_destination_root(destination_root, false)
122
+
123
+ source_paths.each do |source|
124
+ source_file = File.expand_path(file, File.join(source, relative_root))
125
+ return source_file if File.exists?(source_file)
126
+ end
127
+
128
+ if source_paths.empty?
129
+ raise Error, "You don't have any source path defined for class #{self.class.name}. To fix this, " <<
130
+ "you can define a source_root in your class."
131
+ else
132
+ raise Error, "Could not find #{file.inspect} in source paths."
133
+ end
134
+ end
135
+
136
+ # Do something in the root or on a provided subfolder. If a relative path
137
+ # is given it's referenced from the current root. The full path is yielded
138
+ # to the block you provide. The path is set back to the previous path when
139
+ # the method exits.
140
+ #
141
+ # ==== Parameters
142
+ # dir<String>:: the directory to move to.
143
+ # config<Hash>:: give :verbose => true to log and use padding.
144
+ #
145
+ def inside(dir='', config={}, &block)
146
+ verbose = config.fetch(:verbose, false)
147
+
148
+ say_status :inside, dir, verbose
149
+ shell.padding += 1 if verbose
150
+ @destination_stack.push File.expand_path(dir, destination_root)
151
+
152
+ FileUtils.mkdir_p(destination_root) unless File.exist?(destination_root)
153
+ FileUtils.cd(destination_root) { block.arity == 1 ? yield(destination_root) : yield }
154
+
155
+ @destination_stack.pop
156
+ shell.padding -= 1 if verbose
157
+ end
158
+
159
+ # Goes to the root and execute the given block.
160
+ #
161
+ def in_root
162
+ inside(@destination_stack.first) { yield }
163
+ end
164
+
165
+ # Loads an external file and execute it in the instance binding.
166
+ #
167
+ # ==== Parameters
168
+ # path<String>:: The path to the file to execute. Can be a web address or
169
+ # a relative path from the source root.
170
+ #
171
+ # ==== Examples
172
+ #
173
+ # apply "http://gist.github.com/103208"
174
+ #
175
+ # apply "recipes/jquery.rb"
176
+ #
177
+ def apply(path, config={})
178
+ verbose = config.fetch(:verbose, true)
179
+ path = find_in_source_paths(path) unless path =~ /^http\:\/\//
180
+
181
+ say_status :apply, path, verbose
182
+ shell.padding += 1 if verbose
183
+ instance_eval(open(path).read)
184
+ shell.padding -= 1 if verbose
185
+ end
186
+
187
+ # Executes a command returning the contents of the command.
188
+ #
189
+ # ==== Parameters
190
+ # command<String>:: the command to be executed.
191
+ # config<Hash>:: give :verbose => false to not log the status. Specify :with
192
+ # to append an executable to command executation.
193
+ #
194
+ # ==== Example
195
+ #
196
+ # inside('vendor') do
197
+ # run('ln -s ~/edge rails')
198
+ # end
199
+ #
200
+ def run(command, config={})
201
+ return unless behavior == :invoke
202
+
203
+ destination = relative_to_original_destination_root(destination_root, false)
204
+ desc = "#{command} from #{destination.inspect}"
205
+
206
+ if config[:with]
207
+ desc = "#{File.basename(config[:with].to_s)} #{desc}"
208
+ command = "#{config[:with]} #{command}"
209
+ end
210
+
211
+ say_status :run, desc, config.fetch(:verbose, true)
212
+ `#{command}` unless options[:pretend]
213
+ end
214
+
215
+ # Executes a ruby script (taking into account WIN32 platform quirks).
216
+ #
217
+ # ==== Parameters
218
+ # command<String>:: the command to be executed.
219
+ # config<Hash>:: give :verbose => false to not log the status.
220
+ #
221
+ def run_ruby_script(command, config={})
222
+ return unless behavior == :invoke
223
+ run command, config.merge(:with => Thor::Util.ruby_command)
224
+ end
225
+
226
+ # Run a thor command. A hash of options can be given and it's converted to
227
+ # switches.
228
+ #
229
+ # ==== Parameters
230
+ # task<String>:: the task to be invoked
231
+ # args<Array>:: arguments to the task
232
+ # config<Hash>:: give :verbose => false to not log the status. Other options
233
+ # are given as parameter to Thor.
234
+ #
235
+ # ==== Examples
236
+ #
237
+ # thor :install, "http://gist.github.com/103208"
238
+ # #=> thor install http://gist.github.com/103208
239
+ #
240
+ # thor :list, :all => true, :substring => 'rails'
241
+ # #=> thor list --all --substring=rails
242
+ #
243
+ def thor(task, *args)
244
+ config = args.last.is_a?(Hash) ? args.pop : {}
245
+ verbose = config.key?(:verbose) ? config.delete(:verbose) : true
246
+ pretend = config.key?(:pretend) ? config.delete(:pretend) : false
247
+
248
+ args.unshift task
249
+ args.push Thor::Options.to_switches(config)
250
+ command = args.join(' ').strip
251
+
252
+ run command, :with => :thor, :verbose => verbose, :pretend => pretend
253
+ end
254
+
255
+ protected
256
+
257
+ # Allow current root to be shared between invocations.
258
+ #
259
+ def _shared_configuration #:nodoc:
260
+ super.merge!(:destination_root => self.destination_root)
261
+ end
262
+
263
+ def _cleanup_options_and_set(options, key) #:nodoc:
264
+ case options
265
+ when Array
266
+ %w(--force -f --skip -s).each { |i| options.delete(i) }
267
+ options << "--#{key}"
268
+ when Hash
269
+ [:force, :skip, "force", "skip"].each { |i| options.delete(i) }
270
+ options.merge!(key => true)
271
+ end
272
+ end
273
+
274
+ end
275
+ end