/
rails2_appengine.rb
72 lines (69 loc) · 2.71 KB
/
rails2_appengine.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/ruby
#
# Copyright:: Copyright 2009 Google Inc.
# Original Author:: John Woodell (mailto:woodie@google.com)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require 'fileutils'
def composite(source, fragment, index = nil)
File.open(source, 'r+') do |f|
lines = f.readlines
f.pos = 0
File.open(fragment) do |z|
section = z.readlines
if index and index.size < lines.size
f.print lines[0,index] + section + lines[index..-1]
else
f.print lines + section
end
end
f.truncate(f.pos)
end
FileUtils.rm fragment
end
MORE_GEMS = 'rails_appengine/active_support_vendored'
FILE_BASE = 'http://appengine-jruby.googlecode.com/hg/demos/rails2/'
MOD_FILES = %w{ app/controllers/rails/info_controller.rb
config.ru config/boot_rb config/environment_rb
config/initializers/gae_init_patch.rb config/database.yml
config/initializers/session_store_rb public/favicon.ico
script/console.sh script/publish.sh script/server.sh }
# Install Rails 2.3.5
FileUtils.touch 'config.ru'
gemsrc = ARGV[0].eql?('tiny_ds') ? 'Gemfile_td' : 'Gemfile'
system "curl -s -o Gemfile #{FILE_BASE}#{gemsrc}"
system 'appcfg.rb bundle --update .'
# Remove dups and generate Rails app
FileUtils.rm 'public/robots.txt'
system "appcfg.rb run -rthread -r#{MORE_GEMS} bin/rails ."
# Fetch configuration files
FileUtils.mkdir_p 'app/controllers/rails'
MOD_FILES.each { |path| system "curl -s -o #{path} #{FILE_BASE}#{path}" }
if ARGV[0].eql? 'tiny_ds'
system "curl -s -o config/environment_rb #{FILE_BASE}config/environment_td"
end
# Merge configs into boot.rb
composite('config/boot.rb', 'config/boot_rb', 108)
# Merge configs into environment.rb
composite('config/environment.rb', 'config/environment_rb', 30)
# Merge session_store initializer
composite('config/initializers/session_store.rb',
'config/initializers/session_store_rb')
# Set permissions on scripts
%w{console server}.each {|f| FileUtils.chmod 0644, "script/#{f}" }
%w{console server publish}.each {|f| FileUtils.chmod 0744, "script/#{f}.sh" }
# install the nulldb adapter
system 'ruby script/plugin install http://svn.avdi.org/nulldb/trunk/'
puts "##"
puts "## Now type 'dev_appserver.rb .'"
puts "##"