From d1a1409a0f5d6e9ecea2e942de2e87628ee15a67 Mon Sep 17 00:00:00 2001 From: Joachim Filip Ignacy Bartosik Date: Fri, 23 Jul 2010 18:18:57 +0200 Subject: Rake task prepare:lead_data The task fetches Gentoo project leads data from gentoo.org and stores it in tmp/lead_data.yml --- lib/tasks/prepare.rake | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'lib') diff --git a/lib/tasks/prepare.rake b/lib/tasks/prepare.rake index 4c05b07..f28826e 100644 --- a/lib/tasks/prepare.rake +++ b/lib/tasks/prepare.rake @@ -1,4 +1,5 @@ require "ftools" +require "rexml/document" desc "Prepare database and configuration files to run tests (accepts options used by prepare:config and seed option)" opt = ENV.include?('seed') ? ['db:seed'] : [] @@ -26,4 +27,54 @@ namespace :prepare do File.copy('doc/config/config.yml', 'config/config.yml') end + + desc "Prepare project Lead data" + task :lead_data => :environment do + + # Fetch xml document from uri. Collect all elements with name equal to + # name parameter and array containing them (and only them). + def get_all_tags_with_name(uri, name) + raw_data = Net::HTTP.get_response(URI.parse(uri)).body + project_data = REXML::Document.new(raw_data) + projects_el = project_data.children + + removed_sth = true # So it'll enter loop first time + while removed_sth # Repeat until there is nothing left to remove + removed_sth = false + projects_el = projects_el.collect do |x| # Check all elements + if x.respond_to?(:name) && x.name == name # If element has name and + # it's what we're looking + # for let it stay. + x + else + removed_sth = true # otherwise remove it + x.respond_to?(:children) ? x.children : nil + end + end + + # Remove nils & flatten array + if removed_sth + projects_el.flatten! + projects_el.compact! + end + end + projects_el + end + + devs = [] + projects = get_all_tags_with_name('http://www.gentoo.org/proj/en/metastructure/gentoo.xml?passthru=1', 'subproject') + + for proj in projects + devs += get_all_tags_with_name("http://www.gentoo.org#{proj.attribute('ref').to_s}?passthru=1", 'dev') + end + + leads = devs.collect{ |x| x if /lead/i.match(x.attribute('role').to_s) }.compact + lead_nicks = leads.collect{ |x| x.text } + + User.transaction do + for user in User.all + user.update_attribute(:project_lead, lead_nicks.include?(user.nick)) + end + end + end end -- cgit v1.2.3-65-gdbad