public
Description: We eat bandwidth for breakfast.
Homepage: http://waferbaby.com/
Clone URL: git://github.com/waferbaby/waferbaby.git
waferbaby / Rakefile
100644 151 lines (122 sloc) 3.665 kb
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
require 'rubygems'
Gem.clear_paths
Gem.path.unshift(File.join(File.dirname(__FILE__), "gems"))
 
require 'rake'
require 'rake/rdoctask'
require 'rake/testtask'
require 'spec/rake/spectask'
require 'fileutils'
require 'merb-core'
require 'rubigen'
include FileUtils
 
# Load the basic runtime dependencies; this will include
# any plugins and therefore plugin rake tasks.
init_env = ENV['MERB_ENV'] || 'rake'
Merb.load_dependencies(:environment => init_env)
 
# Get Merb plugins and dependencies
Merb::Plugins.rakefiles.each { |r| require r }
 
desc "start runner environment"
task :merb_env do
Merb.start_environment(:environment => init_env, :adapter => 'runner')
end
 
##############################################################################
 
namespace :waferbaby do
namespace :sync do
desc "Syncs a user's icon from gravatar.com"
task :gravatar => :merb_env do
require 'digest/md5'
require 'net/http'
 
Person.all.each do |p|
hash = Digest::MD5.hexdigest(p.email_address)
 
begin
data = Net::HTTP.get('gravatar.com', "/avatar/#{hash}.jpg?r=x&d=_")
if data.blank?
has_icon = false
else
File.open("#{Merb.root_path}/public/images/people/#{p.username}.jpg", "w") do |file|
has_icon = true if file.write(data)
end
end
 
p.update_attributes(:has_icon => has_icon)
 
rescue Exception => e
puts e.to_s
end
end
end
end
end
 
##############################################################################
 
class Freezer
 
class << self
 
def components
{
"core" => "git://github.com/wycats/merb-core.git",
"more" => "git://github.com/wycats/merb-more.git",
"plugins" => "git://github.com/wycats/merb-plugins.git"
}
end
 
def framework_dir
# Should allow customization of this directory's location?
File.join(File.dirname(__FILE__), "framework")
end
 
def gitmodules
File.join(File.dirname(__FILE__), ".gitmodules")
end
 
def freeze(component, update = false)
new(component, update).freeze
end
 
end
 
def initialize(component, update)
@component = "merb-" + component
@update = update
end
 
def freeze
# Ensure that required git commands are available
%w(git-pull git-submodule).each do |bin|
next if in_path?(bin)
$stderr.puts "ERROR: #{bin} must be avaible in PATH"
exit 1
end
 
unless File.directory?(framework_dir)
puts "Creating framework directory ..."
FileUtils.mkdir_p(framework_dir)
end
 
if managed?
puts "#{@component} seems to be already managed by git-submodule."
if @update
puts "Trying to update #{@component} ..."
sh "cd #{framework_dir}/#{@component} && git-pull"
end
else
puts "Creating submodule for #{@component} ..."
sh "git-submodule --quiet add #{components[@component.gsub("merb-", '')]} #{File.basename(framework_dir)}/#{@component}"
if $?.success?
sh("git-submodule init")
else
# Should this instead be a raise?
$stderr.puts("ERROR: unable to create submodule for #{@component}")
end
end
end
 
protected
 
def in_submodule?
return false unless File.exists?(gitmodules)
File.read(gitmodules) =~ %r![submodule "#{framework_dir}/#{@component}"]!
end
 
def managed?
File.directory?(File.join(framework_dir, @component)) || in_submodule?
end
 
def in_path?(bin)
`which #{bin}`
!$?.nil? && $?.success?
end
 
end
 
task :freeze => Freezer.components.keys.map { |component| "freeze:#{component}" }
namespace :freeze do
Freezer.components.each do |component, git_repository|
desc "Freeze #{component} from #{git_repository}"
task component do
Freezer.freeze(component, ENV["UPDATE"])
end
end
end