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
|
|
|
|
platform = Platform.main.find id
|
|
|
|
@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|
|
2014-10-01 20:33:07 +01:00
|
|
|
%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
|
|
|
|
|
2014-10-01 20:33:07 +01:00
|
|
|
def create_empty_metadata(platform, path)
|
2014-09-30 21:05:53 +01:00
|
|
|
case platform.distrib_type
|
|
|
|
when 'rhel'
|
2014-10-01 20:33:07 +01:00
|
|
|
path << '/repodata/'
|
2014-09-30 21:05:53 +01:00
|
|
|
when 'mdv'
|
2014-10-01 20:33:07 +01:00
|
|
|
path << '/media_info/'
|
2014-09-30 21:05:53 +01:00
|
|
|
else
|
|
|
|
return
|
|
|
|
end
|
2014-10-01 20:33:07 +01:00
|
|
|
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
|
|
|
|
@platforms ||= Platform.main.to_a
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|