diff options
author | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2010-07-23 18:18:57 +0200 |
---|---|---|
committer | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2010-07-29 18:49:34 +0200 |
commit | d1a1409a0f5d6e9ecea2e942de2e87628ee15a67 (patch) | |
tree | 9c7ac878094a52e7eeb588af1754ae0c995a698d | |
parent | Improved way admins create questions (diff) | |
download | recruiting-webapp-d1a1409a0f5d6e9ecea2e942de2e87628ee15a67.tar.gz recruiting-webapp-d1a1409a0f5d6e9ecea2e942de2e87628ee15a67.tar.bz2 recruiting-webapp-d1a1409a0f5d6e9ecea2e942de2e87628ee15a67.zip |
Rake task prepare:lead_data
The task fetches Gentoo project leads data from gentoo.org and stores it
in tmp/lead_data.yml
-rw-r--r-- | app/models/user.rb | 2 | ||||
-rw-r--r-- | db/schema.rb | 3 | ||||
-rw-r--r-- | lib/tasks/prepare.rake | 51 |
3 files changed, 55 insertions, 1 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 7b9c5f7..e652e37 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -9,6 +9,7 @@ class User < ActiveRecord::Base role Role, :default => 'recruit' nick :string contributions HoboFields::MarkdownString + project_lead :boolean, :default => false timestamps end @@ -59,6 +60,7 @@ class User < ActiveRecord::Base validate :mentor_is_gentoo_dev_long_enough validates_uniqueness_of :nick, :if => :nick + never_show :project_lead # --- Permissions --- # def create_permitted? diff --git a/db/schema.rb b/db/schema.rb index 588f4e9..15b0b5a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20100727204251) do +ActiveRecord::Schema.define(:version => 20100728172058) do create_table "answers", :force => true do |t| t.text "content" @@ -140,6 +140,7 @@ ActiveRecord::Schema.define(:version => 20100727204251) do t.integer "mentor_id" t.string "state", :default => "active" t.datetime "key_timestamp" + t.boolean "project_lead", :default => false end add_index "users", ["mentor_id"], :name => "index_users_on_mentor_id" 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 |