2011-12-13 13:09:24 +00:00
|
|
|
require 'highline/import'
|
2011-11-22 13:01:33 +00:00
|
|
|
require 'open-uri'
|
|
|
|
|
2011-10-29 22:58:48 +01:00
|
|
|
namespace :import do
|
|
|
|
desc "Load projects"
|
2014-01-21 04:51:49 +00:00
|
|
|
task projects: :environment do
|
2011-12-13 13:27:14 +00:00
|
|
|
source = ENV['SOURCE'] || 'http://dl.dropbox.com/u/984976/package_list.txt'
|
2014-03-18 13:58:51 +00:00
|
|
|
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
|
|
|
|
2013-09-13 13:36:21 +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 CLEAR=true HIDDEN=true > log/srpm_naulinux.log &
|
2012-06-08 18:19:19 +01:00
|
|
|
desc 'Import SRPMs as projects'
|
2014-01-21 04:51:49 +00:00
|
|
|
task srpm: :environment do
|
2012-06-08 18:19:19 +01:00
|
|
|
base = ENV['BASE'] || '/share/alt_repos/rsync'
|
|
|
|
list = ENV['LIST'] #|| 'https://dl.dropbox.com/u/984976/alt_import.txt'
|
|
|
|
mask = ENV['MASK'] || '*.src.rpm'
|
2013-09-13 13:36:21 +01:00
|
|
|
hidden = ENV['HIDDEN'] == 'true' ? true : false
|
2014-03-18 13:58:51 +00:00
|
|
|
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')
|
2012-08-03 11:31:50 +01:00
|
|
|
clear = ENV['CLEAR'] == 'true' ? true : false
|
|
|
|
|
2012-06-08 18:19:19 +01:00
|
|
|
say "START import projects from '#{base}' using '#{list || mask}' for '#{owner.uname}' to repo '#{platform.name}/#{repo.name}'."
|
2012-08-03 11:31:50 +01:00
|
|
|
repo.project_to_repositories.clear if clear
|
|
|
|
(list ? open(list).readlines.map{|n| File.join base, n.chomp.strip} : Dir[File.join base, mask]).each do |srpm_file|
|
|
|
|
print "Processing '#{srpm_file}'... "
|
|
|
|
if name = `rpm -q --qf '[%{Name}]' -p #{srpm_file}` and $?.success? and name.present?
|
|
|
|
if clear # simply add
|
|
|
|
project = Project.find_or_create_by_name_and_owner_type_and_owner_id(name, owner.class.to_s, owner.id)
|
2013-10-24 16:43:18 +01:00
|
|
|
repo.projects << project rescue nil
|
2012-08-03 11:31:50 +01:00
|
|
|
else # check if project already added
|
2014-03-18 13:58:51 +00:00
|
|
|
if project = repo.projects.find_by(name: name) || repo.projects.by_name(name).first # fallback to speedup
|
2012-08-10 17:37:21 +01:00
|
|
|
print "Found project '#{project.name_with_owner}' in '#{platform.name}/#{repo.name}'."
|
2014-01-21 04:51:49 +00:00
|
|
|
elsif scoped = Project.where(owner_id: owner.id, owner_type: owner.class) and
|
2014-03-18 13:58:51 +00:00
|
|
|
project = scoped.find_by(name: name) || scoped.by_name(name).first
|
2012-08-03 11:31:50 +01:00
|
|
|
begin
|
2013-10-24 16:43:18 +01:00
|
|
|
repo.projects << project rescue nil
|
2012-08-03 11:31:50 +01:00
|
|
|
rescue Exception => e
|
2012-08-10 17:37:21 +01:00
|
|
|
print "Add project '#{project.name_with_owner}' to '#{platform.name}/#{repo.name}' FAILED: #{e.message}."
|
2012-08-03 11:31:50 +01:00
|
|
|
else
|
2012-08-10 17:37:21 +01:00
|
|
|
print "Add project '#{project.name_with_owner}' to '#{platform.name}/#{repo.name}' OK."
|
2012-08-03 11:31:50 +01:00
|
|
|
end
|
|
|
|
else
|
2014-01-16 13:39:03 +00:00
|
|
|
description = `rpm -q --qf '[%{Description}]' -p #{srpm_file}`.scrub('')
|
2014-01-21 04:51:49 +00:00
|
|
|
project = Project.create!(name: name, description: description) {|p| p.owner = owner}
|
2013-10-24 16:43:18 +01:00
|
|
|
repo.projects << project rescue nil
|
2012-08-10 17:37:21 +01:00
|
|
|
print "Create project #{project.name_with_owner} in #{platform.name}/#{repo.name} OK."
|
2012-08-03 11:31:50 +01:00
|
|
|
end
|
|
|
|
end
|
2014-01-21 04:51:49 +00:00
|
|
|
project.update_attributes(visibility: 'hidden') if hidden
|
2012-08-03 11:31:50 +01:00
|
|
|
project.import_srpm(srpm_file, platform.name)
|
|
|
|
print " Code import complete!"
|
2012-06-08 18:19:19 +01:00
|
|
|
else
|
2012-08-03 11:31:50 +01:00
|
|
|
print 'RPM Error!'
|
2012-06-08 18:19:19 +01:00
|
|
|
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"
|
2014-01-21 04:51:49 +00:00
|
|
|
task all: :environment do
|
2012-08-15 14:58:17 +01: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")
|
2012-11-12 10:02:23 +00:00
|
|
|
#system("bundle exec rake import:sync:run RELEASE=devel/cooker PLATFORM=cooker REPOSITORY=main")
|
|
|
|
#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")
|
2012-08-28 22:04:00 +01:00
|
|
|
system("bundle exec rake import:sync:run SOURCE=rsync://mirror.yandex.ru/fedora-epel/6/SRPMS/ DESTINATION=#{File.join(APP_CONFIG['root_path'], 'mirror.yandex.ru', 'fedora-epel', '6', 'SRPMS')} PLATFORM=server_personal REPOSITORY=main OWNER=server BRANCH=import")
|
|
|
|
system("bundle exec rake import:sync:run SOURCE=rsync://rh-mirror.redhat.com/redhat/linux/enterprise/6Server/en/os/SRPMS/ DESTINATION=#{File.join(APP_CONFIG['root_path'], 'rh-mirror.redhat.com', 'redhat', 'linux', 'enterprise', '6Server', 'en', 'os', 'SRPMS')} PLATFORM=server_personal REPOSITORY=main OWNER=server BRANCH=import")
|
2012-01-28 01:04:11 +00:00
|
|
|
end
|
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
task run: [:rsync, :parse]
|
2012-01-27 15:35:18 +00:00
|
|
|
|
|
|
|
desc "Rsync with mirror.yandex.ru"
|
2014-01-21 04:51:49 +00:00
|
|
|
task rsync: :environment do
|
2012-01-27 15:35:18 +00:00
|
|
|
release = ENV['RELEASE'] || 'official/2011'
|
|
|
|
repository = ENV['REPOSITORY'] || 'main'
|
2012-08-15 14:58:17 +01:00
|
|
|
source = ENV['SOURCE'] || "rsync://mirror.yandex.ru/mandriva/#{release}/SRPMS/#{repository}/"
|
2012-01-27 15:35:18 +00:00
|
|
|
destination = ENV['DESTINATION'] || File.join(APP_CONFIG['root_path'], 'mirror.yandex.ru', 'mandriva', release, 'SRPMS', repository)
|
2012-08-07 21:23:30 +01:00
|
|
|
say "START rsync projects (*.src.rpm) from '#{source}' to '#{destination}' (#{Time.now.utc})"
|
|
|
|
if system "rsync -rtv --delete --exclude='backports/*' --exclude='testing/*' #{source} #{destination}" # --include='*.src.rpm'
|
2012-01-27 15:35:18 +00:00
|
|
|
say 'Rsync ok!'
|
|
|
|
else
|
|
|
|
say 'Rsync failed!'
|
|
|
|
end
|
2012-08-07 21:23:30 +01:00
|
|
|
say "DONE (#{Time.now.utc})"
|
2012-01-27 15:35:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
desc "Parse repository for changes"
|
2014-01-21 04:51:49 +00:00
|
|
|
task parse: :environment do
|
2012-01-27 15:35:18 +00:00
|
|
|
release = ENV['RELEASE'] || 'official/2011'
|
2014-03-18 13:58:51 +00:00
|
|
|
platform = Platform.find_by(name: ENV['PLATFORM'] || "mandriva2011")
|
|
|
|
repository = platform.repositories.find_by(name: ENV['REPOSITORY'] || 'main')
|
2012-08-15 14:58:17 +01:00
|
|
|
source = ENV['DESTINATION'] || File.join(APP_CONFIG['root_path'], 'mirror.yandex.ru', 'mandriva', release, 'SRPMS', repository.name, '{release,updates}')
|
2014-03-18 13:58:51 +00:00
|
|
|
owner = Group.find_or_create_by(uname: ENV['OWNER'] || 'import') {|g| g.name = g.uname; g.owner = User.first}
|
2012-08-15 14:58:17 +01:00
|
|
|
branch = ENV['BRANCH'] || "import_#{platform.name}"
|
2012-01-27 15:35:18 +00:00
|
|
|
|
2012-08-07 21:23:30 +01:00
|
|
|
say "START (#{Time.now.utc})"
|
2012-08-15 14:58:17 +01:00
|
|
|
Dir[File.join source, '*.src.rpm'].each do |srpm_file|
|
2012-08-07 21:23:30 +01:00
|
|
|
print "Processing '#{srpm_file}'... "
|
2012-01-27 15:35:18 +00:00
|
|
|
if name = `rpm -q --qf '[%{Name}]' -p #{srpm_file}` and $?.success? and name.present? and
|
2012-08-07 21:23:30 +01:00
|
|
|
version = `rpm -q --qf '[%{Version}-%{Release}]' -p #{srpm_file}` and $?.success? and version.present?
|
2014-01-21 04:51:49 +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-08-15 14:58:17 +01:00
|
|
|
if platform.personal? # search project through owner # used for testhat
|
|
|
|
project = Project.find_or_create_by_name_and_owner_type_and_owner_id(name, owner.class.to_s, owner.id)
|
2012-09-25 12:55:30 +01:00
|
|
|
print "Use project #{project.name_with_owner}. "
|
2012-08-15 14:58:17 +01:00
|
|
|
else # search project through repository
|
2014-03-18 13:58:51 +00:00
|
|
|
if project = repository.projects.find_by(name: name) || repository.projects.by_name(name).first # fallback to speedup
|
2012-09-25 12:55:30 +01:00
|
|
|
print "Found project #{project.name_with_owner} in #{platform.name}/#{repository.name}. "
|
2014-01-21 04:51:49 +00:00
|
|
|
elsif scoped = Project.where(owner_id: owner.id, owner_type: owner.class) and
|
2014-03-18 13:58:51 +00:00
|
|
|
project = scoped.find_by(name: name) || scoped.by_name(name).first
|
2012-08-15 14:58:17 +01:00
|
|
|
repository.projects << project
|
2012-09-25 12:55:30 +01:00
|
|
|
print "Add project #{project.name_with_owner} to #{platform.name}/#{repository.name}. "
|
2012-08-15 14:58:17 +01:00
|
|
|
else
|
2014-01-16 13:39:03 +00:00
|
|
|
description = `rpm -q --qf '[%{Description}]' -p #{srpm_file}`.scrub('')
|
2014-01-21 04:51:49 +00:00
|
|
|
project = Project.create!(name: name, description: description) {|p| p.owner = owner}
|
2012-08-15 14:58:17 +01:00
|
|
|
repository.projects << project
|
2012-09-25 12:55:30 +01:00
|
|
|
print "Create project #{project.name_with_owner} at #{platform.name}/#{repository.name}. "
|
2012-08-15 14:58:17 +01:00
|
|
|
end
|
2012-01-27 15:35:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
project.import_srpm(srpm_file, branch)
|
2012-08-10 17:37:21 +01:00
|
|
|
print "New version (#{version}) for #{project.name_with_owner} successfully imported to branch #{branch}! "
|
2012-01-27 15:35:18 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2012-08-07 21:23:30 +01:00
|
|
|
print 'Ok!'
|
2012-01-27 15:35:18 +00:00
|
|
|
else
|
2012-08-07 21:23:30 +01:00
|
|
|
print 'Not updated!'
|
2012-01-27 15:35:18 +00:00
|
|
|
end
|
|
|
|
else
|
2012-08-07 21:23:30 +01:00
|
|
|
print 'RPM Error!'
|
2012-01-27 15:35:18 +00:00
|
|
|
end
|
2012-08-07 21:23:30 +01:00
|
|
|
puts
|
2012-01-27 15:35:18 +00:00
|
|
|
end
|
2012-08-07 21:23:30 +01:00
|
|
|
say "DONE (#{Time.now.utc})"
|
2012-01-27 15:35:18 +00:00
|
|
|
end
|
|
|
|
end
|
2011-10-29 22:58:48 +01:00
|
|
|
end
|