rosa-build/lib/tasks/import.rake

29 lines
1.1 KiB
Ruby
Raw Normal View History

2011-12-13 13:09:24 +00:00
require 'highline/import'
require 'open-uri'
2011-10-29 22:58:48 +01:00
namespace :import do
desc "Load projects"
task :projects => :environment do
2011-12-13 13:27:14 +00:00
source = ENV['SOURCE'] || 'http://dl.dropbox.com/u/984976/package_list.txt'
2012-01-23 14:52:42 +00:00
#owner = User.find_by_uname(ENV['OWNER_UNAME']) || Group.find_by_uname(ENV['OWNER_UNAME']) || User.first
owner = Group.find_by_uname("npp_team")
platform = Platform.find_by_name("RosaNPP") # RosaNPP
2011-12-13 13:09:24 +00:00
repo = platform.repositories.first rescue nil
2011-12-13 13:27:14 +00:00
say "START import projects from '#{source}' for '#{owner.uname}'.#{repo ? " To repo '#{platform.name}/#{repo.name}'." : ''}"
2011-12-13 13:09:24 +00:00
ask 'Press enter to continue'
2011-12-13 13:27:14 +00:00
open(source).readlines.each do |name|
2011-12-05 20:44:38 +00:00
name.chomp!; name.strip! #; name.downcase!
# name = name.match(/^([a-z\d_\-\+\.]+?)-(\d[a-z\d\-\.]+)\.src\.rpm$/)[1] # parse
2011-12-13 13:09:24 +00:00
print "Import '#{name}'..."
p = Project.find_or_create_by_name_and_owner_type_and_owner_id(name, owner.class.to_s, owner.id)
print p.persisted? ? "Ok!" : "Fail!"
if repo
print " Add to repo '#{platform.name}/#{repo.name}'."
repo.projects << p rescue print ' Fail!'
end
puts
2011-10-29 22:58:48 +01:00
end
2011-12-13 13:09:24 +00:00
say 'DONE'
2011-10-29 22:58:48 +01:00
end
end