public
Last active

get a list of bzr branches from launchpad, then create an event.xml for ripary

  • Download Gist
build-event-xml.rb
Ruby
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
#!/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>"
launchpad-bzr-branches.rb
Ruby
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
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.