| 2e33be3 by Johan Sørensen at 2009-01-13 | 1 | #!/usr/bin/env ruby -KU |
| 2 | ||
| 3 | ENV["PATH"] = "/usr/local/bin/:/opt/local/bin:#{ENV["PATH"]}" |
|
| 4 | ENV["RAILS_ENV"] ||= "production" |
|
| 5 | require File.dirname(__FILE__) + "/../config/environment" |
|
| 6 | ||
| 7 | action = ARGV[0] |
|
| 8 | ||
| 9cd746d by Johan Sørensen at 2009-01-15 | 9 | abort("Need create_repos or load_readmes command") unless action |
| 10 | ||
| 11 | def failure_msg(msg) |
|
| 12 | $stderr.puts "\e[1;31m#{msg}\e[0m" |
|
| 13 | end |
|
| 2e33be3 by Johan Sørensen at 2009-01-13 | 14 | |
| 9cd746d by Johan Sørensen at 2009-01-15 | 15 | project_count = Project.count |
| 16 | Project.find(:all).each_with_index do |project, index| |
|
| 2e33be3 by Johan Sørensen at 2009-01-13 | 17 | case action |
| 9cd746d by Johan Sørensen at 2009-01-15 | 18 | when "create_repos" |
| 2e33be3 by Johan Sørensen at 2009-01-13 | 19 | next unless project.wiki_repository.blank? |
| 20 | project.transaction do |
|
| 9cd746d by Johan Sørensen at 2009-01-15 | 21 | puts "Creating wiki repo for #{project.slug} (#{index+1}/#{project_count})" |
| 2e33be3 by Johan Sørensen at 2009-01-13 | 22 | wiki_repo = Repository.new({ |
| 23 | :name => project.slug + Repository::WIKI_NAME_SUFFIX, |
|
| 24 | :kind => Repository::KIND_WIKI, |
|
| 25 | :mainline => false, |
|
| 26 | :user => project.user, |
|
| 27 | }) |
|
| 28 | project.wiki_repository = wiki_repo |
|
| 29 | wiki_repo.save! |
|
| 30 | end |
|
| 9cd746d by Johan Sørensen at 2009-01-15 | 31 | when "load_readmes" |
| 2e33be3 by Johan Sørensen at 2009-01-13 | 32 | wiki_repo = project.wiki_repository |
| 33 | git_dir = File.join(GitoriousConfig["repository_base_path"], project.mainline_repository.gitdir) |
|
| 9cd746d by Johan Sørensen at 2009-01-15 | 34 | unless File.exist?(git_dir) |
| 35 | failure_msg "Skipping #{project.slug}, no mainline repo, wtf? (#{index+1}/#{project_count})" |
|
| 36 | next |
|
| 37 | end |
|
| 2e33be3 by Johan Sørensen at 2009-01-13 | 38 | tree = `env GIT_DIR=#{git_dir} git ls-tree HEAD` |
| 39 | if tree =~ /^\d+ (.+)\t(readme(\..*)?)$/i |
|
| 9cd746d by Johan Sørensen at 2009-01-15 | 40 | begin |
| 41 | sha = $1 |
|
| 42 | readmename = $2 |
|
| 43 | puts "Creating Home in #{project.slug} based on #{$2} (#{$1}) (#{index+1}/#{project_count})" |
|
| 44 | p = Page.find("Home", wiki_repo.git) |
|
| 45 | readmeblob = project.mainline_repository.git.tree / readmename |
|
| 46 | p.content = readmeblob.data |
|
| 47 | p.user = project.user |
|
| 48 | p.save |
|
| 49 | rescue => e |
|
| 50 | failure_msg "FAIL: #{project.slug} #{e.class.name}: #{e.message}" |
|
| 51 | end |
|
| 2e33be3 by Johan Sørensen at 2009-01-13 | 52 | end |
| 53 | end |
|
| 54 | end |

