#778: add file_system_worker for repositories and platforms
This commit is contained in:
parent
6a1d43690e
commit
1509910a1f
|
@ -268,7 +268,7 @@ class BuildList < ActiveRecord::Base
|
||||||
type = save_to_platform.distrib_type
|
type = save_to_platform.distrib_type
|
||||||
archive = results.select{ |r| r['file_name'] =~ /.*\.tar\.gz$/}[0]
|
archive = results.select{ |r| r['file_name'] =~ /.*\.tar\.gz$/}[0]
|
||||||
|
|
||||||
platform_path = "#{APP_CONFIG['root_path']}/platforms/#{save_to_platform.name}/repository"
|
platform_path = "#{save_to_platform.path}/repository"
|
||||||
if save_to_platform.personal?
|
if save_to_platform.personal?
|
||||||
platform_path << '/'
|
platform_path << '/'
|
||||||
platform_path << build_for_platform.name
|
platform_path << build_for_platform.name
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
module AbfWorker
|
||||||
|
class FileSystemWorker
|
||||||
|
@queue = :file_system_worker
|
||||||
|
|
||||||
|
def self.perform(options)
|
||||||
|
id, action = options['id'], options['action']
|
||||||
|
case options['type']
|
||||||
|
when 'platform'
|
||||||
|
@runner = AbfWorker::Runners::Platform.new id, action
|
||||||
|
when 'repository'
|
||||||
|
@runner = AbfWorker::Runners::Repository.new id, action
|
||||||
|
when 'project'
|
||||||
|
@runner = AbfWorker::Runners::Project.new id, action
|
||||||
|
end
|
||||||
|
@runner.run
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,20 @@
|
||||||
|
module AbfWorker
|
||||||
|
module Runners
|
||||||
|
class Base
|
||||||
|
|
||||||
|
# @param [String] action The action which should be run (create/destroy)
|
||||||
|
def initialize(action)
|
||||||
|
@action = action
|
||||||
|
end
|
||||||
|
|
||||||
|
def run
|
||||||
|
send @action
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.mk_dir(path)
|
||||||
|
Dir.mkdir(path) unless File.exists?(path)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,25 @@
|
||||||
|
module AbfWorker
|
||||||
|
module Runners
|
||||||
|
class Platform < AbfWorker::Runners::Base
|
||||||
|
|
||||||
|
# @param [String] id The id of platform
|
||||||
|
def initialize(id, action)
|
||||||
|
super action
|
||||||
|
@platform = Platform.find id
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def create
|
||||||
|
platform_path = @platform.path
|
||||||
|
mk_dir(platform_path)
|
||||||
|
['/projects', '/repository'].each{ |f| mk_dir(platform_path + f) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
system("rm -rf #{@platform.path}")
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,82 @@
|
||||||
|
module AbfWorker
|
||||||
|
module Runners
|
||||||
|
class Repository < AbfWorker::Runners::Base
|
||||||
|
|
||||||
|
# @param [String] id The id of repository
|
||||||
|
def initialize(id, action)
|
||||||
|
super action
|
||||||
|
@repository = Repository.find id
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def create
|
||||||
|
platform = @repository.platform
|
||||||
|
repository_path = platform.path
|
||||||
|
repository_path << '/repository'
|
||||||
|
if platform.personal?
|
||||||
|
Platform.main.pluck.each do |main_platform_name|
|
||||||
|
create_file_tree "#{repository_path}/#{main_platform_name}", true
|
||||||
|
end
|
||||||
|
else
|
||||||
|
create_file_tree repository_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
platform = @repository.platform
|
||||||
|
repository_path = platform.path
|
||||||
|
repository_path << '/repository'
|
||||||
|
if platform.personal?
|
||||||
|
Platform.main.pluck.each do |main_platform_name|
|
||||||
|
destroy_repositories "#{repository_path}/#{main_platform_name}"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
destroy_repositories repository_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy_repositories(repository_path)
|
||||||
|
Arch.pluck(:name).each do |arch|
|
||||||
|
system("rm -rf #{repository_path}/#{arch}/#{@repository.name}")
|
||||||
|
end
|
||||||
|
system("rm -rf #{repository_path}/SRPMS/#{@repository.name}")
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_file_tree(repository_path, personal = false)
|
||||||
|
# platforms/rosa2012.1/repository
|
||||||
|
# platforms/test_personal/repository/rosa2012.1
|
||||||
|
mk_dir repository_path
|
||||||
|
Arch.pluck(:name).each do |arch|
|
||||||
|
path = "#{repository_path}/#{arch}"
|
||||||
|
# platforms/rosa2012.1/repository/i586
|
||||||
|
# platforms/test_personal/repository/rosa2012.1/i586
|
||||||
|
mk_dir path
|
||||||
|
path << '/' << @repository.name
|
||||||
|
# platforms/rosa2012.1/repository/i586/main
|
||||||
|
# platforms/test_personal/repository/rosa2012.1/i586/main
|
||||||
|
mk_dir path
|
||||||
|
# platforms/rosa2012.1/repository/i586/main/release
|
||||||
|
# platforms/test_personal/repository/rosa2012.1/i586/main/release
|
||||||
|
mk_dir "#{path}/release"
|
||||||
|
# platforms/rosa2012.1/repository/i586/main/updates
|
||||||
|
mk_dir "#{path}/updates" unless personal
|
||||||
|
end
|
||||||
|
path = "#{repository_path}/SRPMS"
|
||||||
|
# platforms/rosa2012.1/repository/SRPMS
|
||||||
|
# platforms/test_personal/repository/rosa2012.1/SRPMS
|
||||||
|
mk_dir path
|
||||||
|
path << '/' << @repository.name
|
||||||
|
# platforms/rosa2012.1/repository/SRPMS/main
|
||||||
|
# platforms/test_personal/repository/rosa2012.1/SRPMS/main
|
||||||
|
mk_dir path
|
||||||
|
# platforms/rosa2012.1/repository/SRPMS/main/release
|
||||||
|
# platforms/test_personal/repository/rosa2012.1/SRPMS/main/release
|
||||||
|
mk_dir "#{path}/release"
|
||||||
|
# platforms/rosa2012.1/repository/SRPMS/main/updates
|
||||||
|
mk_dir "#{path}/updates" unless personal
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue