thin 0.3.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of thin might be problematic. Click here for more details.

@@ -0,0 +1,9 @@
1
+ module Thin
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 3
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,247 @@
1
+ # Original copy of this file taken from Piston
2
+ # Copyright (c) 2006 Francois Beausoleil <francois@teksol.info>
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+
22
+ require "optparse"
23
+
24
+ module Transat
25
+ class VersionNeeded < StandardError; end
26
+
27
+ class HelpNeeded < StandardError
28
+ attr_reader :command
29
+
30
+ def initialize(command)
31
+ @command = command
32
+ end
33
+ end
34
+
35
+ class NoCommandGiven < StandardError
36
+ def message
37
+ "No command given"
38
+ end
39
+ end
40
+
41
+ class UnknownOptions < StandardError
42
+ attr_reader :command
43
+
44
+ def initialize(command, unrecognized_options)
45
+ @command, @unrecognized_options = command, unrecognized_options
46
+ end
47
+
48
+ def message
49
+ "Command #{@command} does not accept options #{@unrecognized_options.join(", ")}"
50
+ end
51
+ end
52
+
53
+ class UnknownCommand < StandardError
54
+ def initialize(command, parser)
55
+ @command, @parser = command, parser
56
+ end
57
+
58
+ def message
59
+ "Unknown command: #{@command.inspect}"
60
+ end
61
+ end
62
+
63
+ class BaseCommand
64
+ attr_reader :non_options, :options
65
+ def initialize(non_options, options)
66
+ @non_options, @options = non_options, options
67
+ end
68
+ end
69
+
70
+ class VersionCommand < BaseCommand
71
+ def run
72
+ raise VersionNeeded
73
+ end
74
+ end
75
+
76
+ class HelpCommand < BaseCommand
77
+ def run
78
+ raise HelpNeeded.new(non_options.first)
79
+ end
80
+ end
81
+
82
+ class Parser
83
+ def initialize(&block)
84
+ @valid_options, @received_options, @commands = [], {}, {}
85
+ @option_parser = OptionParser.new
86
+
87
+ command(:help, Transat::HelpCommand)
88
+ command(:version, Transat::VersionCommand)
89
+ instance_eval(&block) if block_given?
90
+ end
91
+
92
+ def option(name, options={})
93
+ options[:long] = name.to_s.gsub("_", "-") unless options[:long]
94
+ @valid_options << name
95
+ @received_options[name] = nil
96
+
97
+ opt_args = []
98
+ opt_args << "-#{options[:short]}" if options.has_key?(:short)
99
+ opt_args << "--#{options[:long] || name}"
100
+ opt_args << "=#{options[:param_name]}" if options.has_key?(:param_name)
101
+ opt_args << options[:message]
102
+ case options[:type]
103
+ when :int, :integer
104
+ opt_args << Integer
105
+ when :float
106
+ opt_args << Float
107
+ when nil
108
+ # NOP
109
+ else
110
+ raise ArgumentError, "Option #{name} has a bad :type parameter: #{options[:type].inspect}"
111
+ end
112
+
113
+ if options.has_key?(:default)
114
+ opt_args << "(default: #{options[:default]})"
115
+ @received_options[name] = options[:default]
116
+ end
117
+
118
+ @option_parser.on(*opt_args.compact) do |value|
119
+ @received_options[name] = value
120
+ end
121
+
122
+ @option_parser.on_tail('-h', '--help') do
123
+ raise HelpNeeded, nil
124
+ end
125
+
126
+ @option_parser.on_tail('-v', '--version') do
127
+ raise VersionNeeded
128
+ end
129
+ end
130
+
131
+ def command(name, klass, options={})
132
+ @commands[name.to_s] = options.merge(:class => klass)
133
+ end
134
+
135
+ def help(message)
136
+ @help = message
137
+ end
138
+
139
+ def parse_and_execute(args=ARGV)
140
+ begin
141
+ command, non_options = parse(args)
142
+ execute(command, non_options)
143
+ rescue HelpNeeded
144
+ $stderr.puts usage($!.command)
145
+ exit 1
146
+ rescue VersionNeeded
147
+ puts "#{program_name} #{version}"
148
+ exit 0
149
+ rescue NoCommandGiven, UnknownOptions, UnknownCommand
150
+ $stderr.puts "Error: #{$!.message}"
151
+ $stderr.puts usage($!.respond_to?(:command) ? $!.command : nil)
152
+ exit 1
153
+ end
154
+ end
155
+
156
+ def parse(args)
157
+ non_options = @option_parser.parse(args)
158
+ command = non_options.shift
159
+ raise NoCommandGiven unless command
160
+ return command, non_options
161
+ end
162
+
163
+ def execute(command, non_options)
164
+ @commands.each do |command_name, options|
165
+ command_klass = options[:class]
166
+
167
+ aliases = [command_name]
168
+ aliases += command_klass.aliases if command_klass.respond_to?(:aliases)
169
+
170
+ valid_options = {}
171
+ @received_options.each_pair do |name, value|
172
+ valid_options[name] = value if options[:valid_options].include?(name)
173
+ end if options[:valid_options]
174
+
175
+ return command_klass.new(non_options, valid_options).run if aliases.include?(command)
176
+ end
177
+
178
+ raise UnknownCommand.new(command, self)
179
+ end
180
+
181
+ def usage(command=nil)
182
+ message = []
183
+
184
+ if command then
185
+ command_klass = @commands[command][:class]
186
+ help =
187
+ if command_klass.respond_to?(:aliases) then
188
+ "#{command} (#{command_klass.aliases.join(", ")})"
189
+ else
190
+ "#{command}"
191
+ end
192
+ help = "#{help}: #{command_klass.help}" if command_klass.respond_to?(:help)
193
+ message << help
194
+ message << command_klass.detailed_help if command_klass.respond_to?(:detailed_help)
195
+ message << ""
196
+ message << "Valid options:"
197
+ command_options_summary(@commands[command], message)
198
+ else
199
+ message << "usage: #{program_name.downcase} <command> [options] [args...]"
200
+ message << "Type '#{program_name.downcase} help <command>' for help on a specific command."
201
+ message << "Type '#{program_name.downcase} version' to get this program's version."
202
+ message << ""
203
+ message << "Available commands are:"
204
+ @commands.sort.each do |command, options|
205
+ command_klass = options[:class]
206
+ if command_klass.respond_to?(:aliases) then
207
+ message << " #{command} (#{command_klass.aliases.join(", ")})"
208
+ else
209
+ message << " #{command}"
210
+ end
211
+ end
212
+ if @help
213
+ message << ""
214
+ message << @help
215
+ end
216
+ end
217
+
218
+ message.map {|line| line.chomp}.join("\n")
219
+ end
220
+
221
+ def command_options_summary(command, message=[])
222
+ valid_options = (command[:valid_options] || []).collect { |opt| "--#{opt.to_s.tr('_', '-')}" }
223
+ @option_parser.top.list.each do |opt|
224
+ opt.summarize({}, {}, @option_parser.summary_width, @option_parser.summary_width - 1, @option_parser.summary_indent) do |line|
225
+ message << line
226
+ end if valid_options.include?(opt.long.to_s)
227
+ end
228
+ message
229
+ end
230
+
231
+ def program_name(value=nil)
232
+ value ? @program_name = value : @program_name
233
+ end
234
+
235
+ def version(value=nil)
236
+ if value then
237
+ @version = value.respond_to?(:join) ? value.join(".") : value
238
+ else
239
+ @version
240
+ end
241
+ end
242
+
243
+ def self.parse_and_execute(args=ARGV, &block)
244
+ self.new(&block).parse_and_execute(args)
245
+ end
246
+ end
247
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: thin
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.3.0
7
+ date: 2007-12-03 00:00:00 -05:00
8
+ summary: Thin and fast web server
9
+ require_paths:
10
+ - lib
11
+ email: macournoyer@gmail.com
12
+ homepage: http://code.macournoyer.com/thin/
13
+ rubyforge_project:
14
+ description: Thin and fast web server
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: false
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.8.6
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Marc-Andre Cournoyer
31
+ files:
32
+ - README
33
+ - Rakefile
34
+ - bin/thin
35
+ - bin/thin_cluster
36
+ - doc/benchmarks.txt
37
+ - lib/thin
38
+ - lib/thin/cgi.rb
39
+ - lib/thin/cluster.rb
40
+ - lib/thin/command.rb
41
+ - lib/thin/commands
42
+ - lib/thin/commands/cluster
43
+ - lib/thin/commands/cluster/base.rb
44
+ - lib/thin/commands/cluster/config.rb
45
+ - lib/thin/commands/cluster/restart.rb
46
+ - lib/thin/commands/cluster/start.rb
47
+ - lib/thin/commands/cluster/stop.rb
48
+ - lib/thin/commands/server
49
+ - lib/thin/commands/server/base.rb
50
+ - lib/thin/commands/server/start.rb
51
+ - lib/thin/commands/server/stop.rb
52
+ - lib/thin/consts.rb
53
+ - lib/thin/daemonizing.rb
54
+ - lib/thin/handler.rb
55
+ - lib/thin/headers.rb
56
+ - lib/thin/logging.rb
57
+ - lib/thin/mime_types.rb
58
+ - lib/thin/rails.rb
59
+ - lib/thin/recipes.rb
60
+ - lib/thin/request.rb
61
+ - lib/thin/response.rb
62
+ - lib/thin/server.rb
63
+ - lib/thin/statuses.rb
64
+ - lib/thin/version.rb
65
+ - lib/thin.rb
66
+ - lib/transat
67
+ - lib/transat/parser.rb
68
+ test_files: []
69
+
70
+ rdoc_options: []
71
+
72
+ extra_rdoc_files: []
73
+
74
+ executables:
75
+ - thin
76
+ - thin_cluster
77
+ extensions: []
78
+
79
+ requirements: []
80
+
81
+ dependencies: []
82
+