Added mock build. Part 5
This commit is contained in:
122
classes/mock.rb
122
classes/mock.rb
@@ -1,15 +1,21 @@
|
||||
require_relative "spork"
|
||||
require_relative "runner"
|
||||
require "fileutils"
|
||||
require "logger"
|
||||
|
||||
BUILD_STRUCTURE = {
|
||||
:SRC => "src",
|
||||
:RPMS => "rpms",
|
||||
:RESULT => "result",
|
||||
:RESULT_SRPM => "result_srpm",
|
||||
}
|
||||
|
||||
#
|
||||
#mock -r /home/alexey/workspace/ruby-projects/mock-gui/projects/prjt1.prj/configs/prjt1.cfg --buildsrpm --spec srcprp/bayrepo_neuro_farm.spec --sources srcprp/ --resultdir result/ --isolation=simple --disable-plugin=ccache
|
||||
#mock -r /home/alexey/workspace/ruby-projects/mock-gui/projects/prjt1.prj/configs/prjt1.cfg result/bayrepo-neuro-farm-0.1-2.src.rpm --resultdir result2/ --isolation simple
|
||||
|
||||
class MockManager
|
||||
attr :path, :config, :error, :last_status, :last_pid, :prep_dir, :db, :resultpath, :process_log, :repo_path
|
||||
attr :path, :config, :error, :last_status, :last_pid, :prep_dir, :db, :resultpath, :process_log, :repo_path, :git_path, :build_id, :log, :recips, :spec, :repo_lock
|
||||
|
||||
def initialize(path, config, cfg_counter_path, db, result_path, repo_path)
|
||||
def initialize(path, config, cfg_counter_path, db, result_path, repo_path, git_path, build_id, recips, spec_file, repo_lock)
|
||||
@error = nil
|
||||
unless File.exist? (path)
|
||||
Dir.mkdir(path)
|
||||
@@ -20,6 +26,11 @@ class MockManager
|
||||
@db = db
|
||||
@resultpath = result_path
|
||||
@repo_path = repo_path
|
||||
@git_path = git_path
|
||||
@build_id = build_id
|
||||
@recips = recips
|
||||
@spec = spec_file
|
||||
@repo_lock = repo_lock
|
||||
|
||||
File.open(cfg_counter_path, "r+") do |f|
|
||||
f.flock(File::LOCK_EX)
|
||||
@@ -34,6 +45,7 @@ class MockManager
|
||||
@process_log = File.join(@prep_dir, "process.log")
|
||||
Dir.mkdir(@prep_dir)
|
||||
FileUtils.touch(@process_log)
|
||||
@log = nil
|
||||
end
|
||||
|
||||
def get_build_process_log()
|
||||
@@ -41,10 +53,110 @@ class MockManager
|
||||
end
|
||||
|
||||
def finalize_build_task()
|
||||
@log.close
|
||||
end
|
||||
|
||||
def clean_build
|
||||
@log.info("Удаление временной сборочной среды #{@path}")
|
||||
FileUtils.rm_rf(@path)
|
||||
end
|
||||
|
||||
def prepare_structure()
|
||||
@log.info("Подготовка структуры каталогов")
|
||||
BUILD_STRUCTURE.each_pair do |key, value|
|
||||
new_path = File.join(@prep_dir, value)
|
||||
@log.info("Создан каталог #{new_path}")
|
||||
Dir.mkdir(new_path)
|
||||
end
|
||||
end
|
||||
|
||||
def prepare_src()
|
||||
@log.info("Подготовка исходных файлов проекта к формированию SRPMS")
|
||||
if File.exist?(@git_path)
|
||||
if File.directory?(@git_path)
|
||||
FileUtils.cp_r(@git_path, File.join(@prep_dir, BUILD_STRUCTURE[:SRC]), verbose: true, remove_destination: true)
|
||||
FileUtils.rm_rf(File.join(@prep_dir, BUILD_STRUCTURE[:SRC], ".git"), secure: true)
|
||||
else
|
||||
@log.error("Это файл #{@git_path}, а не каталог")
|
||||
@error = true
|
||||
end
|
||||
else
|
||||
@log.error("Каталог #{@git_path} не существует")
|
||||
@error = true
|
||||
end
|
||||
end
|
||||
|
||||
def prepare_source()
|
||||
@log.info("Запукс подготовительных скриптов")
|
||||
@recips.each_with_index do |item, index|
|
||||
@log.info("Формируем рецепт #{item[:filepath]}")
|
||||
rcp_name = "#{index}rcp_#{item[:filepath]}"
|
||||
File.open(File.join(@prep_dir, BUILD_STRUCTURE[:SRC], rcp_name)) do |f|
|
||||
f.write(item[:content])
|
||||
end
|
||||
Dir.chdir(File.join(@prep_dir, BUILD_STRUCTURE[:SRC])) do
|
||||
script = File.join(@prep_dir, BUILD_STRUCTURE[:SRC], rcp_name)
|
||||
cmd_args = %Q(/usr/bin/bash -x "#{script}")
|
||||
cmd = Runner.new(cmd_args, @log)
|
||||
cmd.run_clean
|
||||
@error = true if cmd.exit_status != 0
|
||||
end
|
||||
break if @error
|
||||
end
|
||||
end
|
||||
|
||||
def prepare_src_rpm()
|
||||
@log.info("Подготовка SRCRPM")
|
||||
spec_file = File.join(@prep_dir, BUILD_STRUCTURE[:SRC], @spec)
|
||||
if File.exist?(spec_file)
|
||||
Dir.chdir(File.join(@prep_dir, BUILD_STRUCTURE[:SRC])) do
|
||||
script = File.join(@prep_dir, BUILD_STRUCTURE[:SRC], rcp_name)
|
||||
cmd_args = %Q(/usr/bin/mock -r #{@config} --buildsrpm --spec #{spec_file} --sources #{File.join(@prep_dir, BUILD_STRUCTURE[:SRC])} --resultdir #{File.join(@prep_dir, BUILD_STRUCTURE[:RESULT_SRPM])} --isolation=simple --disable-plugin=ccache")
|
||||
cmd = Runner.new(cmd_args, @log)
|
||||
cmd.run_clean
|
||||
@error = true if cmd.exit_status != 0
|
||||
end
|
||||
else
|
||||
@error = true
|
||||
@log.error("Не могу найти sepc файл #{spec_file}")
|
||||
end
|
||||
end
|
||||
|
||||
def build_rpm()
|
||||
end
|
||||
|
||||
def save_logs()
|
||||
end
|
||||
|
||||
def save_rpms()
|
||||
File.open(@repo_lock, File::RDWR | File::CREAT) do |f|
|
||||
f.flock(File::LOCK_EX)
|
||||
# выклдака пакетов и пересоздание repodata
|
||||
end
|
||||
end
|
||||
|
||||
def build_task()
|
||||
finalize_build_task
|
||||
@error = false
|
||||
@db.before_fork
|
||||
spock = Spork.spork(:logger => log) do
|
||||
@db.after_fork
|
||||
$stdout = File.open(@process_log, "w")
|
||||
@log = Logger.new($stdout)
|
||||
if @sepc == ""
|
||||
@error = true
|
||||
@log.error("Не могу найти spec файл")
|
||||
end
|
||||
prepare_structure if @error == false
|
||||
prepare_src if @error == false
|
||||
prepare_source if @error == false
|
||||
prepare_src_rpm if @error == false
|
||||
build_rpm if @error == false
|
||||
save_logs
|
||||
save_rpms if @error == false
|
||||
clean_build
|
||||
@log.close
|
||||
end
|
||||
@db.after_fork
|
||||
spock
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user