Added project spec seting
This commit is contained in:
48
app.rb
48
app.rb
@@ -621,8 +621,16 @@ get "/gitspec/:id/:git_id" do
|
||||
print_error_page(503, "Путь к проектам не существует")
|
||||
else
|
||||
git_info = repo.get_repo_short_info_by_id(params["git_id"].to_i)
|
||||
@spec_file = db.get_project_repo_spec(params["id"], params["git_id"])
|
||||
spec_f = db.get_project_repo_spec(params["id"], params["git_id"])
|
||||
if spec_f.nil?
|
||||
@spec_file = ""
|
||||
else
|
||||
@spec_file = spec_f[:spec_name]
|
||||
end
|
||||
@page_name = "#{prj_info[:projname]} редактирование spec для git проекта #{git_info[:reponame]}"
|
||||
@proj_name = prj_info[:projname]
|
||||
@proj_descr = prj_info[:descr]
|
||||
@git_name = git_info[:reponame]
|
||||
@proj_id = prj_info[:id]
|
||||
@git_id = git_info[:id]
|
||||
git_path = prj.get_project_path_git(prj_info[:id], git_info[:reponame])
|
||||
@@ -638,6 +646,44 @@ get "/gitspec/:id/:git_id" do
|
||||
end
|
||||
end
|
||||
|
||||
post "/gitspec/:id/:git_id" do
|
||||
prj = ProjectsActions.new(cfg.get_projects_path, db)
|
||||
if prj.path.nil?
|
||||
print_error_page(503, "Путь к проектам не существует")
|
||||
else
|
||||
repo = GitRepo.new(cfg.get_repo, db)
|
||||
if repo.path.nil?
|
||||
print_error_page(503, "Путь к репозиториям не существует")
|
||||
else
|
||||
prj_info = prj.get_project(params["id"])
|
||||
if prj_info.nil?
|
||||
print_error_page(503, "Путь к проектам не существует")
|
||||
else
|
||||
git_info = repo.get_repo_short_info_by_id(params["git_id"].to_i)
|
||||
unless params["cancel"].nil?
|
||||
redirect "/prjedit/#{params["id"]}"
|
||||
else
|
||||
unless params["save"].nil?
|
||||
save_spec = ""
|
||||
if params["useCustom"].nil?
|
||||
save_spec = params["filelst"].strip
|
||||
else
|
||||
save_spec = params["speccustom"].strip
|
||||
end
|
||||
if save_spec != ""
|
||||
db.save_project_repo_spec(prj_info[:id], git_info[:id], save_spec)
|
||||
end
|
||||
redirect "/prjedit/#{params["id"]}"
|
||||
else
|
||||
db.delete_project_repo_spec(prj_info[:id], git_info[:id])
|
||||
redirect "/prjedit/#{params["id"]}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
not_found do
|
||||
status 404
|
||||
@page_name = "Кто-то потерялся"
|
||||
|
||||
@@ -21,6 +21,9 @@ end
|
||||
class ProjectsReposSpec < Sequel::Model(:projects_repos_spec)
|
||||
end
|
||||
|
||||
class ProjectsProjects < Sequel::Model(:projects_projects)
|
||||
end
|
||||
|
||||
class DBase
|
||||
attr :error, :last_id
|
||||
|
||||
@@ -166,4 +169,23 @@ class DBase
|
||||
def get_project_repo_spec(prj_id, git_id)
|
||||
ProjectsReposSpec.where(proj_id: prj_id.to_i, repo_id: git_id.to_i).first
|
||||
end
|
||||
|
||||
def save_project_repo_spec(prj_id, git_id, spec)
|
||||
rep = ProjectsReposSpec.where(proj_id: prj_id.to_i, repo_id: git_id.to_i).first
|
||||
if rep.nil?
|
||||
id = ProjectsReposSpec.insert(proj_id: prj_id.to_i, repo_id: git_id.to_i, spec_name: spec)
|
||||
@last_id = id
|
||||
else
|
||||
ProjectsReposSpec.where(proj_id: prj_id.to_i, repo_id: git_id.to_i).update(spec_name: spec)
|
||||
@last_id = nil
|
||||
end
|
||||
end
|
||||
|
||||
def delete_project_repo_spec(prj_id, git_id)
|
||||
ProjectsReposSpec.where(proj_id: prj_id.to_i, repo_id: git_id.to_i).delete
|
||||
end
|
||||
|
||||
def get_projects_links(prj_id)
|
||||
ProjectsProjects.where(proj_id: prj_id.to_i).all
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,8 +24,6 @@ class GitRepo
|
||||
def create_git(project_name, description)
|
||||
@error = nil
|
||||
ret_val = 0
|
||||
File.open("locks/gitcreate", "r") do |f|
|
||||
f.flock(File::LOCK_EX)
|
||||
fname = File.expand_path("#{project_name}.git", @path)
|
||||
if File.exist?(fname)
|
||||
@error = "Репозиторий с таким именем уже существует: #{project_name}"
|
||||
@@ -47,7 +45,6 @@ class GitRepo
|
||||
FileUtils.rm_rf(fname, secure: true)
|
||||
end
|
||||
end
|
||||
end
|
||||
ret_val
|
||||
end
|
||||
|
||||
@@ -58,8 +55,6 @@ class GitRepo
|
||||
|
||||
def getrepos
|
||||
repos_data = []
|
||||
File.open("locks/gitcreate", "r") do |f|
|
||||
f.flock(File::LOCK_SH)
|
||||
repos_files = Dir[File.join(@path, "*.git")]
|
||||
repos_files.each do |fl|
|
||||
repo_name = File.basename(fl, ".git")
|
||||
@@ -74,7 +69,6 @@ class GitRepo
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
repos_data
|
||||
end
|
||||
|
||||
@@ -84,8 +78,6 @@ class GitRepo
|
||||
@error = nil
|
||||
repos_data = { :full => 0 }
|
||||
git_path = File.join(@path, reponame + ".git")
|
||||
File.open("locks/gitcreate", "r") do |f|
|
||||
f.flock(File::LOCK_SH)
|
||||
if File.exist?(git_path)
|
||||
repo = Rugged::Repository.new(git_path)
|
||||
db_info = @db.get_repo_info_by_name(reponame)
|
||||
@@ -131,21 +123,17 @@ class GitRepo
|
||||
else
|
||||
@error = "Репозиторий отсутсвует"
|
||||
end
|
||||
end
|
||||
info[:error] = @error
|
||||
info
|
||||
end
|
||||
|
||||
def delete_repo(reponame)
|
||||
git_path = File.expand_path(reponame + ".git", @path)
|
||||
File.open("locks/gitcreate", "r") do |f|
|
||||
f.flock(File::LOCK_EX)
|
||||
if File.exist?(git_path)
|
||||
FileUtils.rm_rf(git_path, secure: true)
|
||||
@db.delete_repo_by_name(reponame)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def get_repo_short_info_by_id(id)
|
||||
@db.get_repo_info_by_id(id)
|
||||
@@ -155,8 +143,6 @@ class GitRepo
|
||||
@error = nil
|
||||
repo_info = @db.get_repo_info_by_id(id)
|
||||
unless repo_info.nil?
|
||||
File.open("locks/gitcreate", "r") do |f|
|
||||
f.flock(File::LOCK_SH)
|
||||
git_path = File.join(@path, repo_info[:reponame] + ".git")
|
||||
if File.exist?(git_path)
|
||||
repo = Rugged::Repository.new(git_path)
|
||||
@@ -172,7 +158,6 @@ class GitRepo
|
||||
else
|
||||
@error = "Файла репозитория не существует"
|
||||
end
|
||||
end
|
||||
else
|
||||
@error = "Нет информации о репозитории"
|
||||
end
|
||||
@@ -182,12 +167,9 @@ class GitRepo
|
||||
def is_repos_sync(repo_name, prj_repo_path)
|
||||
res = false
|
||||
repo = Rugged::Repository.new(prj_repo_path)
|
||||
File.open("locks/gitcreate", "r") do |f|
|
||||
f.flock(File::LOCK_SH)
|
||||
git_path = File.join(@path, repo_name + ".git")
|
||||
bare_repo = Rugged::Repository.new(git_path)
|
||||
res = (bare_repo.head.target.tree.oid == repo.head.target.tree.oid)
|
||||
end
|
||||
res
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
require "fileutils"
|
||||
require_relative "db"
|
||||
require_relative "repomanage"
|
||||
|
||||
PROJECTS_STRUCTURE = {
|
||||
:REPO => "repo",
|
||||
@@ -30,21 +31,11 @@ class ProjectsActions
|
||||
end
|
||||
|
||||
def get_projects
|
||||
prj = []
|
||||
File.open("locks/prjcreate", "r") do |f|
|
||||
f.flock(File::LOCK_SH)
|
||||
prj = @db.proj_list
|
||||
end
|
||||
prj
|
||||
@db.proj_list
|
||||
end
|
||||
|
||||
def get_project(id)
|
||||
prj = nil
|
||||
File.open("locks/prjcreate", "r") do |f|
|
||||
f.flock(File::LOCK_SH)
|
||||
prj = @db.proj(id.to_i)
|
||||
end
|
||||
prj
|
||||
@db.proj(id.to_i)
|
||||
end
|
||||
|
||||
def get_project_path(id)
|
||||
@@ -77,12 +68,66 @@ class ProjectsActions
|
||||
File.join(proj_path, PROJECTS_STRUCTURE[:SRC], gitname)
|
||||
end
|
||||
|
||||
def generate_linked_repos(id, proj_path, proj_name)
|
||||
linked_prj = []
|
||||
proj_repo_path = File.join(proj_path, PROJECTS_STRUCTURE[:REPO])
|
||||
proj_repo = <<~PRJ_CFG
|
||||
[#{proj_name}-repository]
|
||||
name=Project repository #{proj_name}
|
||||
baseurl=file://#{proj_repo_path}
|
||||
enabled=1
|
||||
priority=80
|
||||
skip_if_unavailable=True
|
||||
PRJ_CFG
|
||||
linked_prj << proj_repo
|
||||
unless id.nil?
|
||||
link_prj_list = @db.get_projects_links(id)
|
||||
unless link_prj_list.nil?
|
||||
link_prj_list.each do |item|
|
||||
internal_repo = ProjectsActions.new(@path, @db)
|
||||
internal_path = internal_repo.get_project_path(item[:proj_id_repository])
|
||||
internal_repo_path = File.join(internal_path, PROJECTS_STRUCTURE[:REPO])
|
||||
internal_proj_info = internal_repo.get_project(item[:proj_id_repository])
|
||||
proj_repo = <<~PRJ_CFG
|
||||
[#{internal_proj_info[:projname]}-repository]
|
||||
name=Project repository #{internal_proj_info[:projname]}
|
||||
baseurl=file://#{internal_repo_path}
|
||||
enabled=1
|
||||
skip_if_unavailable=True
|
||||
PRJ_CFG
|
||||
linked_prj << proj_repo
|
||||
end
|
||||
end
|
||||
end
|
||||
File.open(prj_incl_path, "w") { |f| f << linked_prj.join("\n\n\n") }
|
||||
end
|
||||
|
||||
def generate_config(id, configuration_path, proj_path, proj_name)
|
||||
proj_conf_path = File.join(proj_path, PROJECTS_STRUCTURE[:CONFIGS], "#{proj_name}.cfg")
|
||||
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("#{prj_incl_path}")
|
||||
config_opts['plugin_conf']['ccache_enable'] = True
|
||||
config_opts['plugin_conf']['ccache_opts']['max_cache_size'] = '4G'
|
||||
config_opts['plugin_conf']['ccache_opts']['hashdir'] = True
|
||||
config_opts['plugin_conf']['ccache_opts']['debug'] = False
|
||||
config_opts['plugin_conf']['ccache_opts']['show_stats'] = True
|
||||
config_opts['plugin_conf']['package_state_enable'] = True
|
||||
config_opts['plugin_conf']['procenv_enable'] = True
|
||||
config_opts['plugin_conf']['root_cache_enable'] = True
|
||||
config_opts['plugin_conf']['showrc_enable'] = True
|
||||
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)
|
||||
end
|
||||
|
||||
def create_project(name, description, configuration)
|
||||
@error = nil
|
||||
ret_val = 0
|
||||
project_name = sanitize_rcptname(name)
|
||||
File.open("locks/prjcreate", "r") do |f|
|
||||
f.flock(File::LOCK_EX)
|
||||
fname = File.expand_path("#{project_name}.prj", @path)
|
||||
if File.exist?(fname)
|
||||
@error = "Проект с таким именем уже существует: #{project_name}"
|
||||
@@ -96,25 +141,14 @@ class ProjectsActions
|
||||
Dir.mkdir(new_path)
|
||||
end
|
||||
if File.exist?(configuration)
|
||||
conf_path = File.join(fname, PROJECTS_STRUCTURE[:CONFIGS], "#{project_name}.cfg")
|
||||
proj_config = <<~PRJ_CFG
|
||||
include("#{configuration}")
|
||||
config_opts['plugin_conf']['ccache_enable'] = True
|
||||
config_opts['plugin_conf']['ccache_opts']['max_cache_size'] = '4G'
|
||||
config_opts['plugin_conf']['ccache_opts']['hashdir'] = True
|
||||
config_opts['plugin_conf']['ccache_opts']['debug'] = False
|
||||
config_opts['plugin_conf']['ccache_opts']['show_stats'] = True
|
||||
config_opts['plugin_conf']['package_state_enable'] = True
|
||||
config_opts['plugin_conf']['procenv_enable'] = True
|
||||
config_opts['plugin_conf']['root_cache_enable'] = True
|
||||
config_opts['plugin_conf']['showrc_enable'] = True
|
||||
config_opts['plugin_conf']['yum_cache_enable'] = True
|
||||
PRJ_CFG
|
||||
File.open(conf_path, "w") { |f| f << proj_config }
|
||||
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} не существует"
|
||||
@@ -127,14 +161,10 @@ class ProjectsActions
|
||||
FileUtils.rm_rf(fname, secure: true)
|
||||
end
|
||||
end
|
||||
end
|
||||
ret_val
|
||||
end
|
||||
|
||||
def get_project_gits(id, repo)
|
||||
res = []
|
||||
File.open("locks/prjcreate", "r") do |f|
|
||||
f.flock(File::LOCK_EX)
|
||||
res = @db.get_gits_for_projects(id)
|
||||
res_sync = res.map do |item|
|
||||
prj_p = get_project_path(id)
|
||||
@@ -142,7 +172,6 @@ class ProjectsActions
|
||||
item[:is_repo_synced] = repo.is_repos_sync(item[:reponame], path)
|
||||
item
|
||||
end
|
||||
end
|
||||
res
|
||||
end
|
||||
|
||||
|
||||
14
classes/repomanage.rb
Normal file
14
classes/repomanage.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
class RepoManager
|
||||
attr :path, :error
|
||||
|
||||
def initialize(path)
|
||||
@error = nil
|
||||
unless File.exist? (path)
|
||||
Dir.mkdir(path)
|
||||
end
|
||||
@path = path
|
||||
end
|
||||
|
||||
def create_repo
|
||||
end
|
||||
end
|
||||
49
views/prjprj.erb
Normal file
49
views/prjprj.erb
Normal file
@@ -0,0 +1,49 @@
|
||||
<%= erb :header %>
|
||||
<script src="/js/jquery.dropdown.min.js"></script>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
<h3 class="bg-secondary-subtle text-center border-bottom border-primary-subtle rounded-1 pb-1 mb-2">
|
||||
project 1
|
||||
</h3>
|
||||
<div class="pb-2">gfhs ag jahsg jhasgfjhgfjf ha jhf</div>
|
||||
</div>
|
||||
<div class="col-8">
|
||||
<div class="vstack gap-3">
|
||||
<form action="/rcpcrt" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="prjlst" class="form-label">Выбирете проекты, от которых зависит данный
|
||||
проект</label>
|
||||
<div class="prjlist">
|
||||
<select class="form-control" id="prjlst" name="prjlst" multiple>
|
||||
<option value="1" selected>test1</option>
|
||||
<option value="2">tets2</option>
|
||||
<option value="3">test33</option>
|
||||
<option value="4">test44</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="disableLinks"
|
||||
name="disableLinks" value="disableLinks">
|
||||
<label class="form-check-label" for="disableLinks">Удалить связи со всеми проектами</label>
|
||||
</div>
|
||||
<div class="container">
|
||||
<div style="padding-top: 45px;"></div>
|
||||
</div>
|
||||
<div class="mb-3 text-center">
|
||||
<button type="submit" class="btn btn-primary" name="save" value="save">Сохранить</button>
|
||||
<button type="submit" class="btn btn-secondary" name="cancel"
|
||||
value="cansel">Отменить</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
$('.prjlist').dropdown({
|
||||
searchNoData: '<li style="color:#ddd">Нет данных</li>',
|
||||
});
|
||||
</script>
|
||||
<%= erb :footer %>
|
||||
@@ -1,11 +1,38 @@
|
||||
<%= erb :header %>
|
||||
<script src="js/jquery.dropdown.min.js"></script>
|
||||
<script src="/js/jquery.dropdown.min.js"></script>
|
||||
<div class="container">
|
||||
<form action="/gitspec/<%= ERB::Util.url_encode(@proj_id) %>/<%= ERB::Util.url_encode(@git_id) %>" method="post">
|
||||
<div class="modal fade" id="modalData" aria-hidden="true" aria-labelledby="modalDataLabel"
|
||||
tabindex="-1">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-body">
|
||||
Вы уверены, что хотите удалить привязку spec файла?
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-primary" data-bs-dismiss="modal">Отмена</button>
|
||||
<button class="btn btn-danger" data-bs-dismiss="modal" id="btnDelete">Удалить</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
<h3 class="bg-secondary-subtle text-center border-bottom border-primary-subtle rounded-1 pb-1 mb-2">
|
||||
<a href="/prjedit/<%= ERB::Util.url_encode(@proj_id) %>"><%= @proj_name %></a>
|
||||
</h3>
|
||||
<div class="pb-2"><%= @proj_descr %></div>
|
||||
<div class="pb-2">git репозиторий <%= @git_name %></div>
|
||||
</div>
|
||||
<div class="col-8">
|
||||
<form action="/gitspec/<%= ERB::Util.url_encode(@proj_id) %>/<%= ERB::Util.url_encode(@git_id) %>" method="post" id="sndFrm">
|
||||
<div class="mb-3">
|
||||
<label for="projname" class="form-label">Установить имя spec файла для гит проекта</label>
|
||||
<input type="text" class="form-control" id="speccustom" name="speccustom" value="<%= @spec_file %>">
|
||||
</div>
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="useCustom" name="useCustom" value="useCustom">
|
||||
<label class="form-check-label" for="speccustom">Использовать spec файл, заданный вручную</label>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="description" class="form-label">Доступные spec файлы</label>
|
||||
<div class="filelist">
|
||||
@@ -22,14 +49,19 @@
|
||||
</div>
|
||||
<div class="mb-3 text-center">
|
||||
<button type="submit" class="btn btn-primary" name="save" value="1">Сохранить</button>
|
||||
<button type="submit" class="btn btn-danger" name="delete" value="2">Удалить установленный spec</button>
|
||||
<button type="submit" class="btn btn-secondary" name="delete" value="2">Отмена</button>
|
||||
<button type="button" class="btn btn-danger" name="delete" value="2" id="btnDDD" data-bs-toggle="modal" data-bs-target="#modalData">Удалить установленный spec</button>
|
||||
<button type="submit" class="btn btn-secondary" name="cancel" value="3">Отмена</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
$('.filelist').dropdown({
|
||||
searchNoData: '<li style="color:#ddd">Нет данных</li>',
|
||||
});
|
||||
$('#btnDelete').on("click", function(){
|
||||
$("#sndFrm").trigger("submit");
|
||||
});
|
||||
</script>
|
||||
<%= erb :footer %>
|
||||
Reference in New Issue
Block a user