From 310eb0ec381fd35fab8d4f5ae0c130eecf05dda8 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 1 Oct 2014 00:05:53 +0400 Subject: [PATCH] #432: added CreateEmptyMetadataJob --- app/jobs/create_empty_metadata_job.rb | 72 +++++++++++++ app/models/concerns/empty_metadata.rb | 13 +++ app/models/concerns/personal_repository.rb | 18 ++-- app/models/platform.rb | 97 ++++++++++++------ app/models/repository.rb | 4 +- public/metadatas/mdv/MD5SUM | 1 + public/metadatas/mdv/synthesis.hdlist.cz | Bin 0 -> 20 bytes ...c729e1f4ecb29fb43c2064f1d-filelists.xml.gz | Bin 0 -> 186 bytes ...3fda7fa22444b4121cd6e246fb7-primary.xml.gz | Bin 0 -> 195 bytes ...3720cb60f6411d5525382df28605f-other.xml.gz | Bin 0 -> 182 bytes public/metadatas/rhel/repomd.xml | 28 +++++ 11 files changed, 194 insertions(+), 39 deletions(-) create mode 100644 app/jobs/create_empty_metadata_job.rb create mode 100644 app/models/concerns/empty_metadata.rb create mode 100644 public/metadatas/mdv/MD5SUM create mode 100644 public/metadatas/mdv/synthesis.hdlist.cz create mode 100644 public/metadatas/rhel/31ad3f2fbe7608dea8c8c7952373ca917bfe00fc729e1f4ecb29fb43c2064f1d-filelists.xml.gz create mode 100644 public/metadatas/rhel/a44e7259aa2c562a139498175f1fc64f8e98d3fda7fa22444b4121cd6e246fb7-primary.xml.gz create mode 100644 public/metadatas/rhel/a9769a64dee317b6b67923a4f6c173419e43720cb60f6411d5525382df28605f-other.xml.gz create mode 100644 public/metadatas/rhel/repomd.xml diff --git a/app/jobs/create_empty_metadata_job.rb b/app/jobs/create_empty_metadata_job.rb new file mode 100644 index 000000000..97bd0d1df --- /dev/null +++ b/app/jobs/create_empty_metadata_job.rb @@ -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 diff --git a/app/models/concerns/empty_metadata.rb b/app/models/concerns/empty_metadata.rb new file mode 100644 index 000000000..b073bdfd8 --- /dev/null +++ b/app/models/concerns/empty_metadata.rb @@ -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 diff --git a/app/models/concerns/personal_repository.rb b/app/models/concerns/personal_repository.rb index ed03d9094..f7865d18d 100644 --- a/app/models/concerns/personal_repository.rb +++ b/app/models/concerns/personal_repository.rb @@ -7,17 +7,17 @@ module PersonalRepository def create_personal_repository begin - pl = own_platforms.build - pl.owner = self - pl.name = "#{self.uname}_personal" - pl.description = "#{self.uname}_personal" - pl.platform_type = 'personal' - pl.distrib_type = APP_CONFIG['distr_types'].first - pl.visibility = 'open' + pl = own_platforms.build + pl.owner = self + pl.name = "#{self.uname}_personal" + pl.description = "#{self.uname}_personal" + pl.platform_type = Platform::TYPE_PERSONAL + pl.distrib_type = APP_CONFIG['distr_types'].first + pl.visibility = Platform::VISIBILITY_OPEN pl.save! - rep = pl.repositories.build - rep.name = 'main' + rep = pl.repositories.build + rep.name = 'main' rep.description = 'main' rep.save! rescue Exception => e diff --git a/app/models/platform.rb b/app/models/platform.rb index ee6a6fd40..7ab711098 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -6,12 +6,21 @@ class Platform < ActiveRecord::Base include RegenerationStatus include Owner include EventLoggable + include EmptyMetadata + + CACHED_CHROOT_PRODUCT_NAME = 'cached-chroot' + AUTOMATIC_METADATA_REGENERATIONS = %w(day week) + VISIBILITIES = [ + VISIBILITY_OPEN = 'open', + VISIBILITY_HIDDEN = 'hidden' + ] + NAME_PATTERN = /[\w\-\.]+/ + HUMAN_STATUSES = HUMAN_STATUSES.clone.freeze + TYPES = [ + TYPE_PERSONAL = 'personal', + TYPE_MAIN = 'main' + ] - CACHED_CHROOT_PRODUCT_NAME = 'cached-chroot' - AUTOMATIC_METADATA_REGENERATIONS = %w(day week) - VISIBILITIES = %w(open hidden) - NAME_PATTERN = /[\w\-\.]+/ - HUMAN_STATUSES = HUMAN_STATUSES.clone.freeze belongs_to :parent, class_name: 'Platform', foreign_key: 'parent_platform_id' belongs_to :owner, polymorphic: true @@ -32,16 +41,36 @@ class Platform < ActiveRecord::Base has_many :mass_builds, foreign_key: :save_to_platform_id - validates :description, presence: true - validates :visibility, presence: true, inclusion: { in: VISIBILITIES } - 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'] } + validates :description, + presence: true + + validates :visibility, + 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 -> { if released_was && !released errors.add(:released, I18n.t('flash.platform.released_status_can_not_be_changed')) end } + validate -> { if personal? && (owner_id_changed? || owner_type_changed?) errors.add :owner, I18n.t('flash.platform.owner_can_not_be_changed') @@ -54,22 +83,32 @@ class Platform < ActiveRecord::Base after_update :freeze_platform_and_update_repos after_update :update_owner_relation - after_create -> { symlink_directory unless hidden? } + after_create -> { symlink_directory unless hidden? } after_destroy -> { remove_symlink_directory unless hidden? } - scope :search_order, -> { order(:name) } - scope :search, ->(q) { where("#{table_name}.name ILIKE ?", "%#{q.to_s.strip}%") } - scope :by_visibilities, ->(v) { where(visibility: v) } - scope :opened, -> { where(visibility: 'open') } - scope :hidden, -> { where(visibility: 'hidden') } - scope :by_type, ->(type) { where(platform_type: type) if type.present? } - scope :main, -> { by_type('main') } - scope :personal, -> { by_type('personal') } - scope :waiting_for_regeneration, -> { where(status: WAITING_FOR_REGENERATION) } + scope :search_order, -> { order(:name) } + scope :search, -> (q) { where("#{table_name}.name ILIKE ?", "%#{q.to_s.strip}%") } + scope :by_visibilities, -> (v) { where(visibility: v) } + scope :opened, -> { where(visibility: VISIBILITY_OPEN) } + scope :hidden, -> { where(visibility: VISIBILITY_HIDDEN) } + scope :by_type, -> (type) { where(platform_type: type) if type.present? } + scope :main, -> { by_type(TYPE_MAIN) } + scope :personal, -> { by_type(TYPE_PERSONAL) } + scope :waiting_for_regeneration, -> { where(status: WAITING_FOR_REGENERATION) } 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_readonly :name, :distrib_type, :parent_platform_id, :platform_type + 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 state_machine :status, initial: :ready do @@ -144,15 +183,15 @@ class Platform < ActiveRecord::Base end def hidden? - visibility == 'hidden' + visibility == VISIBILITY_HIDDEN end def personal? - platform_type == 'personal' + platform_type == TYPE_PERSONAL end def main? - platform_type == 'main' + platform_type == TYPE_MAIN end def base_clone(attrs = {}) # :description, :name, :owner @@ -175,10 +214,10 @@ class Platform < ActiveRecord::Base end def change_visibility - if !hidden? - update_attributes(visibility: 'hidden') + if hidden? + update_attributes(visibility: VISIBILITY_OPEN) else - update_attributes(visibility: 'open') + update_attributes(visibility: VISIBILITY_HIDDEN) 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) } end end + later :symlink_directory, queue: :middle def remove_symlink_directory system("rm -Rf #{symlink_path}") @@ -262,7 +302,6 @@ class Platform < ActiveRecord::Base system("mkdir -p -m 0777 #{build_path([name, 'repository'])}") end - def build_path(dir) File.join(APP_CONFIG['root_path'], 'platforms', dir) end diff --git a/app/models/repository.rb b/app/models/repository.rb index cb9fc2b36..c337f9750 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -3,6 +3,7 @@ class Repository < ActiveRecord::Base friendly_id :name, use: [:finders] include EventLoggable + include EmptyMetadata LOCK_FILE_NAMES = { sync: '.sync.lock', repo: '.repo.lock' } SORT = { 'base' => 1, 'main' => 2, 'contrib' => 3, 'non-free' => 4, 'restricted' => 5 } @@ -28,7 +29,7 @@ class Repository < ActiveRecord::Base scope :recent, -> { order(:name) } scope :main, -> { where(name: %w(main base)) } - before_destroy :detele_directory + before_destroy :detele_directory attr_accessible :name, :description, @@ -66,6 +67,7 @@ class Repository < ActiveRecord::Base end end later :clone_relations, loner: true, queue: :low + def add_projects(list, user) current_ability = Ability.new(user) list.lines.each do |line| diff --git a/public/metadatas/mdv/MD5SUM b/public/metadatas/mdv/MD5SUM new file mode 100644 index 000000000..5945ea5b1 --- /dev/null +++ b/public/metadatas/mdv/MD5SUM @@ -0,0 +1 @@ +145c9f725bdcc3ba2f7955b102bce09b synthesis.hdlist.cz diff --git a/public/metadatas/mdv/synthesis.hdlist.cz b/public/metadatas/mdv/synthesis.hdlist.cz new file mode 100644 index 0000000000000000000000000000000000000000..5b1c7aae876f5b057630e674d7440cca7e5009b6 GIT binary patch literal 20 Ucmb2|=3uyZODlwlnVA6w04^Q^vm`>DKwVNpXFOX3F-7 fNe-^xKOdB_Sid76GfQK+{j0p437yAlfi4CB?-xq| literal 0 HcmV?d00001 diff --git a/public/metadatas/rhel/a44e7259aa2c562a139498175f1fc64f8e98d3fda7fa22444b4121cd6e246fb7-primary.xml.gz b/public/metadatas/rhel/a44e7259aa2c562a139498175f1fc64f8e98d3fda7fa22444b4121cd6e246fb7-primary.xml.gz new file mode 100644 index 0000000000000000000000000000000000000000..2d39f07ee07cf0c010cb35b5858c2486a34aa5fd GIT binary patch literal 195 zcmb2|=HOre0;d1^8Tq-X`X#BwC8K z|NlCh%HaH4{Q^f1#cp5V5%a|{jeGs`lIjB%Cbq$D{gRi%w#*8VGE bCwIp0v6FCmykp#l`&-Pv7Mh%|1iBUg_f|-4 literal 0 HcmV?d00001 diff --git a/public/metadatas/rhel/repomd.xml b/public/metadatas/rhel/repomd.xml new file mode 100644 index 000000000..96b5f894a --- /dev/null +++ b/public/metadatas/rhel/repomd.xml @@ -0,0 +1,28 @@ + + + 1412059094 + + 31ad3f2fbe7608dea8c8c7952373ca917bfe00fc729e1f4ecb29fb43c2064f1d + bf9808b81cb2dbc54b4b8e35adc584ddcaa73bd81f7088d73bf7dbbada961310 + + 1412059094 + 186 + 125 + + + a9769a64dee317b6b67923a4f6c173419e43720cb60f6411d5525382df28605f + e0ed5e0054194df036cf09c1a911e15bf2a4e7f26f2a788b6f47d53e80717ccc + + 1412059094 + 182 + 121 + + + a44e7259aa2c562a139498175f1fc64f8e98d3fda7fa22444b4121cd6e246fb7 + e1e2ffd2fb1ee76f87b70750d00ca5677a252b397ab6c2389137a0c33e7b359f + + 1412059094 + 195 + 167 + +