Set a couple of props on script/import_storage to prepare for the next

checkin...
This commit is contained in:
Ben Bleything 2005-08-22 16:50:38 +00:00
parent e5b7037259
commit 0238780355

188
script/import_storage Normal file → Executable file
View file

@ -1,94 +1,94 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
require 'optparse' require 'optparse'
OPTIONS = { OPTIONS = {
:instiki_root => nil, :instiki_root => nil,
:storage => nil, :storage => nil,
} }
ARGV.options do |opts| ARGV.options do |opts|
script_name = File.basename($0) script_name = File.basename($0)
opts.banner = "Usage: ruby #{script_name} [options]" opts.banner = "Usage: ruby #{script_name} [options]"
opts.separator "" opts.separator ""
opts.on("-t", "--storage /full/path/to/storage", String, opts.on("-t", "--storage /full/path/to/storage", String,
"Full path to your storage, ", "Full path to your storage, ",
"such as /home/joe/instiki/storage/2500", "such as /home/joe/instiki/storage/2500",
"It should be the directory that ", "It should be the directory that ",
"contains .snapshot files.") do |storage| "contains .snapshot files.") do |storage|
OPTIONS[:storage] = storage OPTIONS[:storage] = storage
end end
opts.separator "" opts.separator ""
opts.on("-i", "--instiki /full/path/to/instiki", String, opts.on("-i", "--instiki /full/path/to/instiki", String,
"Full path to your Instiki installation, ", "Full path to your Instiki installation, ",
"such as /home/joe/instiki") do |instiki| "such as /home/joe/instiki") do |instiki|
OPTIONS[:instiki] = instiki OPTIONS[:instiki] = instiki
end end
opts.separator "" opts.separator ""
opts.on_tail("-h", "--help", opts.on_tail("-h", "--help",
"Show this help message.") { puts opts; exit } "Show this help message.") { puts opts; exit }
opts.parse! opts.parse!
end end
if OPTIONS[:instiki].nil? or OPTIONS[:storage].nil? if OPTIONS[:instiki].nil? or OPTIONS[:storage].nil?
$stderr.puts "Please specify full paths to Instiki installation and storage" $stderr.puts "Please specify full paths to Instiki installation and storage"
$stderr.puts $stderr.puts
puts ARGV.options puts ARGV.options
exit -1 exit -1
end end
raise "Directory #{OPTIONS[:instiki]} not found" unless File.directory?(OPTIONS[:instiki]) raise "Directory #{OPTIONS[:instiki]} not found" unless File.directory?(OPTIONS[:instiki])
raise "Directory #{OPTIONS[:storage]} not found" unless File.directory?(OPTIONS[:storage]) raise "Directory #{OPTIONS[:storage]} not found" unless File.directory?(OPTIONS[:storage])
expected_page_rb_path = File.join(OPTIONS[:instiki], 'app/models/page.rb') 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) raise "Instiki installation not found in #{OPTIONS[:instiki]}" unless File.file?(expected_page_rb_path)
expected_snapshot_pattern = File.join(OPTIONS[:storage], '*.snapshot') expected_snapshot_pattern = File.join(OPTIONS[:storage], '*.snapshot')
raise "No snapshots found in OPTIONS[:storage]" if Dir[expected_snapshot_pattern].empty? raise "No snapshots found in OPTIONS[:storage]" if Dir[expected_snapshot_pattern].empty?
INSTIKI_ROOT = File.expand_path(OPTIONS[:instiki]) INSTIKI_ROOT = File.expand_path(OPTIONS[:instiki])
ADDITIONAL_LOAD_PATHS = %w( ADDITIONAL_LOAD_PATHS = %w(
app/models app/models
lib lib
vendor/madeleine-0.7.1/lib vendor/madeleine-0.7.1/lib
vendor/RedCloth-3.0.3/lib vendor/RedCloth-3.0.3/lib
vendor/rubyzip-0.5.8/lib vendor/rubyzip-0.5.8/lib
).map { |dir| "#{File.expand_path(File.join(INSTIKI_ROOT, dir))}" ).map { |dir| "#{File.expand_path(File.join(INSTIKI_ROOT, dir))}"
}.delete_if { |dir| not File.exist?(dir) } }.delete_if { |dir| not File.exist?(dir) }
# Prepend to $LOAD_PATH # Prepend to $LOAD_PATH
ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) } ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) }
require 'webrick' require 'webrick'
require 'wiki_service' require 'wiki_service'
class Revision class Revision
alias :__display_content :display_content alias :__display_content :display_content
def display_content def display_content
return self return self
end end
end end
WikiService.storage_path = OPTIONS[:storage] WikiService.storage_path = OPTIONS[:storage]
wiki = WikiService.instance wiki = WikiService.instance
wiki.webs.each_pair do |web_name, web| wiki.webs.each_pair do |web_name, web|
# INSERT INTO webs goes here # INSERT INTO webs goes here
puts "Web #{web_name} has #{web.pages.keys.size} pages" puts "Web #{web_name} has #{web.pages.keys.size} pages"
web.pages.each_pair do |page_name, page| web.pages.each_pair do |page_name, page|
# INSERT INTO pages goes here # INSERT INTO pages goes here
puts " Page #{page_name} has #{page.revisions.size} revisions" puts " Page #{page_name} has #{page.revisions.size} revisions"
page.revisions.each_with_index do |rev, i| page.revisions.each_with_index do |rev, i|
# INSERT INTO revisions goes here # INSERT INTO revisions goes here
puts " Revision #{i} created at #{rev.created_at}" puts " Revision #{i} created at #{rev.created_at}"
end end
end end
end end