Skip to content

Instantly share code, notes, and snippets.

@anotherjesse
Created December 26, 2010 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anotherjesse/755117 to your computer and use it in GitHub Desktop.
Save anotherjesse/755117 to your computer and use it in GitHub Desktop.
get a list of bzr branches from launchpad, then create an event.xml for ripary
#!/usr/bin/env ruby
require 'date'
require 'time'
$all_events = {}
class Event
attr_reader :date, :branch, :filename
def initialize(date, branch, filename)
@date = date
@branch = branch
@filename = filename
end
def <=>(b)
return @date <=> b.date
end
def to_s
"#{@date}:#{@filename}"
end
end
class Events < Hash
def add(e)
if self[e.to_s].nil?
self[e.to_s] = e
end
end
def to_a
self.values
end
end
def load_events(branch, path)
input = IO.popen("bzr log --long -v #{path}")
begin
while true
while true
line = input.readline("\n")
# puts line
# match = line.match("author: ([^ ]+).*") # author: Cerberus <matt.dietz@rackspace.com>, mdietz <mdietz@openstack>
#author = match[1] if match
match = line.match("timestamp: (.*)") # timestamp: Thu 2010-12-23 19:07:10 +0000
date = ((DateTime.parse(match[1]) - DateTime.civil(1970))*86400) if match
match = line.match("(added|modified|removed|renamed):.*")
break if match
#date = match[2]
end
while true
break if line == "------------------------------------------------------------\n"
if line.match(" .*")
$events.add Event.new(date.to_i * 1000, branch, line.strip)
end
line = input.readline("\n")
end
end
rescue EOFError
end
end
$events = Events.new
load_events('trunk', 'trunk')
Dir['*'].each do |branch|
load_events(branch, branch) if File.directory? branch
end
@events = $events.to_a.sort!
puts "<?xml version=\"1.0\"?>"
puts "<file_events>"
@events.each do |e|
puts "<event date=\"#{e.date}\" author=\"#{e.branch}\" filename=\"/#{e.filename}\"/>"
end
puts "</file_events>"
require 'open-uri'
def url(repo, offset)
"https://code.launchpad.net/#{repo}/+branches?field.lifecycle=ALL&field.lifecycle-empty-marker=1&field.sort_by=newest+first&field.sort_by-empty-marker=1&start=#{offset}"
end
def branches(repo)
offset = 0
results = []
loop do
puts "# grabbing offset #{offset}"
html = open(url(repo,offset)).read
new_branches = html.scan(/href="\/(~[^\/]+\/#{repo}\/[^\/]+)"/).flatten
break if new_branches.empty?
results += new_branches
offset += 100
end
return results
end
def folder(repo, name)
name.gsub("~", '').gsub("/#{repo}/", '_')
end
def init(repo)
puts "mkdir #{repo}"
puts "cd #{repo}"
puts "bzr init-repo ."
puts "bzr branch lp:#{repo} trunk"
branches(repo).each do |name|
puts "bzr branch lp:#{name} #{folder(repo, name)}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment