Improve import sync script to work with EPEL ang RHEL repositories. Refs #112
This commit is contained in:
parent
f2565c4877
commit
77ff4e71e8
|
@ -77,13 +77,15 @@ namespace :import do
|
||||||
|
|
||||||
namespace :sync do
|
namespace :sync do
|
||||||
desc "Sync all repos"
|
desc "Sync all repos"
|
||||||
task :all do
|
task :all => :environment do
|
||||||
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=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=contrib")
|
||||||
system("bundle exec rake import:sync:run RELEASE=official/2011 PLATFORM=mandriva2011 REPOSITORY=non-free")
|
# 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")
|
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=contrib")
|
||||||
system("bundle exec rake import:sync:run RELEASE=devel/cooker PLATFORM=cooker REPOSITORY=non-free")
|
system("bundle exec rake import:sync:run RELEASE=devel/cooker PLATFORM=cooker REPOSITORY=non-free")
|
||||||
|
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=testhat_personal REPOSITORY=main OWNER=testhat 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=testhat_personal REPOSITORY=main OWNER=testhat BRANCH=import")
|
||||||
end
|
end
|
||||||
|
|
||||||
task :run => [:rsync, :parse]
|
task :run => [:rsync, :parse]
|
||||||
|
@ -92,7 +94,7 @@ namespace :import do
|
||||||
task :rsync => :environment do
|
task :rsync => :environment do
|
||||||
release = ENV['RELEASE'] || 'official/2011'
|
release = ENV['RELEASE'] || 'official/2011'
|
||||||
repository = ENV['REPOSITORY'] || 'main'
|
repository = ENV['REPOSITORY'] || 'main'
|
||||||
source = "rsync://mirror.yandex.ru/mandriva/#{release}/SRPMS/#{repository}/"
|
source = ENV['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)
|
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}' (#{Time.now.utc})"
|
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'
|
if system "rsync -rtv --delete --exclude='backports/*' --exclude='testing/*' #{source} #{destination}" # --include='*.src.rpm'
|
||||||
|
@ -108,29 +110,34 @@ namespace :import do
|
||||||
release = ENV['RELEASE'] || 'official/2011'
|
release = ENV['RELEASE'] || 'official/2011'
|
||||||
platform = Platform.find_by_name(ENV['PLATFORM'] || "mandriva2011")
|
platform = Platform.find_by_name(ENV['PLATFORM'] || "mandriva2011")
|
||||||
repository = platform.repositories.find_by_name(ENV['REPOSITORY'] || 'main')
|
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)
|
source = ENV['DESTINATION'] || File.join(APP_CONFIG['root_path'], 'mirror.yandex.ru', 'mandriva', release, 'SRPMS', repository.name, '{release,updates}')
|
||||||
owner = Group.find_or_create_by_uname(ENV['OWNER'] || 'import') {|g| g.name = g.uname; g.owner = User.first}
|
owner = Group.find_or_create_by_uname(ENV['OWNER'] || 'import') {|g| g.name = g.uname; g.owner = User.first}
|
||||||
branch = "import_#{platform.name}"
|
branch = ENV['BRANCH'] || "import_#{platform.name}"
|
||||||
|
|
||||||
say "START (#{Time.now.utc})"
|
say "START (#{Time.now.utc})"
|
||||||
Dir[File.join source, '{release,updates}', '*.src.rpm'].each do |srpm_file|
|
Dir[File.join source, '*.src.rpm'].each do |srpm_file|
|
||||||
print "Processing '#{srpm_file}'... "
|
print "Processing '#{srpm_file}'... "
|
||||||
if name = `rpm -q --qf '[%{Name}]' -p #{srpm_file}` and $?.success? and name.present? and
|
if name = `rpm -q --qf '[%{Name}]' -p #{srpm_file}` and $?.success? and name.present? and
|
||||||
version = `rpm -q --qf '[%{Version}-%{Release}]' -p #{srpm_file}` and $?.success? and version.present?
|
version = `rpm -q --qf '[%{Version}-%{Release}]' -p #{srpm_file}` and $?.success? and version.present?
|
||||||
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)
|
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)
|
||||||
if version != project_import.version.to_s and File.mtime(srpm_file) > project_import.file_mtime
|
if version != project_import.version.to_s and File.mtime(srpm_file) > project_import.file_mtime
|
||||||
unless project = project_import.project
|
unless project = project_import.project
|
||||||
if project = repository.projects.find_by_name(name) || repository.projects.by_name(name).first # fallback to speedup
|
if platform.personal? # search project through owner # used for testhat
|
||||||
print "Found project #{project.owner.uname}/#{project.name} in #{platform.name}/#{repository.name}. "
|
project = Project.find_or_create_by_name_and_owner_type_and_owner_id(name, owner.class.to_s, owner.id)
|
||||||
elsif scoped = Project.where(:owner_id => owner.id, :owner_type => owner.class) and
|
print "Use project #{project.owner.uname}/#{project.name}. "
|
||||||
project = scoped.find_by_name(name) || scoped.by_name(name).first
|
else # search project through repository
|
||||||
repository.projects << project
|
if project = repository.projects.find_by_name(name) || repository.projects.by_name(name).first # fallback to speedup
|
||||||
print "Add project #{project.owner.uname}/#{project.name} to #{platform.name}/#{repository.name}. "
|
print "Found project #{project.owner.uname}/#{project.name} in #{platform.name}/#{repository.name}. "
|
||||||
else
|
elsif scoped = Project.where(:owner_id => owner.id, :owner_type => owner.class) and
|
||||||
description = ::Iconv.conv('UTF-8//IGNORE', 'UTF-8', `rpm -q --qf '[%{Description}]' -p #{srpm_file}`)
|
project = scoped.find_by_name(name) || scoped.by_name(name).first
|
||||||
project = Project.create!(:name => name, :description => description) {|p| p.owner = owner}
|
repository.projects << project
|
||||||
repository.projects << project
|
print "Add project #{project.owner.uname}/#{project.name} to #{platform.name}/#{repository.name}. "
|
||||||
print "Create project #{project.owner.uname}/#{project.name} at #{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
|
||||||
|
print "Create project #{project.owner.uname}/#{project.name} at #{platform.name}/#{repository.name}. "
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
project.import_srpm(srpm_file, branch)
|
project.import_srpm(srpm_file, branch)
|
||||||
|
|
Loading…
Reference in New Issue