2011-12-13 13:09:24 +00:00
|
|
|
require 'highline/import'
|
2011-11-22 13:01:33 +00:00
|
|
|
require 'open-uri'
|
2012-01-30 20:36:58 +00:00
|
|
|
require 'iconv'
|
2011-11-22 13:01:33 +00:00
|
|
|
|
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!
|
2011-11-30 20:06:54 +00:00
|
|
|
# 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
|
2012-01-27 15:35:18 +00:00
|
|
|
|
2012-06-08 19:01:33 +01:00
|
|
|
# bundle exec rake import:srpm RAILS_ENV=production BASE=/share/platforms/naulinux5x_personal/tmp/SRPMS LIST=https://dl.dropbox.com/u/984976/nauschool5x.srpms.txt OWNER=naulinux PLATFORM=naulinux REPO=main > log/srpm_naulinux.log
|
2012-06-08 18:19:19 +01:00
|
|
|
desc 'Import SRPMs as projects'
|
|
|
|
task :srpm => :environment do
|
|
|
|
base = ENV['BASE'] || '/share/alt_repos/rsync'
|
|
|
|
list = ENV['LIST'] #|| 'https://dl.dropbox.com/u/984976/alt_import.txt'
|
|
|
|
mask = ENV['MASK'] || '*.src.rpm'
|
|
|
|
owner = User.find_by_uname(ENV['OWNER']) || Group.find_by_uname!(ENV['OWNER'] || 'altlinux')
|
|
|
|
platform = Platform.find_by_name!(ENV['PLATFORM'] || 'altlinux5')
|
|
|
|
repo = platform.repositories.find_by_name!(ENV['REPO'] || 'main')
|
|
|
|
say "START import projects from '#{base}' using '#{list || mask}' for '#{owner.uname}' to repo '#{platform.name}/#{repo.name}'."
|
|
|
|
repo.project_to_repositories.clear if agree "Clear destination repo #{platform.name}/#{repo.name}?"
|
|
|
|
(list ? open(list).readlines.map{|n| File.join base, n.chomp.strip} : Dir[File.join base, mask]).each do |path|
|
|
|
|
print "Processing '#{path}'..."
|
|
|
|
if name = `rpm -q --qf '[%{Name}]' -p #{path}` and $?.success? and name.present?
|
|
|
|
p = Project.find_or_create_by_name_and_owner_type_and_owner_id(name, owner.class.to_s, owner.id)
|
|
|
|
p.import_srpm(path, platform.name)
|
|
|
|
repo.projects << p
|
|
|
|
print "Ok! - #{p.name}"
|
|
|
|
else
|
|
|
|
print 'Fail!'
|
|
|
|
end
|
|
|
|
puts
|
|
|
|
end
|
|
|
|
say 'DONE'
|
|
|
|
end
|
|
|
|
|
2012-01-27 15:35:18 +00:00
|
|
|
namespace :sync do
|
2012-01-28 01:04:11 +00:00
|
|
|
desc "Sync all repos"
|
|
|
|
task :all do
|
2012-01-28 02:05:31 +00:00
|
|
|
system("bundle exec rake import:sync:run RELEASE=official/2011 PLATFORM=mandriva2011 REPOSITORY=main")
|
|
|
|
system("bundle exec rake import:sync:run RELEASE=official/2011 PLATFORM=mandriva2011 REPOSITORY=contrib")
|
|
|
|
system("bundle exec rake import:sync:run RELEASE=official/2011 PLATFORM=mandriva2011 REPOSITORY=non-free")
|
|
|
|
system("bundle exec rake import:sync:run RELEASE=devel/cooker PLATFORM=cooker REPOSITORY=main")
|
2012-01-28 01:04:11 +00:00
|
|
|
system("bundle exec rake import:sync:run RELEASE=devel/cooker PLATFORM=cooker REPOSITORY=contrib")
|
|
|
|
system("bundle exec rake import:sync:run RELEASE=devel/cooker PLATFORM=cooker REPOSITORY=non-free")
|
|
|
|
end
|
|
|
|
|
|
|
|
task :run => [:rsync, :parse]
|
2012-01-27 15:35:18 +00:00
|
|
|
|
|
|
|
desc "Rsync with mirror.yandex.ru"
|
|
|
|
task :rsync => :environment do
|
|
|
|
release = ENV['RELEASE'] || 'official/2011'
|
|
|
|
repository = ENV['REPOSITORY'] || 'main'
|
|
|
|
source = "rsync://mirror.yandex.ru/mandriva/#{release}/SRPMS/#{repository}/"
|
|
|
|
destination = ENV['DESTINATION'] || File.join(APP_CONFIG['root_path'], 'mirror.yandex.ru', 'mandriva', release, 'SRPMS', repository)
|
|
|
|
say "START rsync projects (*.src.rpm) from '#{source}' to '#{destination}'"
|
2012-02-24 15:27:49 +00:00
|
|
|
if system "rsync -rtv --exclude='backports/*' --exclude='testing/*' #{source} #{destination}" # --delete --include='*.src.rpm'
|
2012-01-27 15:35:18 +00:00
|
|
|
say 'Rsync ok!'
|
|
|
|
else
|
|
|
|
say 'Rsync failed!'
|
|
|
|
end
|
|
|
|
say 'DONE'
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "Parse repository for changes"
|
|
|
|
task :parse => :environment do
|
|
|
|
release = ENV['RELEASE'] || 'official/2011'
|
|
|
|
platform = Platform.find_by_name(ENV['PLATFORM'] || "mandriva2011")
|
|
|
|
repository = platform.repositories.find_by_name(ENV['REPOSITORY'] || 'main')
|
|
|
|
source = ENV['SOURCE'] || File.join(APP_CONFIG['root_path'], 'mirror.yandex.ru', 'mandriva', release, 'SRPMS', repository.name)
|
2012-02-24 15:27:49 +00:00
|
|
|
owner = Group.find_or_create_by_uname(ENV['OWNER'] || 'import') {|g| g.name = g.uname; g.owner = User.first}
|
2012-01-27 15:35:18 +00:00
|
|
|
branch = "import_#{platform.name}"
|
|
|
|
|
|
|
|
say 'START'
|
|
|
|
Dir[File.join source, '{release,updates}', '*.src.rpm'].each do |srpm_file|
|
|
|
|
say "=== Processing '#{srpm_file}'..."
|
|
|
|
if name = `rpm -q --qf '[%{Name}]' -p #{srpm_file}` and $?.success? and name.present? and
|
|
|
|
version = `rpm -q --qf '[%{Version}]' -p #{srpm_file}` and $?.success? and version.present?
|
2012-01-31 18:48:37 +00:00
|
|
|
project_import = ProjectImport.find_by_name_and_platform_id(name, platform.id) || ProjectImport.by_name(name).where(:platform_id => platform.id).first || ProjectImport.new(:name => name, :platform_id => platform.id)
|
2012-01-27 15:35:18 +00:00
|
|
|
if version != project_import.version.to_s and File.mtime(srpm_file) > project_import.file_mtime
|
|
|
|
unless project = project_import.project
|
2012-01-28 01:04:11 +00:00
|
|
|
if project = repository.projects.find_by_name(name) || repository.projects.by_name(name).first # fallback to speedup
|
2012-01-27 15:35:18 +00:00
|
|
|
say "Found project '#{project.owner.uname}/#{project.name}'"
|
2012-01-28 01:04:11 +00:00
|
|
|
elsif scoped = Project.where(:owner_id => owner.id, :owner_type => owner.class) and
|
2012-01-28 04:22:29 +00:00
|
|
|
project = scoped.find_by_name(name) || scoped.by_name(name).first
|
2012-01-27 15:35:18 +00:00
|
|
|
repository.projects << project
|
|
|
|
say "Add project '#{project.owner.uname}/#{project.name}' to '#{platform.name}/#{repository.name}'"
|
|
|
|
else
|
|
|
|
description = ::Iconv.conv('UTF-8//IGNORE', 'UTF-8', `rpm -q --qf '[%{Description}]' -p #{srpm_file}`)
|
|
|
|
project = Project.create!(:name => name, :description => description) {|p| p.owner = owner}
|
|
|
|
repository.projects << project
|
|
|
|
say "Create project #{project.owner.uname}/#{project.name} in #{platform.name}/#{repository.name}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
project.import_srpm(srpm_file, branch)
|
|
|
|
say "New version (#{version}) for '#{project.owner.uname}/#{project.name}' successfully imported to branch '#{branch}'!"
|
|
|
|
|
|
|
|
project_import.project = project
|
2012-01-31 18:48:37 +00:00
|
|
|
# project_import.platform = platform
|
2012-01-27 15:35:18 +00:00
|
|
|
project_import.version = version
|
|
|
|
project_import.file_mtime = File.mtime(srpm_file)
|
|
|
|
project_import.save!
|
|
|
|
|
|
|
|
# TODO notify import.members
|
|
|
|
|
|
|
|
say '=== Success!'
|
|
|
|
else
|
|
|
|
say '=== Not changed!'
|
|
|
|
end
|
|
|
|
else
|
|
|
|
say '=== Fail!'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
say 'DONE'
|
|
|
|
end
|
|
|
|
end
|
2011-10-29 22:58:48 +01:00
|
|
|
end
|