/
Rakefile
197 lines (149 loc) · 5.08 KB
/
Rakefile
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
require File.join(File.dirname(__FILE__), 'vendor', 'gems', 'environment')
require "tokyocabinet"
require "open-uri"
require "json"
require "grit"
require "pp"
include TokyoCabinet
include Grit
HOMEBREW_LOCATION = `brew --prefix`.chomp!
def format_url(url)
url.gsub(/^(http)(.+)/, 'git\2.git')
end
def in_homebrew
Dir.chdir(HOMEBREW_LOCATION) do |hb|
yield
end
end
desc "Use this to setup everything up and get going"
task :bootstrap => ["network:remotes:add_all", "network:remotes:fetch", "db:build"] do
puts %Q{
==========================================
Bootstrapped.
==========================================
You may now run "app.rb"
Please contribute back as this is still very hackish.
}
end
namespace :network do
task :get_members do
@members = JSON.parse(open("http://github.com/mxcl/homebrew/network/members.json").read)["users"]
end
desc "Prints out all members in the homebrew network"
task :ls => [:get_members] do
@members.each do |member|
login = member['owner']['login']
url = member['url']
git_url = format_url(url)
puts "== #{login}"
puts " #{url}"
puts " #{git_url}"
end
end
namespace :remotes do
desc "List all remotes for your homebrew installation"
task :ls do
in_homebrew { puts `git remote -v` }
end
desc "Add a user from the network as a remote (ex: rake network:remotes:add[mxcl])"
task :add, [:user] => [:get_members] do |t, args|
hit = 0
puts %Q{
==========================================
All network remotes
==========================================
}
@members.each do |member|
next unless args.user == member['owner']['login']
in_homebrew {
`git remote add #{args.user} #{format_url(member['url'])}`
}
hit = 1
end
puts "Network member #{args.user} not found, remote not added" if hit == 0
end
# FIXME: I live in Seattle. Its never dry here.
desc "Add all users from network as remotes and fetch (non-destructive)"
task :add_all => [:get_members] do
current_remotes = []
in_homebrew do
current_list = `git remote -v`
current_list.each_line {|l| current_remotes << l.split(' ').first }
end
current_remotes.uniq!
puts %Q{
==========================================
ADDING all network remotes
==========================================
}
@members.each do |member|
user = member['owner']['login']
url = member['url']
next if current_remotes.include?(user)
in_homebrew { `git remote add #{user} #{format_url(url)}`}
puts "Added: #{user} #{format_url(url)}"
end
end
# FIXME: Raindrops keep falling on my head
desc "Fetches (non-destructive) from all your remotes. Use network:remotes:add_all prior for greater effect."
task :fetch do
current_remotes = []
in_homebrew do
current_list = `git remote -v`
current_list.each_line {|l| current_remotes << l.split(' ').first }
end
current_remotes.uniq!
puts %Q{
==========================================
FETCHING from all network remotes
==========================================
}
current_remotes.each do |remote|
in_homebrew { `git fetch #{remote}` }
end
end
# FIXME: I could use a towel here
desc "Remove all remotes (except origin) from your homebrew install"
task :remove_all do
current_remotes = []
in_homebrew do
current_list = `git remote -v`
current_list.each_line {|l| current_remotes << l.split(' ').first }
end
current_remotes.uniq!
puts %Q{
==========================================
REMOVING all network remotes
==========================================
}
current_remotes.each do |remote|
next if remote == "origin"
in_homebrew { `git remote rm #{remote}` }
puts "Removed: #{remote}"
end
end
end
end
namespace :homebrew do
desc "Prints location where homebrew is installed"
task :location do
puts "Homebrew is installed in: #{HOMEBREW_LOCATION}"
end
end
namespace :db do
desc "Builds a TokyoCabinet BDB database to help search the git repo faster"
task :build do
DB = BDB::new # B-Tree database; keys may have multiple values
DB.open("repo.bdb", BDB::OWRITER | BDB::OCREAT)
@repo = Repo.new(HOMEBREW_LOCATION)
@repo.remotes.each do |remote|
user, branch = remote.name.split('/')
next if user == "origin"
puts "Indexing: #{remote.name}"
@repo.tree(remote.name, ["Library/Formula"]).contents.first.contents.each do |pkg|
formula = pkg.name.chomp('.rb')
DB.putdup(remote.name, formula)
end
end
end
end