Added project to project linking
This commit is contained in:
@@ -188,4 +188,20 @@ class DBase
|
||||
def get_projects_links(prj_id)
|
||||
ProjectsProjects.where(proj_id: prj_id.to_i).all
|
||||
end
|
||||
|
||||
def delete_linked_projects(prj_id)
|
||||
ProjectsProjects.where(proj_id: prj_id.to_i).delete
|
||||
end
|
||||
|
||||
def delete_linked_projects_with_id(prj_id, prj_id_link)
|
||||
ProjectsProjects.where(proj_id: prj_id.to_i, proj_id_repository: prj_id_link.to_i).delete
|
||||
end
|
||||
|
||||
def save_linked_projects(prj_id, prj_id_link)
|
||||
item = ProjectsProjects.where(proj_id: prj_id.to_i, proj_id_repository: prj_id_link.to_i).first
|
||||
if item.nil?
|
||||
id = ProjectsProjects.insert(proj_id: prj_id.to_i, proj_id_repository: prj_id_link.to_i)
|
||||
@last_id = id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
11
classes/mock.rb
Normal file
11
classes/mock.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class MockManager
|
||||
attr :path, :error, :last_status, :last_pid
|
||||
|
||||
def initialize(path)
|
||||
@error = nil
|
||||
unless File.exist? (path)
|
||||
Dir.mkdir(path)
|
||||
end
|
||||
@path = path
|
||||
end
|
||||
end
|
||||
@@ -68,7 +68,7 @@ class ProjectsActions
|
||||
File.join(proj_path, PROJECTS_STRUCTURE[:SRC], gitname)
|
||||
end
|
||||
|
||||
def generate_linked_repos(id, proj_path, proj_name)
|
||||
def generate_linked_repos(id, proj_path, proj_name, linked_repo_tpl)
|
||||
linked_prj = []
|
||||
proj_repo_path = File.join(proj_path, PROJECTS_STRUCTURE[:REPO])
|
||||
proj_repo = <<~PRJ_CFG
|
||||
@@ -99,7 +99,17 @@ class ProjectsActions
|
||||
end
|
||||
end
|
||||
end
|
||||
File.open(prj_incl_path, "w") { |f| f << linked_prj.join("\n\n\n") }
|
||||
File.open(linked_repo_tpl, "w") { |f| f << linked_prj.join("\n\n\n") }
|
||||
end
|
||||
|
||||
def regenerate_linked_repos(id)
|
||||
proj_path = get_project_path(id)
|
||||
config_path = File.join(proj_path, PROJECTS_STRUCTURE[:CONFIGS])
|
||||
prj_incl_path = File.join(config_path, "repos_include.tpl")
|
||||
prj_info = get_project(id)
|
||||
unless prj_info.nil?
|
||||
generate_linked_repos(id, proj_path, prj_info[:projname], prj_incl_path)
|
||||
end
|
||||
end
|
||||
|
||||
def generate_config(id, configuration_path, proj_path, proj_name)
|
||||
@@ -107,7 +117,7 @@ class ProjectsActions
|
||||
conf_path = File.join(proj_path, PROJECTS_STRUCTURE[:CONFIGS])
|
||||
prj_incl_path = File.join(conf_path, "repos_include.tpl")
|
||||
proj_config = <<~PRJ_CFG
|
||||
include("#{configuration}")
|
||||
include("#{configuration_path}")
|
||||
include("#{prj_incl_path}")
|
||||
config_opts['plugin_conf']['ccache_enable'] = True
|
||||
config_opts['plugin_conf']['ccache_opts']['max_cache_size'] = '4G'
|
||||
@@ -121,7 +131,7 @@ class ProjectsActions
|
||||
config_opts['plugin_conf']['yum_cache_enable'] = True
|
||||
PRJ_CFG
|
||||
File.open(proj_conf_path, "w") { |f| f << proj_config }
|
||||
generate_linked_repos(id, proj_path, proj_name)
|
||||
generate_linked_repos(id, proj_path, proj_name, prj_incl_path)
|
||||
end
|
||||
|
||||
def create_project(name, description, configuration)
|
||||
@@ -134,29 +144,29 @@ class ProjectsActions
|
||||
ret_val = 1
|
||||
else
|
||||
created = false
|
||||
begin
|
||||
Dir.mkdir(fname)
|
||||
PROJECTS_STRUCTURE.each_pair do |key, value|
|
||||
new_path = File.join(fname, value)
|
||||
Dir.mkdir(new_path)
|
||||
end
|
||||
if File.exist?(configuration)
|
||||
generate_config(nil, configuration, fname, project_name)
|
||||
@error = @db.proj_create(project_name, description)
|
||||
if @error.nil?
|
||||
created = true
|
||||
end
|
||||
repo_path = File.join(fname, PROJECTS_STRUCTURE[:REPO])
|
||||
repoman = RepoManager.new(repo_path)
|
||||
repoman.create_repo
|
||||
else
|
||||
ret_val = 1
|
||||
@error = "Конфигурация #{configuration} не существует"
|
||||
end
|
||||
rescue => e
|
||||
ret_val = 1
|
||||
@error = e.message
|
||||
#begin
|
||||
Dir.mkdir(fname)
|
||||
PROJECTS_STRUCTURE.each_pair do |key, value|
|
||||
new_path = File.join(fname, value)
|
||||
Dir.mkdir(new_path)
|
||||
end
|
||||
if File.exist?(configuration)
|
||||
generate_config(nil, configuration, fname, project_name)
|
||||
@error = @db.proj_create(project_name, description)
|
||||
if @error.nil?
|
||||
created = true
|
||||
end
|
||||
repo_path = File.join(fname, PROJECTS_STRUCTURE[:REPO])
|
||||
repoman = RepoManager.new(repo_path)
|
||||
repoman.create_repo
|
||||
else
|
||||
ret_val = 1
|
||||
@error = "Конфигурация #{configuration} не существует"
|
||||
end
|
||||
#rescue => e
|
||||
# ret_val = 1
|
||||
# @error = e.message
|
||||
#end
|
||||
unless created
|
||||
FileUtils.rm_rf(fname, secure: true)
|
||||
end
|
||||
@@ -199,4 +209,33 @@ class ProjectsActions
|
||||
end
|
||||
err
|
||||
end
|
||||
|
||||
def get_related_projects_list(prj_id)
|
||||
links_list = []
|
||||
links = @db.get_projects_links(prj_id)
|
||||
unless links.nil?
|
||||
links_list = links.map do |item|
|
||||
prj_info = @db.proj(item[:proj_id_repository])
|
||||
if prj_info.nil?
|
||||
item[:list_state] = false
|
||||
else
|
||||
item[:list_state] = true
|
||||
item[:prj_info] = prj_info
|
||||
end
|
||||
item
|
||||
end.select { |item| item[:list_state] }
|
||||
end
|
||||
links_list
|
||||
end
|
||||
|
||||
def delete_linked_projects(prj_id)
|
||||
@db.delete_linked_projects(prj_id)
|
||||
end
|
||||
|
||||
def save_linked_projects(prj_id, new_ids, delete_ids)
|
||||
delete_ids.each { |item| @db.delete_linked_projects_with_id(prj_id, item) }
|
||||
new_ids.each do |item|
|
||||
@db.save_linked_projects(prj_id, item)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class RepoManager
|
||||
attr :path, :error
|
||||
attr :path, :error, :last_status, :last_pid
|
||||
|
||||
def initialize(path)
|
||||
@error = nil
|
||||
@@ -10,5 +10,10 @@ class RepoManager
|
||||
end
|
||||
|
||||
def create_repo
|
||||
%x(/usr/bin/createrepo_c --database --workers 1 "#{@path}")
|
||||
result = $?
|
||||
@last_status = result.exitstatus
|
||||
@last_pid = result.pid
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user