rosa-build/app/jobs/create_empty_metadata_job.rb

71 lines
1.8 KiB
Ruby
Raw Normal View History

2014-09-30 21:05:53 +01:00
class CreateEmptyMetadataJob < Struct.new(:class_name, :id)
@queue = :low
def perform
case class_name
when Platform.name
create_empty_metadata_for_platform
when Repository.name
create_empty_metadata_for_repository Repository.find(id)
end
end
def self.perform(class_name, id)
new(class_name, id).perform
end
private
def create_empty_metadata_for_platform
2014-10-01 21:10:05 +01:00
platform = Platform.main.opened.find id
2014-09-30 21:05:53 +01:00
@platforms = [platform]
repositories = Repository.joins(:platform).
where(platforms: { platform_type: Platform::TYPE_PERSONAL })
repositories.find_each do |r|
create_empty_metadata_for_repository r
end
end
def create_empty_metadata_for_repository(repository)
@platforms = [repository.platform] if repository.platform.main?
platforms.each do |platform|
arch_names.each do |arch_name|
%w(release updates).each do |type|
path = "#{ repository.platform.path }/repository/"
path << "#{ platform.name }/" if repository.platform.personal?
path << "#{ arch_name }/#{ repository.name }/#{ type }"
create_empty_metadata(platform, path)
2014-09-30 21:05:53 +01:00
end
end
end
end
def create_empty_metadata(platform, path)
2014-09-30 21:05:53 +01:00
case platform.distrib_type
when 'rhel'
path << '/repodata/'
2014-09-30 21:05:53 +01:00
when 'mdv'
path << '/media_info/'
2014-09-30 21:05:53 +01:00
else
return
end
if Dir["#{ path }/*"].empty?
2014-09-30 21:05:53 +01:00
system "mkdir -p -m 0777 #{ path }"
system "cp -f #{ empty_metadatas(platform) }/* #{ path }/"
end
end
def empty_metadatas(platform)
Rails.root.join('public', 'metadatas', platform.distrib_type).to_s
end
def arch_names
@arch_names ||= Arch.pluck(:name)
end
def platforms
2014-10-01 21:10:05 +01:00
@platforms ||= Platform.main.opened.to_a
2014-09-30 21:05:53 +01:00
end
end