Added project spec seting

master
alexey 1 month ago
parent e0d169e679
commit aee02beb03

@ -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,28 +24,25 @@ 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}"
ret_val = 1
else
Dir.mkdir(fname)
Rugged::Repository.init_at(fname, :bare)
repo = Rugged::Repository.new(fname)
created = false
if repo.bare?
@error = @db.creategit(project_name, description)
if @error.nil?
created = true
end
else
@error = "Репозиторий почему-то не пустой"
end
unless created
FileUtils.rm_rf(fname, secure: true)
fname = File.expand_path("#{project_name}.git", @path)
if File.exist?(fname)
@error = "Репозиторий с таким именем уже существует: #{project_name}"
ret_val = 1
else
Dir.mkdir(fname)
Rugged::Repository.init_at(fname, :bare)
repo = Rugged::Repository.new(fname)
created = false
if repo.bare?
@error = @db.creategit(project_name, description)
if @error.nil?
created = true
end
else
@error = "Репозиторий почему-то не пустой"
end
unless created
FileUtils.rm_rf(fname, secure: true)
end
end
ret_val
@ -58,20 +55,17 @@ 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")
db_info = @db.get_repo_info_by_name(repo_name)
unless db_info.nil?
repos_files = Dir[File.join(@path, "*.git")]
repos_files.each do |fl|
repo_name = File.basename(fl, ".git")
db_info = @db.get_repo_info_by_name(repo_name)
unless db_info.nil?
repos_data << { :reponame => db_info.reponame, :descr => db_info.descr, :public => db_info.public, :id => db_info.id }
else
result = create_git_db_only(repo_name)
if result.nil?
db_info = @db.get_repo_info_by_name(repo_name)
repos_data << { :reponame => db_info.reponame, :descr => db_info.descr, :public => db_info.public, :id => db_info.id }
else
result = create_git_db_only(repo_name)
if result.nil?
db_info = @db.get_repo_info_by_name(repo_name)
repos_data << { :reponame => db_info.reponame, :descr => db_info.descr, :public => db_info.public, :id => db_info.id }
end
end
end
end
@ -84,53 +78,50 @@ 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)
unless db_info.nil?
if File.exist?(git_path)
repo = Rugged::Repository.new(git_path)
db_info = @db.get_repo_info_by_name(reponame)
unless db_info.nil?
db_info = db_info.first
repos_data = { :reponame => db_info.reponame, :descr => db_info.descr, :public => db_info.public, :full => 1 }
else
result = create_git_db_only(reponame)
if result.nil?
db_info = @db.get_repo_info_by_name(reponame)
db_info = db_info.first
repos_data = { :reponame => db_info.reponame, :descr => db_info.descr, :public => db_info.public, :full => 1 }
end
end
if repos_data[:full] == 1
info[:info] = repos_data
if repo.empty?
info[:commits] = []
info[:branches] = []
info[:tags] = []
else
result = create_git_db_only(reponame)
if result.nil?
db_info = @db.get_repo_info_by_name(reponame)
db_info = db_info.first
repos_data = { :reponame => db_info.reponame, :descr => db_info.descr, :public => db_info.public, :full => 1 }
ref = repo.head
unless branch.nil?
ref_name = File.join("refs/heads/", branch)
ref = repo.references[ref_name]
end
end
if repos_data[:full] == 1
info[:info] = repos_data
if repo.empty?
info[:commits] = []
info[:branches] = []
info[:tags] = []
else
ref = repo.head
unless branch.nil?
ref_name = File.join("refs/heads/", branch)
ref = repo.references[ref_name]
end
commits = []
unless ref.nil?
walker = Rugged::Walker.new(repo)
walker.sorting(Rugged::SORT_DATE)
walker.push(ref.target)
commits = walker.map do |commit|
{ :message => commit.message, :author => commit.author, :time => commit.time, :sha => commit.oid }
end.first(10)
end
info[:commits] = commits
info[:branches] = repo.branches.each_name(:local).sort
info[:tags] = repo.tags.map { |tag| tag.name }
commits = []
unless ref.nil?
walker = Rugged::Walker.new(repo)
walker.sorting(Rugged::SORT_DATE)
walker.push(ref.target)
commits = walker.map do |commit|
{ :message => commit.message, :author => commit.author, :time => commit.time, :sha => commit.oid }
end.first(10)
end
else
@error = result
info[:commits] = commits
info[:branches] = repo.branches.each_name(:local).sort
info[:tags] = repo.tags.map { |tag| tag.name }
end
else
@error = "Репозиторий отсутсвует"
@error = result
end
else
@error = "Репозиторий отсутсвует"
end
info[:error] = @error
info
@ -138,12 +129,9 @@ class GitRepo
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
if File.exist?(git_path)
FileUtils.rm_rf(git_path, secure: true)
@db.delete_repo_by_name(reponame)
end
end
@ -155,23 +143,20 @@ 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)
if repo.empty?
@error = "Репозиторий пустой, нельзя добавить в проект пустой репозиторий"
else
if File.exist?(path)
FileUtils.rm_rf(path, secure: true)
end
Dir.mkdir(path)
Rugged::Repository.clone_at(repo.path, path)
end
git_path = File.join(@path, repo_info[:reponame] + ".git")
if File.exist?(git_path)
repo = Rugged::Repository.new(git_path)
if repo.empty?
@error = "Репозиторий пустой, нельзя добавить в проект пустой репозиторий"
else
@error = "Файла репозитория не существует"
if File.exist?(path)
FileUtils.rm_rf(path, secure: true)
end
Dir.mkdir(path)
Rugged::Repository.clone_at(repo.path, path)
end
else
@error = "Файла репозитория не существует"
end
else
@error = "Нет информации о репозитории"
@ -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
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)
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,71 +68,109 @@ 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}"
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)
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 }
@error = @db.proj_create(project_name, description)
if @error.nil?
created = true
end
else
ret_val = 1
@error = "Конфигурация #{configuration} не существует"
fname = File.expand_path("#{project_name}.prj", @path)
if File.exist?(fname)
@error = "Проект с таким именем уже существует: #{project_name}"
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
rescue => e
repo_path = File.join(fname, PROJECTS_STRUCTURE[:REPO])
repoman = RepoManager.new(repo_path)
repoman.create_repo
else
ret_val = 1
@error = e.message
end
unless created
FileUtils.rm_rf(fname, secure: true)
@error = "Конфигурация #{configuration} не существует"
end
rescue => e
ret_val = 1
@error = e.message
end
unless created
FileUtils.rm_rf(fname, secure: true)
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)
path = File.join(prj_p, PROJECTS_STRUCTURE[:SRC], item[:reponame])
item[:is_repo_synced] = repo.is_repos_sync(item[:reponame], path)
item
end
res = @db.get_gits_for_projects(id)
res_sync = res.map do |item|
prj_p = get_project_path(id)
path = File.join(prj_p, PROJECTS_STRUCTURE[:SRC], item[:reponame])
item[:is_repo_synced] = repo.is_repos_sync(item[:reponame], path)
item
end
res
end

@ -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

@ -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,35 +1,67 @@
<%= 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="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="mb-3">
<label for="description" class="form-label">Доступные spec файлы</label>
<div class="filelist">
<select class="form-control" id="filelst" name="filelst">
<% @files_list.each do |item| %>
<% if !@spec_file.nil? && item.include?(@spec_file) %>
<option value="<%= item %>" selected><%= item %></option>
<% else %>
<option value="<%= item %>"><%= item %></option>
<% end %>
<% end %>
</select>
<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 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>
</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">
<select class="form-control" id="filelst" name="filelst">
<% @files_list.each do |item| %>
<% if !@spec_file.nil? && item.include?(@spec_file) %>
<option value="<%= item %>" selected><%= item %></option>
<% else %>
<option value="<%= item %>"><%= item %></option>
<% end %>
<% end %>
</select>
</div>
</div>
<div class="mb-3 text-center">
<button type="submit" class="btn btn-primary" name="save" value="1">Сохранить</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>
</form>
</div>
</div>
<script>
$('.filelist').dropdown({
searchNoData: '<li style="color:#ddd">Нет данных</li>',
});
$('#btnDelete').on("click", function(){
$("#sndFrm").trigger("submit");
});
</script>
<%= erb :footer %>
Loading…
Cancel
Save