#432: added CreateEmptyMetadataJob
This commit is contained in:
parent
6339880d49
commit
310eb0ec38
|
@ -0,0 +1,72 @@
|
||||||
|
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|
|
||||||
|
[repository.name, "debug_#{repository.name}"].each do |repository_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(repository, platform, path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_empty_metadata(repository, platform, path)
|
||||||
|
case platform.distrib_type
|
||||||
|
when 'rhel'
|
||||||
|
path << 'repodata/'
|
||||||
|
when 'mdv'
|
||||||
|
path << 'media_info/'
|
||||||
|
else
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if Dir["#{path}/*"].empty?
|
||||||
|
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
|
|
@ -0,0 +1,13 @@
|
||||||
|
module EmptyMetadata
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
included do
|
||||||
|
after_create :create_empty_metadata
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_empty_metadata
|
||||||
|
return if is_a?(Platform) && personal?
|
||||||
|
Resque.enqueue(CreateEmptyMetadataJob, self.class.name, id)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -11,9 +11,9 @@ module PersonalRepository
|
||||||
pl.owner = self
|
pl.owner = self
|
||||||
pl.name = "#{self.uname}_personal"
|
pl.name = "#{self.uname}_personal"
|
||||||
pl.description = "#{self.uname}_personal"
|
pl.description = "#{self.uname}_personal"
|
||||||
pl.platform_type = 'personal'
|
pl.platform_type = Platform::TYPE_PERSONAL
|
||||||
pl.distrib_type = APP_CONFIG['distr_types'].first
|
pl.distrib_type = APP_CONFIG['distr_types'].first
|
||||||
pl.visibility = 'open'
|
pl.visibility = Platform::VISIBILITY_OPEN
|
||||||
pl.save!
|
pl.save!
|
||||||
|
|
||||||
rep = pl.repositories.build
|
rep = pl.repositories.build
|
||||||
|
|
|
@ -6,12 +6,21 @@ class Platform < ActiveRecord::Base
|
||||||
include RegenerationStatus
|
include RegenerationStatus
|
||||||
include Owner
|
include Owner
|
||||||
include EventLoggable
|
include EventLoggable
|
||||||
|
include EmptyMetadata
|
||||||
|
|
||||||
CACHED_CHROOT_PRODUCT_NAME = 'cached-chroot'
|
CACHED_CHROOT_PRODUCT_NAME = 'cached-chroot'
|
||||||
AUTOMATIC_METADATA_REGENERATIONS = %w(day week)
|
AUTOMATIC_METADATA_REGENERATIONS = %w(day week)
|
||||||
VISIBILITIES = %w(open hidden)
|
VISIBILITIES = [
|
||||||
|
VISIBILITY_OPEN = 'open',
|
||||||
|
VISIBILITY_HIDDEN = 'hidden'
|
||||||
|
]
|
||||||
NAME_PATTERN = /[\w\-\.]+/
|
NAME_PATTERN = /[\w\-\.]+/
|
||||||
HUMAN_STATUSES = HUMAN_STATUSES.clone.freeze
|
HUMAN_STATUSES = HUMAN_STATUSES.clone.freeze
|
||||||
|
TYPES = [
|
||||||
|
TYPE_PERSONAL = 'personal',
|
||||||
|
TYPE_MAIN = 'main'
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
belongs_to :parent, class_name: 'Platform', foreign_key: 'parent_platform_id'
|
belongs_to :parent, class_name: 'Platform', foreign_key: 'parent_platform_id'
|
||||||
belongs_to :owner, polymorphic: true
|
belongs_to :owner, polymorphic: true
|
||||||
|
@ -32,16 +41,36 @@ class Platform < ActiveRecord::Base
|
||||||
|
|
||||||
has_many :mass_builds, foreign_key: :save_to_platform_id
|
has_many :mass_builds, foreign_key: :save_to_platform_id
|
||||||
|
|
||||||
validates :description, presence: true
|
validates :description,
|
||||||
validates :visibility, presence: true, inclusion: { in: VISIBILITIES }
|
presence: true
|
||||||
validates :automatic_metadata_regeneration, inclusion: { in: AUTOMATIC_METADATA_REGENERATIONS }, allow_blank: true
|
|
||||||
validates :name, uniqueness: {case_sensitive: false}, presence: true, format: { with: /\A#{NAME_PATTERN}\z/ }
|
validates :visibility,
|
||||||
validates :distrib_type, presence: true, inclusion: { in: APP_CONFIG['distr_types'] }
|
presence: true,
|
||||||
|
inclusion: { in: VISIBILITIES }
|
||||||
|
|
||||||
|
validates :platform_type,
|
||||||
|
presence: true,
|
||||||
|
inclusion: { in: TYPES }
|
||||||
|
|
||||||
|
validates :automatic_metadata_regeneration,
|
||||||
|
inclusion: { in: AUTOMATIC_METADATA_REGENERATIONS },
|
||||||
|
allow_blank: true
|
||||||
|
|
||||||
|
validates :name,
|
||||||
|
uniqueness: { case_sensitive: false },
|
||||||
|
presence: true,
|
||||||
|
format: { with: /\A#{NAME_PATTERN}\z/ }
|
||||||
|
|
||||||
|
validates :distrib_type,
|
||||||
|
presence: true,
|
||||||
|
inclusion: { in: APP_CONFIG['distr_types'] }
|
||||||
|
|
||||||
validate -> {
|
validate -> {
|
||||||
if released_was && !released
|
if released_was && !released
|
||||||
errors.add(:released, I18n.t('flash.platform.released_status_can_not_be_changed'))
|
errors.add(:released, I18n.t('flash.platform.released_status_can_not_be_changed'))
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
validate -> {
|
validate -> {
|
||||||
if personal? && (owner_id_changed? || owner_type_changed?)
|
if personal? && (owner_id_changed? || owner_type_changed?)
|
||||||
errors.add :owner, I18n.t('flash.platform.owner_can_not_be_changed')
|
errors.add :owner, I18n.t('flash.platform.owner_can_not_be_changed')
|
||||||
|
@ -58,17 +87,27 @@ class Platform < ActiveRecord::Base
|
||||||
after_destroy -> { remove_symlink_directory unless hidden? }
|
after_destroy -> { remove_symlink_directory unless hidden? }
|
||||||
|
|
||||||
scope :search_order, -> { order(:name) }
|
scope :search_order, -> { order(:name) }
|
||||||
scope :search, ->(q) { where("#{table_name}.name ILIKE ?", "%#{q.to_s.strip}%") }
|
scope :search, -> (q) { where("#{table_name}.name ILIKE ?", "%#{q.to_s.strip}%") }
|
||||||
scope :by_visibilities, ->(v) { where(visibility: v) }
|
scope :by_visibilities, -> (v) { where(visibility: v) }
|
||||||
scope :opened, -> { where(visibility: 'open') }
|
scope :opened, -> { where(visibility: VISIBILITY_OPEN) }
|
||||||
scope :hidden, -> { where(visibility: 'hidden') }
|
scope :hidden, -> { where(visibility: VISIBILITY_HIDDEN) }
|
||||||
scope :by_type, ->(type) { where(platform_type: type) if type.present? }
|
scope :by_type, -> (type) { where(platform_type: type) if type.present? }
|
||||||
scope :main, -> { by_type('main') }
|
scope :main, -> { by_type(TYPE_MAIN) }
|
||||||
scope :personal, -> { by_type('personal') }
|
scope :personal, -> { by_type(TYPE_PERSONAL) }
|
||||||
scope :waiting_for_regeneration, -> { where(status: WAITING_FOR_REGENERATION) }
|
scope :waiting_for_regeneration, -> { where(status: WAITING_FOR_REGENERATION) }
|
||||||
|
|
||||||
accepts_nested_attributes_for :platform_arch_settings, allow_destroy: true
|
accepts_nested_attributes_for :platform_arch_settings, allow_destroy: true
|
||||||
attr_accessible :name, :distrib_type, :parent_platform_id, :platform_type, :owner, :visibility, :description, :released, :platform_arch_settings_attributes, :automatic_metadata_regeneration
|
attr_accessible :name,
|
||||||
|
:distrib_type,
|
||||||
|
:parent_platform_id,
|
||||||
|
:platform_type,
|
||||||
|
:owner,
|
||||||
|
:visibility,
|
||||||
|
:description,
|
||||||
|
:released,
|
||||||
|
:platform_arch_settings_attributes,
|
||||||
|
:automatic_metadata_regeneration
|
||||||
|
|
||||||
attr_readonly :name, :distrib_type, :parent_platform_id, :platform_type
|
attr_readonly :name, :distrib_type, :parent_platform_id, :platform_type
|
||||||
|
|
||||||
state_machine :status, initial: :ready do
|
state_machine :status, initial: :ready do
|
||||||
|
@ -144,15 +183,15 @@ class Platform < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def hidden?
|
def hidden?
|
||||||
visibility == 'hidden'
|
visibility == VISIBILITY_HIDDEN
|
||||||
end
|
end
|
||||||
|
|
||||||
def personal?
|
def personal?
|
||||||
platform_type == 'personal'
|
platform_type == TYPE_PERSONAL
|
||||||
end
|
end
|
||||||
|
|
||||||
def main?
|
def main?
|
||||||
platform_type == 'main'
|
platform_type == TYPE_MAIN
|
||||||
end
|
end
|
||||||
|
|
||||||
def base_clone(attrs = {}) # :description, :name, :owner
|
def base_clone(attrs = {}) # :description, :name, :owner
|
||||||
|
@ -175,10 +214,10 @@ class Platform < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def change_visibility
|
def change_visibility
|
||||||
if !hidden?
|
if hidden?
|
||||||
update_attributes(visibility: 'hidden')
|
update_attributes(visibility: VISIBILITY_OPEN)
|
||||||
else
|
else
|
||||||
update_attributes(visibility: 'open')
|
update_attributes(visibility: VISIBILITY_HIDDEN)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -190,6 +229,7 @@ class Platform < ActiveRecord::Base
|
||||||
File.open(File.join(symlink_path, "#{name}.#{arch.name}.list"), 'w') {|f| f.write(str) }
|
File.open(File.join(symlink_path, "#{name}.#{arch.name}.list"), 'w') {|f| f.write(str) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
later :symlink_directory, queue: :middle
|
||||||
|
|
||||||
def remove_symlink_directory
|
def remove_symlink_directory
|
||||||
system("rm -Rf #{symlink_path}")
|
system("rm -Rf #{symlink_path}")
|
||||||
|
@ -262,7 +302,6 @@ class Platform < ActiveRecord::Base
|
||||||
system("mkdir -p -m 0777 #{build_path([name, 'repository'])}")
|
system("mkdir -p -m 0777 #{build_path([name, 'repository'])}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def build_path(dir)
|
def build_path(dir)
|
||||||
File.join(APP_CONFIG['root_path'], 'platforms', dir)
|
File.join(APP_CONFIG['root_path'], 'platforms', dir)
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,6 +3,7 @@ class Repository < ActiveRecord::Base
|
||||||
friendly_id :name, use: [:finders]
|
friendly_id :name, use: [:finders]
|
||||||
|
|
||||||
include EventLoggable
|
include EventLoggable
|
||||||
|
include EmptyMetadata
|
||||||
|
|
||||||
LOCK_FILE_NAMES = { sync: '.sync.lock', repo: '.repo.lock' }
|
LOCK_FILE_NAMES = { sync: '.sync.lock', repo: '.repo.lock' }
|
||||||
SORT = { 'base' => 1, 'main' => 2, 'contrib' => 3, 'non-free' => 4, 'restricted' => 5 }
|
SORT = { 'base' => 1, 'main' => 2, 'contrib' => 3, 'non-free' => 4, 'restricted' => 5 }
|
||||||
|
@ -66,6 +67,7 @@ class Repository < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
later :clone_relations, loner: true, queue: :low
|
later :clone_relations, loner: true, queue: :low
|
||||||
|
|
||||||
def add_projects(list, user)
|
def add_projects(list, user)
|
||||||
current_ability = Ability.new(user)
|
current_ability = Ability.new(user)
|
||||||
list.lines.each do |line|
|
list.lines.each do |line|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
145c9f725bdcc3ba2f7955b102bce09b synthesis.hdlist.cz
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,28 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<repomd xmlns="http://linux.duke.edu/metadata/repo" xmlns:rpm="http://linux.duke.edu/metadata/rpm">
|
||||||
|
<revision>1412059094</revision>
|
||||||
|
<data type="filelists">
|
||||||
|
<checksum type="sha256">31ad3f2fbe7608dea8c8c7952373ca917bfe00fc729e1f4ecb29fb43c2064f1d</checksum>
|
||||||
|
<open-checksum type="sha256">bf9808b81cb2dbc54b4b8e35adc584ddcaa73bd81f7088d73bf7dbbada961310</open-checksum>
|
||||||
|
<location href="repodata/31ad3f2fbe7608dea8c8c7952373ca917bfe00fc729e1f4ecb29fb43c2064f1d-filelists.xml.gz"/>
|
||||||
|
<timestamp>1412059094</timestamp>
|
||||||
|
<size>186</size>
|
||||||
|
<open-size>125</open-size>
|
||||||
|
</data>
|
||||||
|
<data type="other">
|
||||||
|
<checksum type="sha256">a9769a64dee317b6b67923a4f6c173419e43720cb60f6411d5525382df28605f</checksum>
|
||||||
|
<open-checksum type="sha256">e0ed5e0054194df036cf09c1a911e15bf2a4e7f26f2a788b6f47d53e80717ccc</open-checksum>
|
||||||
|
<location href="repodata/a9769a64dee317b6b67923a4f6c173419e43720cb60f6411d5525382df28605f-other.xml.gz"/>
|
||||||
|
<timestamp>1412059094</timestamp>
|
||||||
|
<size>182</size>
|
||||||
|
<open-size>121</open-size>
|
||||||
|
</data>
|
||||||
|
<data type="primary">
|
||||||
|
<checksum type="sha256">a44e7259aa2c562a139498175f1fc64f8e98d3fda7fa22444b4121cd6e246fb7</checksum>
|
||||||
|
<open-checksum type="sha256">e1e2ffd2fb1ee76f87b70750d00ca5677a252b397ab6c2389137a0c33e7b359f</open-checksum>
|
||||||
|
<location href="repodata/a44e7259aa2c562a139498175f1fc64f8e98d3fda7fa22444b4121cd6e246fb7-primary.xml.gz"/>
|
||||||
|
<timestamp>1412059094</timestamp>
|
||||||
|
<size>195</size>
|
||||||
|
<open-size>167</open-size>
|
||||||
|
</data>
|
||||||
|
</repomd>
|
Loading…
Reference in New Issue