Checkout of Instiki Trunk 1/21/2007.
This commit is contained in:
commit
69b62b6f33
1138 changed files with 139586 additions and 0 deletions
19
script/benchmarker
Executable file
19
script/benchmarker
Executable file
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
if ARGV.empty?
|
||||
puts "Usage: benchmarker times 'Person.expensive_way' 'Person.another_expensive_way' ..."
|
||||
exit
|
||||
end
|
||||
|
||||
require File.dirname(__FILE__) + '/../config/environment'
|
||||
require 'benchmark'
|
||||
include Benchmark
|
||||
|
||||
# Don't include compilation in the benchmark
|
||||
ARGV[1..-1].each { |expression| eval(expression) }
|
||||
|
||||
bm(6) do |x|
|
||||
ARGV[1..-1].each_with_index do |expression, idx|
|
||||
x.report("##{idx + 1}") { ARGV[0].to_i.times { eval(expression) } }
|
||||
end
|
||||
end
|
4
script/breakpointer
Executable file
4
script/breakpointer
Executable file
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/env ruby
|
||||
require 'rubygems'
|
||||
require_gem 'rails'
|
||||
require 'breakpoint_client'
|
23
script/console
Executable file
23
script/console
Executable file
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env ruby
|
||||
irb = RUBY_PLATFORM =~ /mswin32/ ? 'irb.bat' : 'irb'
|
||||
|
||||
require 'optparse'
|
||||
options = { :sandbox => false, :irb => irb }
|
||||
OptionParser.new do |opt|
|
||||
opt.on('-s', '--sandbox', 'Rollback database modifications on exit.') { |options[:sandbox]| }
|
||||
opt.on("--irb=[#{irb}]", 'Invoke a different irb.') { |options[:irb]| }
|
||||
opt.parse!(ARGV)
|
||||
end
|
||||
|
||||
libs = " -r irb/completion"
|
||||
libs << " -r #{File.dirname(__FILE__)}/../config/environment"
|
||||
libs << " -r console_sandbox" if options[:sandbox]
|
||||
|
||||
ENV['RAILS_ENV'] = ARGV.first || 'development'
|
||||
if options[:sandbox]
|
||||
puts "Loading #{ENV['RAILS_ENV']} environment in sandbox."
|
||||
puts "Any modifications you make will be rolled back on exit."
|
||||
else
|
||||
puts "Loading #{ENV['RAILS_ENV']} environment."
|
||||
end
|
||||
exec "#{options[:irb]} #{libs} --prompt-mode simple"
|
7
script/destroy
Executable file
7
script/destroy
Executable file
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/env ruby
|
||||
require File.dirname(__FILE__) + '/../config/environment'
|
||||
require 'rails_generator'
|
||||
require 'rails_generator/scripts/destroy'
|
||||
|
||||
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
||||
Rails::Generator::Scripts::Destroy.new.run(ARGV)
|
7
script/generate
Executable file
7
script/generate
Executable file
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/env ruby
|
||||
require File.dirname(__FILE__) + '/../config/environment'
|
||||
require 'rails_generator'
|
||||
require 'rails_generator/scripts/generate'
|
||||
|
||||
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
||||
Rails::Generator::Scripts::Generate.new.run(ARGV)
|
228
script/import_storage
Executable file
228
script/import_storage
Executable file
|
@ -0,0 +1,228 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'optparse'
|
||||
|
||||
OPTIONS = {
|
||||
:instiki_root => nil,
|
||||
:storage => nil,
|
||||
:database => 'mysql'
|
||||
}
|
||||
|
||||
ARGV.options do |opts|
|
||||
script_name = File.basename($0)
|
||||
opts.banner = "Usage: ruby #{script_name} [options]"
|
||||
|
||||
opts.separator ""
|
||||
|
||||
opts.on("-t", "--storage /full/path/to/storage", String,
|
||||
"Full path to your storage, ",
|
||||
"such as /home/joe/instiki/storage/2500",
|
||||
"It should be the directory that ",
|
||||
"contains .snapshot files.") do |storage|
|
||||
OPTIONS[:storage] = storage
|
||||
end
|
||||
|
||||
opts.separator ""
|
||||
|
||||
opts.on("-i", "--instiki /full/path/to/instiki", String,
|
||||
"Full path to your Instiki 0.10 installation, ",
|
||||
"such as /home/joe/instiki-0.10.2") do |instiki|
|
||||
OPTIONS[:instiki] = instiki
|
||||
end
|
||||
|
||||
opts.separator ""
|
||||
|
||||
opts.on("-o", "--outfile /full/path/to/output_file", String,
|
||||
"Full path (including filename!) to where ",
|
||||
"you want the SQL output placed, such as ",
|
||||
"/home/joe/instiki.sql") do |outfile|
|
||||
OPTIONS[:outfile] = outfile
|
||||
end
|
||||
|
||||
opts.on("-d", "--database {mysql|sqlite|postgres}", String,
|
||||
"Target database (they have slightly different syntax)",
|
||||
"default: mysql") do |database|
|
||||
OPTIONS[:database] = database
|
||||
end
|
||||
|
||||
opts.separator ""
|
||||
|
||||
opts.on_tail("-h", "--help",
|
||||
"Show this help message.") { puts opts; exit }
|
||||
|
||||
opts.parse!
|
||||
end
|
||||
|
||||
if OPTIONS[:instiki].nil? or OPTIONS[:storage].nil? or OPTIONS[:outfile].nil?
|
||||
$stderr.puts "Please specify full paths to Instiki 0.10 installation and storage,"
|
||||
$stderr.puts "as well as the path to the output file"
|
||||
$stderr.puts
|
||||
puts ARGV.options
|
||||
exit -1
|
||||
end
|
||||
|
||||
if FileTest.exists? OPTIONS[:outfile]
|
||||
$stderr.puts "Output file #{OPTIONS[:outfile]} already exists!"
|
||||
$stderr.puts "Please specify a new file"
|
||||
$stderr.puts
|
||||
puts ARGV.options
|
||||
exit -1
|
||||
end
|
||||
|
||||
raise "Directory #{OPTIONS[:instiki]} not found" unless File.directory?(OPTIONS[:instiki])
|
||||
raise "Directory #{OPTIONS[:storage]} not found" unless File.directory?(OPTIONS[:storage])
|
||||
|
||||
expected_page_rb_path = File.join(OPTIONS[:instiki], 'app/models/page.rb')
|
||||
raise "Instiki installation not found in #{OPTIONS[:instiki]}" unless File.file?(expected_page_rb_path)
|
||||
|
||||
expected_snapshot_pattern = File.join(OPTIONS[:storage], '*.snapshot')
|
||||
raise "No snapshots found in #{expected_snapshot_pattern}" if Dir[expected_snapshot_pattern].empty?
|
||||
|
||||
INSTIKI_ROOT = File.expand_path(OPTIONS[:instiki])
|
||||
|
||||
ADDITIONAL_LOAD_PATHS = %w(
|
||||
app/models
|
||||
lib
|
||||
vendor/madeleine-0.7.1/lib
|
||||
vendor/RedCloth-3.0.3/lib
|
||||
vendor/RedCloth-3.0.4/lib
|
||||
vendor/rubyzip-0.5.8/lib
|
||||
).map { |dir| "#{File.expand_path(File.join(INSTIKI_ROOT, dir))}"
|
||||
}.delete_if { |dir| not File.exist?(dir) }
|
||||
|
||||
# Prepend to $LOAD_PATH
|
||||
ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) }
|
||||
|
||||
require 'webrick'
|
||||
require 'wiki_service'
|
||||
|
||||
# substitute an extremely expensive method with something cheap.
|
||||
class Revision
|
||||
alias :__display_content :display_content
|
||||
def display_content
|
||||
return self
|
||||
end
|
||||
end
|
||||
|
||||
class Time
|
||||
def ansi
|
||||
strftime('%Y-%m-%d %H:%M:%S')
|
||||
end
|
||||
end
|
||||
|
||||
def sql_insert(table, hash)
|
||||
columns = hash.keys
|
||||
|
||||
values = columns.map { |column| hash[column] }
|
||||
values = values.map do |value|
|
||||
if value.nil?
|
||||
'NULL'
|
||||
else
|
||||
if (value == false or value == true) and OPTIONS[:database] == 'mysql'
|
||||
value = value ? '1' : '0'
|
||||
end
|
||||
|
||||
case OPTIONS[:database]
|
||||
when 'mysql', 'postgres'
|
||||
value = value.to_s.gsub("'", "\\\\'")
|
||||
when 'sqlite'
|
||||
value = value.to_s.gsub("'", "''")
|
||||
else
|
||||
raise "Unsupported database option #{OPTIONS[:database]}"
|
||||
end
|
||||
"'#{value.gsub("\r\n", "\n")}'"
|
||||
end
|
||||
end
|
||||
|
||||
output = "INSERT INTO #{table} ("
|
||||
output << columns.join(", ")
|
||||
|
||||
output << ") VALUES ("
|
||||
output << values.join(", ")
|
||||
output << ");"
|
||||
output
|
||||
end
|
||||
|
||||
def delete_all(outfile)
|
||||
%w(wiki_references revisions pages system webs).each { |table| outfile.puts "DELETE FROM #{table};" }
|
||||
end
|
||||
|
||||
def next_id(key)
|
||||
$ids ||= {}
|
||||
if $ids[key].nil?
|
||||
$ids[key] = 1
|
||||
else
|
||||
$ids[key] = $ids[key] + 1
|
||||
end
|
||||
$ids[key]
|
||||
end
|
||||
|
||||
def current_id(key)
|
||||
$ids[key] or raise "No curent ID for #{key.inspect}"
|
||||
end
|
||||
|
||||
WikiService.storage_path = OPTIONS[:storage]
|
||||
wiki = WikiService.instance
|
||||
|
||||
File.open(OPTIONS[:outfile], 'w') { |outfile|
|
||||
|
||||
outfile.puts "BEGIN;"
|
||||
delete_all(outfile)
|
||||
outfile.puts "COMMIT;"
|
||||
|
||||
wiki.webs.each_pair do |web_name, web|
|
||||
outfile.puts "BEGIN;"
|
||||
outfile.puts sql_insert(:webs, {
|
||||
:id => next_id(:web),
|
||||
:name => web.name,
|
||||
:address => web.address,
|
||||
:password => web.password,
|
||||
:additional_style => web.additional_style,
|
||||
:allow_uploads => web.allow_uploads,
|
||||
:published => web.published,
|
||||
:count_pages => web.count_pages,
|
||||
:markup => web.markup,
|
||||
:color => web.color,
|
||||
:max_upload_size => web.max_upload_size,
|
||||
:safe_mode => web.safe_mode,
|
||||
:brackets_only => web.brackets_only,
|
||||
:created_at => web.pages.values.map { |p| p.revisions.first.created_at }.min.ansi,
|
||||
:updated_at => web.pages.values.map { |p| p.revisions.last.created_at }.max.ansi
|
||||
})
|
||||
outfile.puts "COMMIT;"
|
||||
|
||||
puts "Web #{web_name} has #{web.pages.keys.size} pages"
|
||||
web.pages.each_pair do |page_name, page|
|
||||
|
||||
outfile.puts "BEGIN;"
|
||||
|
||||
outfile.puts sql_insert(:pages, {
|
||||
:id => next_id(:page),
|
||||
:web_id => current_id(:web),
|
||||
:locked_by => page.locked_by,
|
||||
:name => page.name,
|
||||
:created_at => page.revisions.first.created_at.ansi,
|
||||
:updated_at => page.revisions.last.created_at.ansi
|
||||
})
|
||||
|
||||
puts " Page #{page_name} has #{page.revisions.size} revisions"
|
||||
page.revisions.each_with_index do |rev, i|
|
||||
|
||||
outfile.puts sql_insert(:revisions, {
|
||||
:id => next_id(:revision),
|
||||
:page_id => current_id(:page),
|
||||
:content => rev.content,
|
||||
:author => rev.author.to_s,
|
||||
:ip => (rev.author.is_a?(Author) ? rev.author.ip : 'N/A'),
|
||||
:created_at => rev.created_at.ansi,
|
||||
:updated_at => rev.created_at.ansi,
|
||||
:revised_at => rev.created_at.ansi
|
||||
})
|
||||
puts " Revision #{i} created at #{rev.created_at.ansi}"
|
||||
end
|
||||
|
||||
outfile.puts "COMMIT;"
|
||||
|
||||
end
|
||||
end
|
||||
}
|
34
script/profiler
Executable file
34
script/profiler
Executable file
|
@ -0,0 +1,34 @@
|
|||
#!/usr/bin/env ruby
|
||||
if ARGV.empty?
|
||||
$stderr.puts "Usage: profiler 'Person.expensive_method(10)' [times]"
|
||||
exit(1)
|
||||
end
|
||||
|
||||
# Keep the expensive require out of the profile.
|
||||
$stderr.puts 'Loading Rails...'
|
||||
require File.dirname(__FILE__) + '/../config/environment'
|
||||
|
||||
# Define a method to profile.
|
||||
if ARGV[1] and ARGV[1].to_i > 1
|
||||
eval "def profile_me() #{ARGV[1]}.times { #{ARGV[0]} } end"
|
||||
else
|
||||
eval "def profile_me() #{ARGV[0]} end"
|
||||
end
|
||||
|
||||
# Use the ruby-prof extension if available. Fall back to stdlib profiler.
|
||||
begin
|
||||
require 'prof'
|
||||
$stderr.puts 'Using the ruby-prof extension.'
|
||||
Prof.clock_mode = Prof::GETTIMEOFDAY
|
||||
Prof.start
|
||||
profile_me
|
||||
results = Prof.stop
|
||||
require 'rubyprof_ext'
|
||||
Prof.print_profile(results, $stderr)
|
||||
rescue LoadError
|
||||
$stderr.puts 'Using the standard Ruby profiler.'
|
||||
Profiler__.start_profile
|
||||
profile_me
|
||||
Profiler__.stop_profile
|
||||
Profiler__.print_profile($stderr)
|
||||
end
|
28
script/reset_references
Executable file
28
script/reset_references
Executable file
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
ENV['RAILS_ENV'] = ARGV.first || 'development'
|
||||
|
||||
$stderr.puts "Loading Rails for #{ENV['RAILS_ENV']} environment..."
|
||||
require File.dirname(__FILE__) + '/../config/environment'
|
||||
|
||||
class StubUrlGenerator
|
||||
def make_link(*args)
|
||||
'StubLink'
|
||||
end
|
||||
end
|
||||
|
||||
PageRenderer.setup_url_generator(StubUrlGenerator.new)
|
||||
WikiReference.delete_all
|
||||
|
||||
Web.find_all.each do |web|
|
||||
web.pages.find(:all, :order => 'name').each do |page|
|
||||
$stderr.puts "Processing page '#{page.name}'"
|
||||
begin
|
||||
PageRenderer.new(page.current_revision).display_content(update_references = true)
|
||||
rescue => e
|
||||
puts e
|
||||
puts e.backtrace
|
||||
end
|
||||
end
|
||||
end
|
||||
|
29
script/runner
Executable file
29
script/runner
Executable file
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env ruby
|
||||
require 'optparse'
|
||||
|
||||
options = { :environment => "development" }
|
||||
|
||||
ARGV.options do |opts|
|
||||
script_name = File.basename($0)
|
||||
opts.banner = "Usage: runner 'puts Person.find(1).name' [options]"
|
||||
|
||||
opts.separator ""
|
||||
|
||||
opts.on("-e", "--environment=name", String,
|
||||
"Specifies the environment for the runner to operate under (test/development/production).",
|
||||
"Default: development") { |options[:environment]| }
|
||||
|
||||
opts.separator ""
|
||||
|
||||
opts.on("-h", "--help",
|
||||
"Show this help message.") { puts opts; exit }
|
||||
|
||||
opts.parse!
|
||||
end
|
||||
|
||||
ENV["RAILS_ENV"] = options[:environment]
|
||||
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
require File.dirname(__FILE__) + '/../config/environment'
|
||||
eval(ARGV.first)
|
49
script/server
Executable file
49
script/server
Executable file
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'webrick'
|
||||
require 'optparse'
|
||||
|
||||
OPTIONS = {
|
||||
:port => 2500,
|
||||
:ip => "0.0.0.0",
|
||||
:environment => "production",
|
||||
:server_root => File.expand_path(File.dirname(__FILE__) + "/../public/"),
|
||||
:server_type => WEBrick::SimpleServer
|
||||
}
|
||||
|
||||
ARGV.options do |opts|
|
||||
script_name = File.basename($0)
|
||||
opts.banner = "Usage: ruby #{script_name} [options]"
|
||||
|
||||
opts.separator ""
|
||||
|
||||
opts.on("-p", "--port=port", Integer,
|
||||
"Runs Instiki on the specified port.",
|
||||
"Default: 2500") { |OPTIONS[:port]| }
|
||||
opts.on("-b", "--binding=ip", String,
|
||||
"Binds Instiki to the specified ip.",
|
||||
"Default: 0.0.0.0") { |OPTIONS[:ip]| }
|
||||
opts.on("-e", "--environment=name", String,
|
||||
"Specifies the environment to run this server under (test/development/production).",
|
||||
"Default: development") { |OPTIONS[:environment]| }
|
||||
opts.on("-d", "--daemon",
|
||||
"Make Instiki run as a Daemon (only works if fork is available -- meaning on *nix)."
|
||||
) { OPTIONS[:server_type] = WEBrick::Daemon }
|
||||
|
||||
opts.separator ""
|
||||
|
||||
opts.on("-h", "--help",
|
||||
"Show this help message.") { puts opts; exit }
|
||||
|
||||
opts.parse!
|
||||
end
|
||||
|
||||
ENV["RAILS_ENV"] = OPTIONS[:environment]
|
||||
require File.dirname(__FILE__) + "/../config/environment"
|
||||
require 'webrick_server'
|
||||
|
||||
OPTIONS['working_directory'] = File.expand_path(RAILS_ROOT)
|
||||
|
||||
puts "=> Instiki started on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"
|
||||
puts "=> Ctrl-C to shutdown; call with --help for options" if OPTIONS[:server_type] == WEBrick::SimpleServer
|
||||
DispatchServlet.dispatch(OPTIONS)
|
Loading…
Add table
Add a link
Reference in a new issue