waferbaby / waferbaby
- Source
- Commits
- Network (3)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Tree:
3afe62e
waferbaby / Rakefile
| 1781b1c9 » | waferbaby | 2008-05-07 | 1 | require 'rubygems' | |
| 2 | Gem.clear_paths | ||||
| 3 | Gem.path.unshift(File.join(File.dirname(__FILE__), "gems")) | ||||
| 4 | |||||
| 5 | require 'rake' | ||||
| 6 | require 'rake/rdoctask' | ||||
| 7 | require 'rake/testtask' | ||||
| 8 | require 'spec/rake/spectask' | ||||
| 9 | require 'fileutils' | ||||
| 10 | require 'merb-core' | ||||
| 11 | require 'rubigen' | ||||
| 12 | include FileUtils | ||||
| 13 | |||||
| 14 | # Load the basic runtime dependencies; this will include | ||||
| 15 | # any plugins and therefore plugin rake tasks. | ||||
| 16 | init_env = ENV['MERB_ENV'] || 'rake' | ||||
| 17 | Merb.load_dependencies(:environment => init_env) | ||||
| 5a78d15b » | waferbaby | 2009-01-10 | 18 | ||
| 1781b1c9 » | waferbaby | 2008-05-07 | 19 | # Get Merb plugins and dependencies | |
| 20 | Merb::Plugins.rakefiles.each { |r| require r } | ||||
| 21 | |||||
| 22 | desc "start runner environment" | ||||
| 23 | task :merb_env do | ||||
| 5a78d15b » | waferbaby | 2009-01-10 | 24 | Merb.start_environment(:environment => init_env, :adapter => 'runner') | |
| 1781b1c9 » | waferbaby | 2008-05-07 | 25 | end | |
| 26 | |||||
| 27 | ############################################################################## | ||||
| 28 | |||||
| 5a78d15b » | waferbaby | 2009-01-10 | 29 | namespace :waferbaby do | |
| 30 | namespace :sync do | ||||
| 31 | desc "Syncs a user's icon from gravatar.com" | ||||
| 32 | task :gravatar => :merb_env do | ||||
| 33 | require 'digest/md5' | ||||
| 34 | require 'net/http' | ||||
| 35 | |||||
| 36 | Person.all.each do |p| | ||||
| 37 | hash = Digest::MD5.hexdigest(p.email_address) | ||||
| 38 | |||||
| 39 | begin | ||||
| 40 | data = Net::HTTP.get('gravatar.com', "/avatar/#{hash}.jpg?r=x&d=_") | ||||
| 41 | if data.blank? | ||||
| 42 | has_icon = false | ||||
| 43 | else | ||||
| 5cebe3d2 » | waferbaby | 2009-03-14 | 44 | File.open("#{Merb.root_path}/public/images/people/#{p.username}.jpg", "w") do |file| | |
| 5a78d15b » | waferbaby | 2009-01-10 | 45 | has_icon = true if file.write(data) | |
| 46 | end | ||||
| 47 | end | ||||
| 48 | |||||
| 49 | p.update_attributes(:has_icon => has_icon) | ||||
| 50 | |||||
| 51 | rescue Exception => e | ||||
| 52 | puts e.to_s | ||||
| 53 | end | ||||
| 54 | end | ||||
| 55 | end | ||||
| 56 | end | ||||
| 1781b1c9 » | waferbaby | 2008-05-07 | 57 | end | |
| 58 | |||||
| 5a78d15b » | waferbaby | 2009-01-10 | 59 | ############################################################################## | |
| 1781b1c9 » | waferbaby | 2008-05-07 | 60 | ||
| 61 | class Freezer | ||||
| 5a78d15b » | waferbaby | 2009-01-10 | 62 | ||
| 63 | class << self | ||||
| 64 | |||||
| 65 | def components | ||||
| 66 | { | ||||
| 67 | "core" => "git://github.com/wycats/merb-core.git", | ||||
| 68 | "more" => "git://github.com/wycats/merb-more.git", | ||||
| 69 | "plugins" => "git://github.com/wycats/merb-plugins.git" | ||||
| 70 | } | ||||
| 71 | end | ||||
| 72 | |||||
| 73 | def framework_dir | ||||
| 74 | # Should allow customization of this directory's location? | ||||
| 75 | File.join(File.dirname(__FILE__), "framework") | ||||
| 76 | end | ||||
| 77 | |||||
| 78 | def gitmodules | ||||
| 79 | File.join(File.dirname(__FILE__), ".gitmodules") | ||||
| 80 | end | ||||
| 81 | |||||
| 82 | def freeze(component, update = false) | ||||
| 83 | new(component, update).freeze | ||||
| 84 | end | ||||
| 85 | |||||
| 86 | end | ||||
| 87 | |||||
| 88 | def initialize(component, update) | ||||
| 89 | @component = "merb-" + component | ||||
| 90 | @update = update | ||||
| 91 | end | ||||
| 92 | |||||
| 93 | def freeze | ||||
| 94 | # Ensure that required git commands are available | ||||
| 95 | %w(git-pull git-submodule).each do |bin| | ||||
| 96 | next if in_path?(bin) | ||||
| 97 | $stderr.puts "ERROR: #{bin} must be avaible in PATH" | ||||
| 98 | exit 1 | ||||
| 99 | end | ||||
| 100 | |||||
| 101 | unless File.directory?(framework_dir) | ||||
| 102 | puts "Creating framework directory ..." | ||||
| 103 | FileUtils.mkdir_p(framework_dir) | ||||
| 104 | end | ||||
| 105 | |||||
| 106 | if managed? | ||||
| 107 | puts "#{@component} seems to be already managed by git-submodule." | ||||
| 108 | if @update | ||||
| 109 | puts "Trying to update #{@component} ..." | ||||
| 110 | sh "cd #{framework_dir}/#{@component} && git-pull" | ||||
| 111 | end | ||||
| 112 | else | ||||
| 113 | puts "Creating submodule for #{@component} ..." | ||||
| 114 | sh "git-submodule --quiet add #{components[@component.gsub("merb-", '')]} #{File.basename(framework_dir)}/#{@component}" | ||||
| 115 | if $?.success? | ||||
| 116 | sh("git-submodule init") | ||||
| 117 | else | ||||
| 118 | # Should this instead be a raise? | ||||
| 119 | $stderr.puts("ERROR: unable to create submodule for #{@component}") | ||||
| 120 | end | ||||
| 121 | end | ||||
| 122 | end | ||||
| 123 | |||||
| 124 | protected | ||||
| 125 | |||||
| 126 | def in_submodule? | ||||
| 127 | return false unless File.exists?(gitmodules) | ||||
| 128 | File.read(gitmodules) =~ %r![submodule "#{framework_dir}/#{@component}"]! | ||||
| 129 | end | ||||
| 130 | |||||
| 131 | def managed? | ||||
| 132 | File.directory?(File.join(framework_dir, @component)) || in_submodule? | ||||
| 133 | end | ||||
| 134 | |||||
| 135 | def in_path?(bin) | ||||
| 136 | `which #{bin}` | ||||
| 137 | !$?.nil? && $?.success? | ||||
| 138 | end | ||||
| 1781b1c9 » | waferbaby | 2008-05-07 | 139 | ||
| 140 | end | ||||
| 141 | |||||
| 142 | task :freeze => Freezer.components.keys.map { |component| "freeze:#{component}" } | ||||
| 143 | namespace :freeze do | ||||
| 5a78d15b » | waferbaby | 2009-01-10 | 144 | Freezer.components.each do |component, git_repository| | |
| 145 | desc "Freeze #{component} from #{git_repository}" | ||||
| 146 | task component do | ||||
| 147 | Freezer.freeze(component, ENV["UPDATE"]) | ||||
| 148 | end | ||||
| 149 | end | ||||
| 1781b1c9 » | waferbaby | 2008-05-07 | 150 | end | |
