ramaze 2011.01.30 → 2011.07.25
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/.mailmap +2 -0
- data/.rvmrc +1 -0
- data/README.md +119 -197
- data/Rakefile +14 -97
- data/bin/ramaze +6 -14
- data/doc/AUTHORS +8 -4
- data/doc/CHANGELOG +3784 -3339
- data/examples/app/chat/start.rb +2 -2
- data/lib/proto/app.rb +2 -3
- data/lib/proto/config.ru +4 -5
- data/lib/proto/controller/init.rb +11 -4
- data/lib/proto/controller/main.rb +12 -7
- data/lib/proto/layout/default.xhtml +56 -23
- data/lib/proto/model/init.rb +3 -1
- data/lib/proto/public/css/grid.css +107 -0
- data/lib/proto/public/css/layout.css +81 -0
- data/lib/proto/public/css/reset.css +123 -0
- data/lib/proto/public/css/text.css +109 -0
- data/lib/proto/public/images/bg.png +0 -0
- data/lib/proto/spec/main.rb +2 -2
- data/lib/proto/start.rb +11 -1
- data/lib/proto/view/index.xhtml +27 -23
- data/lib/ramaze.rb +0 -1
- data/lib/ramaze/app.rb +85 -12
- data/lib/ramaze/app_graph.rb +107 -0
- data/lib/ramaze/bin/console.rb +87 -0
- data/lib/ramaze/bin/create.rb +94 -0
- data/lib/ramaze/bin/helper.rb +107 -0
- data/lib/ramaze/bin/restart.rb +95 -0
- data/lib/ramaze/bin/runner.rb +141 -0
- data/lib/ramaze/bin/start.rb +206 -0
- data/lib/ramaze/bin/status.rb +152 -0
- data/lib/ramaze/bin/stop.rb +112 -0
- data/lib/ramaze/cache.rb +9 -4
- data/lib/ramaze/cache/localmemcache.rb +10 -13
- data/lib/ramaze/cache/lru.rb +49 -7
- data/lib/ramaze/cache/memcache.rb +170 -92
- data/lib/ramaze/cache/sequel.rb +301 -118
- data/lib/ramaze/controller.rb +108 -9
- data/lib/ramaze/controller/default.rb +15 -2
- data/lib/ramaze/current.rb +14 -2
- data/lib/ramaze/dependencies.rb +46 -0
- data/lib/ramaze/files.rb +38 -3
- data/lib/ramaze/gestalt.rb +12 -12
- data/lib/ramaze/helper.rb +0 -2
- data/lib/ramaze/helper/auth.rb +30 -23
- data/lib/ramaze/helper/blue_form.rb +175 -126
- data/lib/ramaze/helper/csrf.rb +76 -91
- data/lib/ramaze/helper/email.rb +105 -0
- data/lib/ramaze/helper/erector.rb +16 -15
- data/lib/ramaze/helper/gestalt.rb +2 -2
- data/lib/ramaze/helper/layout.rb +89 -73
- data/lib/ramaze/helper/link.rb +7 -6
- data/lib/ramaze/helper/localize.rb +6 -5
- data/lib/ramaze/helper/markaby.rb +25 -23
- data/lib/ramaze/helper/maruku.rb +3 -3
- data/lib/ramaze/helper/paginate.rb +19 -27
- data/lib/ramaze/helper/remarkably.rb +3 -3
- data/lib/ramaze/helper/request_accessor.rb +3 -3
- data/lib/ramaze/helper/send_file.rb +12 -8
- data/lib/ramaze/helper/simple_captcha.rb +5 -6
- data/lib/ramaze/helper/stack.rb +7 -4
- data/lib/ramaze/helper/tagz.rb +10 -11
- data/lib/ramaze/helper/thread.rb +19 -16
- data/lib/ramaze/helper/ultraviolet.rb +7 -4
- data/lib/ramaze/helper/user.rb +40 -21
- data/lib/ramaze/helper/xhtml.rb +29 -20
- data/lib/ramaze/log.rb +3 -11
- data/lib/ramaze/log/analogger.rb +5 -4
- data/lib/ramaze/log/growl.rb +9 -7
- data/lib/ramaze/log/hub.rb +3 -5
- data/lib/ramaze/log/informer.rb +15 -12
- data/lib/ramaze/log/knotify.rb +3 -5
- data/lib/ramaze/log/logger.rb +3 -5
- data/lib/ramaze/log/logging.rb +6 -8
- data/lib/ramaze/log/rotatinginformer.rb +27 -17
- data/lib/ramaze/log/syslog.rb +7 -7
- data/lib/ramaze/log/xosd.rb +3 -5
- data/lib/ramaze/middleware_compiler.rb +27 -4
- data/lib/ramaze/reloader.rb +50 -12
- data/lib/ramaze/reloader/watch_inotify.rb +4 -5
- data/lib/ramaze/reloader/watch_stat.rb +3 -3
- data/lib/ramaze/request.rb +18 -8
- data/lib/ramaze/response.rb +38 -7
- data/lib/ramaze/rest.rb +36 -0
- data/lib/ramaze/setup.rb +101 -31
- data/lib/ramaze/spec.rb +1 -1
- data/lib/ramaze/spec/bacon.rb +6 -3
- data/lib/ramaze/spec/helper/bacon.rb +0 -1
- data/lib/ramaze/version.rb +1 -1
- data/lib/ramaze/view.rb +2 -11
- data/lib/ramaze/view/erector.rb +46 -31
- data/lib/ramaze/view/erubis.rb +7 -3
- data/lib/ramaze/view/ezamar.rb +7 -3
- data/lib/ramaze/view/gestalt.rb +9 -3
- data/lib/ramaze/view/haml.rb +7 -3
- data/lib/ramaze/view/liquid.rb +3 -3
- data/lib/ramaze/view/lokar.rb +7 -3
- data/lib/ramaze/view/mustache.rb +11 -5
- data/lib/ramaze/view/nagoro.rb +3 -3
- data/lib/ramaze/view/sass.rb +1 -1
- data/lib/ramaze/view/slippers.rb +40 -13
- data/lib/ramaze/view/tagz.rb +9 -5
- data/ramaze.gemspec +23 -128
- data/spec/helper.rb +5 -0
- data/spec/ramaze/bin/app/config.ru +11 -0
- data/spec/ramaze/bin/create.rb +28 -0
- data/spec/ramaze/bin/runner.rb +30 -0
- data/spec/ramaze/bin/start.rb +38 -0
- data/spec/ramaze/cache/memcache.rb +10 -3
- data/spec/ramaze/cache/sequel.rb +7 -0
- data/spec/ramaze/controller/provide_inheritance.rb +0 -10
- data/spec/ramaze/dispatcher/file.rb +19 -15
- data/spec/ramaze/helper/auth.rb +10 -9
- data/spec/ramaze/helper/blue_form.rb +121 -68
- data/spec/ramaze/helper/email.rb +69 -0
- data/spec/ramaze/helper/layout.rb +12 -15
- data/spec/ramaze/helper/layout/alternative.xhtml +5 -0
- data/spec/ramaze/helper/user.rb +2 -0
- data/spec/ramaze/log/growl.rb +14 -1
- data/spec/{contrib → ramaze}/rest.rb +1 -1
- data/spec/ramaze/session/memcache.rb +2 -2
- data/spec/ramaze/view/sass.rb +1 -1
- data/tasks/bacon.rake +3 -3
- data/tasks/gem.rake +17 -18
- data/tasks/rcov.rake +2 -3
- data/tasks/release.rake +8 -65
- data/tasks/setup.rake +10 -8
- data/tasks/todo.rake +9 -5
- data/tasks/yard.rake +3 -2
- metadata +105 -397
- data/MANIFEST +0 -532
- data/TODO.md +0 -19
- data/benchmark/bench_templates/bench.rb +0 -67
- data/benchmark/bench_templates/view/large.erb +0 -79
- data/benchmark/bench_templates/view/large.haml +0 -41
- data/benchmark/bench_templates/view/large.lok +0 -79
- data/benchmark/bench_templates/view/large.xhtml +0 -79
- data/benchmark/bench_templates/view/small.erb +0 -21
- data/benchmark/bench_templates/view/small.haml +0 -12
- data/benchmark/bench_templates/view/small.lok +0 -21
- data/benchmark/bench_templates/view/small.xhtml +0 -21
- data/benchmark/results.txt +0 -131
- data/benchmark/run.rb +0 -355
- data/benchmark/suite/minimal.rb +0 -11
- data/benchmark/suite/no_informer.rb +0 -7
- data/benchmark/suite/no_sessions.rb +0 -9
- data/benchmark/suite/no_template.rb +0 -7
- data/benchmark/suite/simple.rb +0 -5
- data/benchmark/suite/template_erubis.rb +0 -8
- data/benchmark/suite/template_etanni.rb +0 -8
- data/benchmark/suite/template_ezamar.rb +0 -8
- data/benchmark/suite/template_haml.rb +0 -13
- data/benchmark/suite/template_liquid.rb +0 -11
- data/benchmark/suite/template_markaby.rb +0 -9
- data/benchmark/suite/template_nagoro.rb +0 -8
- data/benchmark/suite/template_redcloth.rb +0 -13
- data/benchmark/suite/template_tenjin.rb +0 -8
- data/benchmark/test.rb +0 -35
- data/doc/FAQ +0 -92
- data/doc/INSTALL +0 -92
- data/doc/TODO +0 -29
- data/doc/meta/announcement.txt +0 -119
- data/doc/meta/configuration.txt +0 -163
- data/doc/meta/internals.txt +0 -278
- data/doc/meta/users.kml +0 -64
- data/doc/tutorial/todolist.html +0 -1512
- data/doc/tutorial/todolist.txt +0 -920
- data/examples/app/sourceview/public/coderay.css +0 -104
- data/examples/app/sourceview/public/images/file.gif +0 -0
- data/examples/app/sourceview/public/images/folder.gif +0 -0
- data/examples/app/sourceview/public/images/tv-collapsable-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-collapsable.gif +0 -0
- data/examples/app/sourceview/public/images/tv-expandable-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-expandable.gif +0 -0
- data/examples/app/sourceview/public/images/tv-item-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-item.gif +0 -0
- data/examples/app/sourceview/public/jquery.js +0 -11
- data/examples/app/sourceview/public/jquery.treeview.css +0 -48
- data/examples/app/sourceview/public/jquery.treeview.js +0 -223
- data/examples/app/sourceview/public/sourceview.js +0 -52
- data/examples/app/sourceview/start.rb +0 -79
- data/examples/app/sourceview/view/index.haml +0 -59
- data/examples/helpers/httpdigest.rb +0 -107
- data/lib/proto/public/css/screen.css +0 -30
- data/lib/proto/public/js/jquery.js +0 -7179
- data/lib/ramaze/contrib/addressable_route.rb +0 -56
- data/lib/ramaze/contrib/app_graph.rb +0 -64
- data/lib/ramaze/contrib/email.rb +0 -88
- data/lib/ramaze/contrib/facebook.rb +0 -23
- data/lib/ramaze/contrib/facebook/facebook.rb +0 -171
- data/lib/ramaze/contrib/gettext.rb +0 -113
- data/lib/ramaze/contrib/gettext/mo.rb +0 -155
- data/lib/ramaze/contrib/gettext/parser.rb +0 -46
- data/lib/ramaze/contrib/gettext/po.rb +0 -109
- data/lib/ramaze/contrib/gzip_filter.rb +0 -1
- data/lib/ramaze/contrib/maruku_uv.rb +0 -59
- data/lib/ramaze/contrib/profiling.rb +0 -36
- data/lib/ramaze/contrib/rest.rb +0 -23
- data/lib/ramaze/contrib/sequel/create_join.rb +0 -26
- data/lib/ramaze/contrib/sequel/form_field.rb +0 -129
- data/lib/ramaze/contrib/sequel/image.rb +0 -196
- data/lib/ramaze/contrib/sequel/relation.rb +0 -98
- data/lib/ramaze/helper/httpdigest.rb +0 -96
- data/lib/ramaze/tool/bin.rb +0 -340
- data/lib/ramaze/tool/create.rb +0 -48
- data/lib/ramaze/tool/project_creator.rb +0 -120
- data/lib/ramaze/view/less.rb +0 -12
- data/lib/ramaze/view/maruku.rb +0 -15
- data/lib/ramaze/view/redcloth.rb +0 -21
- data/spec/contrib/addressable_route.rb +0 -30
- data/spec/examples/helpers/httpdigest.rb +0 -64
- data/spec/examples/templates/template_redcloth.rb +0 -13
- data/spec/ramaze/bin/ramaze.rb +0 -96
- data/spec/ramaze/helper/httpdigest.rb +0 -176
- data/spec/ramaze/view/less.rb +0 -60
- data/spec/ramaze/view/less/file.css.less +0 -8
- data/spec/ramaze/view/redcloth.rb +0 -66
- data/spec/ramaze/view/redcloth/external.redcloth +0 -8
- data/tasks/copyright.rake +0 -21
- data/tasks/gem_setup.rake +0 -112
- data/tasks/git.rake +0 -46
- data/tasks/grancher.rake +0 -12
- data/tasks/jquery.rake +0 -15
- data/tasks/manifest.rake +0 -4
- data/tasks/metric_changes.rake +0 -24
- data/tasks/reversion.rake +0 -8
- data/tasks/traits.rake +0 -21
data/lib/ramaze/tool/bin.rb
DELETED
@@ -1,340 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
### This module offers the functionality to start, stop, restart, create,
|
3
|
-
### Check status, or run a console of a ramaze application
|
4
|
-
### see ramaze -h for usage
|
5
|
-
module Ramaze
|
6
|
-
module Tool
|
7
|
-
module Bin
|
8
|
-
module Helpers # Helper methods {{{
|
9
|
-
|
10
|
-
def default_pidfile # {{{
|
11
|
-
return @default_pidfile if @default_pidfile
|
12
|
-
require "pathname"
|
13
|
-
@default_pidfile = (Pathname.new(".").expand_path.basename.to_s + ".pid").strip
|
14
|
-
end # }}}
|
15
|
-
|
16
|
-
# We're really only concerned about win32ole, so we focus our check on its
|
17
|
-
# ability to load that
|
18
|
-
def is_windows? # {{{
|
19
|
-
return @is_win if @is_win
|
20
|
-
begin
|
21
|
-
require "win32ole"
|
22
|
-
rescue LoadError
|
23
|
-
end
|
24
|
-
@is_win ||= Object.const_defined?("WIN32OLE")
|
25
|
-
end # }}}
|
26
|
-
|
27
|
-
# Find the path to rackup, by searching for -R (undocumented cli argument),
|
28
|
-
# then checking RUBYLIB for the _first_ rack it can find there, finally
|
29
|
-
# falling back to gems and looking for rackup in the gem bindir.
|
30
|
-
# If we can't find rackup we're raising; not even #usage is sane without
|
31
|
-
# rackup.
|
32
|
-
def rackup_path # {{{
|
33
|
-
return @rackup_path if @rackup_path
|
34
|
-
# Use the supplied path if the user supplied -R
|
35
|
-
if path_supplied = ARGV.delete("-R")
|
36
|
-
@rackup_path = ARGV.delete(@ourargs[@ourargs.index("-R") + 1])
|
37
|
-
if @rackup_path and File.file?(@rackup_path)
|
38
|
-
return @rackup_path
|
39
|
-
else
|
40
|
-
$stderr.puts "rackup does not exist at #{@rackup_path} (given with -R)"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
# Check with 'which' on platforms which support it
|
44
|
-
unless is_windows?
|
45
|
-
@rackup_path = %x{which rackup}.to_s.chomp
|
46
|
-
if @rackup_path.size > 0 and File.file?(@rackup_path)
|
47
|
-
return @rackup_path
|
48
|
-
end
|
49
|
-
end
|
50
|
-
# check for rackup in RUBYLIB
|
51
|
-
libs = ENV["RUBYLIB"].to_s.split(is_windows? ? ";" : ":")
|
52
|
-
if rack_lib = libs.detect { |r| r.match %r<(\\|/)rack\1> }
|
53
|
-
require "pathname"
|
54
|
-
@rackup_path = Pathname.new(rack_lib).parent.join("bin").join("rackup").expand_path
|
55
|
-
return @rackup_path if File.file?(@rackup_path)
|
56
|
-
end
|
57
|
-
begin
|
58
|
-
require "rubygems"
|
59
|
-
require "rack"
|
60
|
-
require "pathname"
|
61
|
-
@rackup_path = Pathname.new(Gem.bindir).join("rackup").to_s
|
62
|
-
return @rackup_path if File.file?(@rackup_path)
|
63
|
-
rescue LoadError
|
64
|
-
nil
|
65
|
-
end
|
66
|
-
@rackup_path = nil
|
67
|
-
raise "Cannot find path to rackup, please supply full path to rackup with -R"
|
68
|
-
end # }}}
|
69
|
-
|
70
|
-
def is_running?(pid) # {{{
|
71
|
-
if is_windows?
|
72
|
-
wmi = WIN32OLE.connect("winmgmts://")
|
73
|
-
processes, ours = wmi.ExecQuery("select * from win32_process where ProcessId = #{pid}"), []
|
74
|
-
processes.each { |process| ours << process.Name }
|
75
|
-
ours.first.nil?
|
76
|
-
else
|
77
|
-
begin
|
78
|
-
prio = Process.getpriority(Process::PRIO_PROCESS, pid)
|
79
|
-
true
|
80
|
-
rescue Errno::ESRCH
|
81
|
-
false
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end # }}}
|
85
|
-
|
86
|
-
def check_running?(pid_file) # {{{
|
87
|
-
return false unless File.file?(pid_file)
|
88
|
-
is_running?(File.read(pid_file).to_i)
|
89
|
-
end # }}}
|
90
|
-
|
91
|
-
def find_pid(pid_file) # {{{
|
92
|
-
if pid_file.nil? or not File.file?(pid_file)
|
93
|
-
pid_file = default_pidfile
|
94
|
-
end
|
95
|
-
unless File.file?(pid_file)
|
96
|
-
$stderr.puts "Could not find running process id."
|
97
|
-
return false
|
98
|
-
end
|
99
|
-
pid_file
|
100
|
-
end # }}}
|
101
|
-
end # End helper methods }}}
|
102
|
-
|
103
|
-
class Cmd # This class contains the command methods {{{
|
104
|
-
include Helpers
|
105
|
-
attr_accessor :command
|
106
|
-
|
107
|
-
def initialize(args = nil)
|
108
|
-
args ||= ARGV
|
109
|
-
raise "arguments must be an array!" unless args.respond_to?(:detect)
|
110
|
-
@ourargs = args.dup
|
111
|
-
@command = args.detect { |arg| arg.match(/^(?:--?)?(?:start|stop|restart|create|h(?:elp)?|v(?:ersion)?|console|status)/) }
|
112
|
-
if command.nil?
|
113
|
-
@command = ""
|
114
|
-
else
|
115
|
-
args.delete(@command)
|
116
|
-
end
|
117
|
-
ARGV.replace(args)
|
118
|
-
end
|
119
|
-
|
120
|
-
# {{{ #run is called when we're interactive ($0 == __FILE__)
|
121
|
-
def self.run(args = nil)
|
122
|
-
cmd = new(args)
|
123
|
-
case cmd.command
|
124
|
-
when /^(?:--?)?status$/
|
125
|
-
cmd.status(cmd.command)
|
126
|
-
when /^(?:--?)?restart$/
|
127
|
-
cmd.stop(cmd.command)
|
128
|
-
cmd.start
|
129
|
-
when /^(?:--?)?start$/
|
130
|
-
cmd.start
|
131
|
-
when /^(?:--?)?create$/
|
132
|
-
cmd.create(cmd.command)
|
133
|
-
when /^(?:--?)?stop$/
|
134
|
-
if cmd.stop(cmd.command)
|
135
|
-
puts "Ramazement has ended, go in peace."
|
136
|
-
$stdout.flush
|
137
|
-
else
|
138
|
-
puts "Ramaze failed to stop (or was not running)"
|
139
|
-
end
|
140
|
-
when /^(?:--?)?console$/
|
141
|
-
require "ramaze"
|
142
|
-
require "irb"
|
143
|
-
require "irb/completion"
|
144
|
-
Ramaze.options.started = true
|
145
|
-
require "./start"
|
146
|
-
IRB.start
|
147
|
-
puts "Ramazement has ended, go in peace."
|
148
|
-
when /^(?:--?)?h(elp)?$/
|
149
|
-
puts cmd.usage
|
150
|
-
when /^(?:--?)?v(ersion)?$/
|
151
|
-
cmd.include_ramaze
|
152
|
-
puts Ramaze::VERSION
|
153
|
-
exit
|
154
|
-
when /^$/
|
155
|
-
puts "Must supply a valid command"
|
156
|
-
puts cmd.usage
|
157
|
-
exit 1
|
158
|
-
else
|
159
|
-
puts "#{command} not implemented"
|
160
|
-
puts cmd.usage
|
161
|
-
exit 1
|
162
|
-
end
|
163
|
-
end # }}}
|
164
|
-
|
165
|
-
def include_ramaze # {{{
|
166
|
-
begin
|
167
|
-
$:.unshift File.join(File.dirname(__FILE__), '/../lib')
|
168
|
-
require 'ramaze'
|
169
|
-
rescue LoadError
|
170
|
-
$:.shift
|
171
|
-
|
172
|
-
begin
|
173
|
-
require 'rubygems'
|
174
|
-
rescue LoadError
|
175
|
-
end
|
176
|
-
require 'ramaze'
|
177
|
-
end
|
178
|
-
end # }}}
|
179
|
-
|
180
|
-
def usage # {{{
|
181
|
-
txt = [
|
182
|
-
"\n Usage:",
|
183
|
-
"ramaze <start [PIDFILE]|stop [PIDFILE]|restart [PIDFILE]|status [PIDFILE]|create PROJECT|console> [ruby/rack options]\n",
|
184
|
-
"Commands:\n",
|
185
|
-
" * All commands which take an optional PIDFILE (defaults to PROJECT.pid otherwise).",
|
186
|
-
" * All commands which start a ramaze instance will default to webrick on port 7000",
|
187
|
-
" unless you supply the rack options -p/--port PORT and/or * -s/--server SERVER.\n",
|
188
|
-
" start - Starts an instance of this application.\n",
|
189
|
-
" stop - Stops a running instance of this application.\n",
|
190
|
-
" restart - Stops running instance of this application, then starts it back up. Pidfile",
|
191
|
-
" (if supplied) is used for both stop and start.\n",
|
192
|
-
" status - Gives status of a running ramaze instance\n",
|
193
|
-
" create - Creates a new prototype Ramaze application in a directory named PROJECT in",
|
194
|
-
" the current directory. ramaze create foo would make ./foo containing an",
|
195
|
-
" application prototype. Rack options are ignored here.\n",
|
196
|
-
" console - Starts an irb console with app.rb (and irb completion) loaded. This command",
|
197
|
-
" ignores rack options, ARGV is passed on to IRB.\n\n\t"
|
198
|
-
].join("\n\t")
|
199
|
-
|
200
|
-
if is_windows?
|
201
|
-
txt << %x{ruby #{rackup_path} --help}.split("\n").reject { |line| line.match(/^Usage:/) }.join("\n\t")
|
202
|
-
else
|
203
|
-
txt << %x{#{rackup_path} --help}.split("\n").reject { |line| line.match(/^Usage:/) }.join("\n\t")
|
204
|
-
end
|
205
|
-
|
206
|
-
txt.gsub(/^\t$/, '')
|
207
|
-
end # }}}
|
208
|
-
|
209
|
-
### Methods for commands {{{
|
210
|
-
def start # {{{
|
211
|
-
include_ramaze
|
212
|
-
|
213
|
-
# Find the name of this app
|
214
|
-
app_name = default_pidfile.sub(/\.pid$/,'')
|
215
|
-
rack_args = []
|
216
|
-
|
217
|
-
if daemonize = @ourargs.detect { |arg| arg.match(/^(-[dD]|--daemonize)$/) }
|
218
|
-
if pid_arg = @ourargs.detect { |arg| arg.match(/^(-P|--pid)/) }
|
219
|
-
puts "User supplied pid: #{pid_arg}"
|
220
|
-
pid_file = @ourargs[@ourargs.index(pid_arg) + 1]
|
221
|
-
puts "Starting daemon with user defined pidfile: #{pid_file}"
|
222
|
-
else
|
223
|
-
puts "Starting daemon with default pidfile: #{pid_file = default_pidfile}"
|
224
|
-
rack_args += ["-P", pid_file]
|
225
|
-
end
|
226
|
-
if check_running?(pid_file)
|
227
|
-
$stderr.puts "Ramaze is already running with pidfile: #{pid_file}"
|
228
|
-
exit 127
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
port = Ramaze.options.adapter.port.to_s
|
233
|
-
rack_args += ["-p", port ] if @ourargs.grep(/^(-p|--port)/).empty?
|
234
|
-
|
235
|
-
handler = Ramaze.options.adapter.handler.to_s
|
236
|
-
rack_args += ["-s", handler] if @ourargs.grep(/^(-s|--server)/).empty?
|
237
|
-
|
238
|
-
if is_windows?
|
239
|
-
exec("ruby", rackup_path.to_s, "config.ru", *(ARGV + rack_args))
|
240
|
-
else
|
241
|
-
exec(rackup_path.to_s, "config.ru", *(ARGV + rack_args))
|
242
|
-
end
|
243
|
-
end # }}}
|
244
|
-
|
245
|
-
def create(command) # {{{
|
246
|
-
opts = {}
|
247
|
-
if forced = @ourargs.detect { |arg| arg.match(/^(--force)/) }
|
248
|
-
puts "Overwriting any existing files as requested."
|
249
|
-
opts[:force] = true
|
250
|
-
@ourargs.delete(forced)
|
251
|
-
end
|
252
|
-
if amended = @ourargs.detect { |arg| arg.match(/^(--amend)/) }
|
253
|
-
puts "Only amending missing files as requested."
|
254
|
-
opts[:amend] = true
|
255
|
-
@ourargs.delete(amended)
|
256
|
-
end
|
257
|
-
project_name = @ourargs[@ourargs.index(command) + 1]
|
258
|
-
if project_name.nil?
|
259
|
-
$stderr.puts "Must supply a project name" if project_name.nil?
|
260
|
-
puts usage
|
261
|
-
exit 1
|
262
|
-
end
|
263
|
-
include_ramaze
|
264
|
-
require 'ramaze/tool/create'
|
265
|
-
Ramaze::Tool::Create.create(project_name, opts)
|
266
|
-
end # }}}
|
267
|
-
|
268
|
-
def stop(command) # {{{
|
269
|
-
unless pid_file = find_pid(@ourargs[@ourargs.index(command) + 1])
|
270
|
-
$stderr.puts "No pid_file found! Cannot stop ramaze (may not be started)."
|
271
|
-
return false
|
272
|
-
end
|
273
|
-
pid = File.read(pid_file).to_i
|
274
|
-
puts "Stopping pid #{pid}"
|
275
|
-
Process.kill("INT", pid)
|
276
|
-
sleep 2
|
277
|
-
if is_running?(pid)
|
278
|
-
$stderr.puts "Process #{pid} did not die, forcing it with -9"
|
279
|
-
Process.kill(9, pid)
|
280
|
-
File.unlink(pid_file) if File.file?(pid_file)
|
281
|
-
true
|
282
|
-
else
|
283
|
-
File.unlink(pid_file) if File.file?(pid_file)
|
284
|
-
true
|
285
|
-
end
|
286
|
-
end # }}}
|
287
|
-
|
288
|
-
def status(command) # {{{
|
289
|
-
unless pid_file = find_pid(@ourargs[@ourargs.index(command) + 1])
|
290
|
-
$stderr.puts "No pid_file found! Ramaze may not be started."
|
291
|
-
exit 1
|
292
|
-
end
|
293
|
-
puts "Pid file #{pid_file} found, PID is #{pid = File.read(pid_file)}"
|
294
|
-
unless is_running?(pid.to_i)
|
295
|
-
$stderr.puts "PID #{pid} is not running"
|
296
|
-
exit 1
|
297
|
-
end
|
298
|
-
if is_windows?
|
299
|
-
wmi = WIN32OLE.connect("winmgmts://")
|
300
|
-
processes, ours = wmi.ExecQuery("select * from win32_process where ProcessId = #{pid}"), []
|
301
|
-
processes.each { |p| ours << [p.Name, p.CommandLine, p.VirtualSize, p.CreationDate, p.ExecutablePath, p.Status ] }
|
302
|
-
puts "Ramaze is running!\n\tName: %s\n\tCommand Line: %s\n\tVirtual Size: %s\n\tStarted: %s\n\tExec Path: %s\n\tStatus: %s" % ours.first
|
303
|
-
else
|
304
|
-
require "pathname"
|
305
|
-
# Check for /proc
|
306
|
-
if File.directory?(proc_dir = Pathname.new("/proc"))
|
307
|
-
proc_dir = proc_dir.join(pid)
|
308
|
-
# If we have a "stat" file, we'll assume linux and get as much info
|
309
|
-
# as we can
|
310
|
-
if File.file?(stat_file = proc_dir.join("stat"))
|
311
|
-
stats = File.read(stat_file).split
|
312
|
-
puts "Ramaze is running!\n\tCommand Line: %s\n\tVirtual Size: %s\n\tStarted: %s\n\tExec Path: %s\n\tStatus: %s" % [
|
313
|
-
File.read(proc_dir.join("cmdline")).split("\000").join(" "),
|
314
|
-
"%s k" % (stats[22].to_f / 1024),
|
315
|
-
File.mtime(proc_dir),
|
316
|
-
File.readlink(proc_dir.join("exe")),
|
317
|
-
stats[2]
|
318
|
-
]
|
319
|
-
exit
|
320
|
-
end
|
321
|
-
end
|
322
|
-
# Fallthrough status, just print a ps
|
323
|
-
puts "Ramaze process #{pid} is running!"
|
324
|
-
begin
|
325
|
-
puts %x{ps l #{pid}}
|
326
|
-
rescue
|
327
|
-
puts "No further information available"
|
328
|
-
end
|
329
|
-
end
|
330
|
-
end # }}}
|
331
|
-
|
332
|
-
### End of command methods }}}
|
333
|
-
end # }}}
|
334
|
-
end
|
335
|
-
end
|
336
|
-
end
|
337
|
-
|
338
|
-
if $0 == __FILE__
|
339
|
-
Ramaze::Tool::Bin::Cmd.run(ARGV)
|
340
|
-
end
|
data/lib/ramaze/tool/create.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
|
2
|
-
# All files in this distribution are subject to the terms of the Ruby license.
|
3
|
-
|
4
|
-
require 'ramaze/tool/project_creator'
|
5
|
-
|
6
|
-
module Ramaze
|
7
|
-
module Tool
|
8
|
-
|
9
|
-
# Create is a simple class used to create new projects based on the proto
|
10
|
-
# directory.
|
11
|
-
#
|
12
|
-
# It is primarly used for this command:
|
13
|
-
#
|
14
|
-
# ramaze --create project
|
15
|
-
#
|
16
|
-
# where project is the directory you want the content put into.
|
17
|
-
|
18
|
-
class Create
|
19
|
-
|
20
|
-
# Default options passed to Create::create
|
21
|
-
# :proto is the directory to duplicate
|
22
|
-
# :amend no files may be overwritten but missing files will be added
|
23
|
-
# :force will overwrite existing files
|
24
|
-
# :layout copy one subdirectory in +proto+
|
25
|
-
|
26
|
-
DEFAULT = {
|
27
|
-
:proto => File.join(ROOT, 'proto'),
|
28
|
-
:amend => false,
|
29
|
-
:force => false,
|
30
|
-
:layout => '/',
|
31
|
-
}
|
32
|
-
|
33
|
-
# Using ProjectCreator to copy all files and directories from lib/proto
|
34
|
-
# to another location.
|
35
|
-
# +options+ are described in the DEFAULT constant and should be:
|
36
|
-
# :force => (true|false|nil)
|
37
|
-
# :amend => (true|false|nil)
|
38
|
-
# :layout => (String|nil)
|
39
|
-
# :proto => String
|
40
|
-
|
41
|
-
def self.create(project, options = {})
|
42
|
-
options = DEFAULT.merge(options)
|
43
|
-
creator = ProjectCreator.new(project, options)
|
44
|
-
creator.create
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,120 +0,0 @@
|
|
1
|
-
# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
|
2
|
-
# All files in this distribution are subject to the terms of the Ruby license.
|
3
|
-
|
4
|
-
require 'fileutils'
|
5
|
-
require 'find'
|
6
|
-
|
7
|
-
class ProjectCreator
|
8
|
-
PROTO = []
|
9
|
-
PROTO << '~/.proto/' if ENV["HOME"] # Guard against Windows
|
10
|
-
attr_accessor :name, :options
|
11
|
-
|
12
|
-
def initialize(name, options = {})
|
13
|
-
@name, @options = name, options
|
14
|
-
end
|
15
|
-
|
16
|
-
def target
|
17
|
-
File.expand_path(name)
|
18
|
-
end
|
19
|
-
|
20
|
-
def proto
|
21
|
-
PROTO.map!{|pr| File.expand_path(pr) }
|
22
|
-
proto = options[:proto] ||= PROTO.find{|f| File.directory?(f) }
|
23
|
-
layout = options[:layout] ||= '/'
|
24
|
-
File.expand_path(File.join(proto, layout))
|
25
|
-
end
|
26
|
-
|
27
|
-
def create_root?
|
28
|
-
return true unless File.directory?(target)
|
29
|
-
return true if amend? or force?
|
30
|
-
fatal "%p is a directory, choose different project name or use --amend/--force" % target
|
31
|
-
end
|
32
|
-
|
33
|
-
def got_proto?
|
34
|
-
return true if File.directory?(proto)
|
35
|
-
fatal "Cannot create, %p doesn't exist, use --proto or create the proto directory" % proto
|
36
|
-
end
|
37
|
-
|
38
|
-
def create
|
39
|
-
got_proto?
|
40
|
-
|
41
|
-
puts "Found proto at: %p, proceeding...\n\n" % proto
|
42
|
-
mkdir(relate('/')) if create_root?
|
43
|
-
proceed
|
44
|
-
end
|
45
|
-
|
46
|
-
def proceed
|
47
|
-
files, directories = partition{|path| File.file?(path) }
|
48
|
-
proceed_directories(directories)
|
49
|
-
proceed_files(files)
|
50
|
-
end
|
51
|
-
|
52
|
-
def proceed_files(files)
|
53
|
-
files.each{|file| copy(file, relate(file)) }
|
54
|
-
end
|
55
|
-
|
56
|
-
def proceed_directories(dirs)
|
57
|
-
dirs.each{|dir| mkdir(relate(dir)) }
|
58
|
-
end
|
59
|
-
|
60
|
-
def mkdir(dir)
|
61
|
-
return unless mkdir?(dir)
|
62
|
-
|
63
|
-
relate = dir.sub("#{target}/", '')
|
64
|
-
puts "%12s %s" % ['mkdir', relate]
|
65
|
-
|
66
|
-
FileUtils.mkdir_p(dir)
|
67
|
-
end
|
68
|
-
|
69
|
-
def mkdir?(dir)
|
70
|
-
exists = File.directory?(dir)
|
71
|
-
|
72
|
-
!exists && amend? or exists && force? or !exists
|
73
|
-
end
|
74
|
-
|
75
|
-
def copy(from, to)
|
76
|
-
return unless copy?(to)
|
77
|
-
|
78
|
-
relate = to.sub("#{target}/", '')
|
79
|
-
puts "%12s %s" % ['create', relate]
|
80
|
-
|
81
|
-
FileUtils.cp(from, to, :preserve => true)
|
82
|
-
post_process(to)
|
83
|
-
end
|
84
|
-
|
85
|
-
def copy?(file)
|
86
|
-
exists = File.file?(file)
|
87
|
-
|
88
|
-
!exists && amend? or exists && force? or !exists
|
89
|
-
end
|
90
|
-
|
91
|
-
# Think about a useful way to process the generated files it should be
|
92
|
-
# possible to substitute some things like the project name in the
|
93
|
-
# configuration
|
94
|
-
|
95
|
-
def post_process(file)
|
96
|
-
return
|
97
|
-
source = File.read(file)
|
98
|
-
File.open(file, 'w+') do |io|
|
99
|
-
io.write(source.gsub('$project', "'#@name'"))
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def relate(path)
|
104
|
-
File.join(target, path.to_s.sub(proto, ''))
|
105
|
-
end
|
106
|
-
|
107
|
-
def amend?; options[:amend] end
|
108
|
-
def force?; options[:force] end
|
109
|
-
|
110
|
-
def fatal(message)
|
111
|
-
warn message
|
112
|
-
exit 1
|
113
|
-
end
|
114
|
-
|
115
|
-
def each
|
116
|
-
Dir.glob("#{proto}/**/*", File::FNM_DOTMATCH).each{|path| yield(path) }
|
117
|
-
end
|
118
|
-
|
119
|
-
include Enumerable
|
120
|
-
end
|