Added delete of items.Part 1

master
alexey 3 weeks ago
parent e6c5742ea4
commit ecf3d47392

264
app.rb

@ -721,12 +721,14 @@ post "/prjaddrepo/:id" do
else
if params["disableLinks"].nil?
list_id = params["prjlst"]
current_list = prj.get_related_projects_list(params["id"])
current_list_id = current_list.map { |item| item[:proj_id_repository] }
new_ids = list_id - current_list_id
removed_ids = current_list_id - list_id
prj.save_linked_projects(params["id"], new_ids, removed_ids)
prj.regenerate_linked_repos(params["id"])
unless list_id.nil?
current_list = prj.get_related_projects_list(params["id"])
current_list_id = current_list.map { |item| item[:proj_id_repository] }
new_ids = list_id - current_list_id
removed_ids = current_list_id - list_id
prj.save_linked_projects(params["id"], new_ids, removed_ids)
prj.regenerate_linked_repos(params["id"])
end
redirect "/prjedit/#{params["id"]}"
else
prj.delete_linked_projects(params["id"])
@ -800,11 +802,7 @@ get "/buildinforaw/:build_id" do
info = db.get_build_task_process_log(build_id)
unless info.nil?
if File.exist?(info[:errlogpath])
output = ""
File.readlines(info[:errlogpath]).each do |line|
output << line
end
output
send_file info[:errlogpath]
else
"Файла для чтения сборки уже не существует #{info[:errlogpath]}"
end
@ -943,6 +941,250 @@ get "/buildinfof/:build_id" do
end
end
get "/buildinfofraw" do
if params["file"].nil? || !File.exist?(params["file"])
print_error_page(503, "Файл не найден")
else
if !File.binary?(params["file"]) && params["file"].start_with?(File.join(Dir.pwd(), cfg.get_projects_path))
send_file params["file"]
else
print_error_page(503, "Файл не может быть скачан")
end
end
end
get "/prjbuilds/:id" do
prj = ProjectsActions.new(cfg.get_projects_path, db)
if prj.path.nil?
print_error_page(503, "Путь к проектам не существует")
else
prj_info = prj.get_project(params["id"])
@prj = prj_info
@page_name = "Список всех сборок для проекта #{prj_info[:projname]}"
builds_lst = db.get_builds_for_project(params["id"])
if params["p"].nil?
@page = 1
else
@page = params["p"].to_i
if @page < 1
@page = 1
else
@page = @page + 1
end
end
if builds_lst.nil?
builds_lst = []
end
items_per_page = cfg.get_items_per_page
@builds_list = builds_lst[(@page - 1) * items_per_page, items_per_page]
@max_pages = builds_lst.length / items_per_page
if (@max_pages * items_per_page) != builds_lst.length
@max_pages = @max_pages + 1
end
erb :prjbuildslist
end
end
get "/prjrpm/:id" do
@raw = nil
prj = ProjectsActions.new(cfg.get_projects_path, db)
if prj.path.nil?
print_error_page(503, "Путь к проектам не существует")
else
prj_info = prj.get_project(params["id"])
if params["p"].nil?
filepath = ""
else
filepath = params["p"]
end
proj_path = prj.get_project_repo(params["id"])
f_path = File.join(proj_path, filepath)
if File.exist?(f_path)
if File.directory?(f_path)
@file_content = []
@files_list = Dir[File.join(f_path, "*")].reject do |item|
item =~ /repodata$/
end.map do |item|
if File.directory?(item)
{ :file => item.delete_prefix(proj_path + "/"), :isdir => true }
else
{ :file => item.delete_prefix(proj_path + "/"), :isdir => false }
end
end
else
if File.binary?(f_path)
if f_path =~ /\.rpm$/
rpm_rd = RPMReader.new
rpm_info = rpm_rd.get_rpm_info(f_path)
if rpm_info[:error].nil?
@raw = f_path
rpm_info = rpm_info[:pkginfo]
@file_content = []
@file_content << "Имя пакета: #{rpm_info.name}"
@file_content << "Версия пакета: #{rpm_info.version}"
@file_content << ""
@file_content << "Changelog:"
rpm_info.changelog.first(10).each do |entry|
@file_content << "#{entry.time} #{entry.name}"
@file_content << "#{entry.text}"
@file_content << "---------------"
end
@file_content << "---------------"
@file_content << "Файлы:"
rpm_info.files.each do |file|
@file_content << "#{file.path} (#{file.size})"
end
@file_content << "---------------"
@file_content << "Зависимости:"
rpm_info.provides.each do |item|
@file_content << "Provides: #{item.name}"
end
rpm_info.requires.each do |item|
@file_content << "Requires: #{item.name}"
end
rpm_info.obsoletes.each do |item|
@file_content << "Obsoletes: #{item.name}"
end
rpm_info.conflicts.each do |item|
@file_content << "Conflicts: #{item.name}"
end
else
@file_content = ["Двоичный файл"]
end
else
@file_content = ["Двоичный файл"]
end
else
@file_content = File.readlines(f_path)
end
@files_list = Dir[File.join(File.dirname(f_path), "*")].map do |item|
if File.directory?(item)
{ :file => item.delete_prefix(proj_path + "/"), :isdir => true }
else
{ :file => item.delete_prefix(proj_path + "/"), :isdir => false }
end
end
end
if filepath != ""
if File.dirname(f_path) == proj_path
fn = ""
else
if File.directory?(f_path)
fn = File.dirname(f_path).delete_prefix(proj_path + "/")
else
f_path = File.dirname(f_path)
if File.dirname(f_path) == proj_path
fn = ""
else
fn = File.dirname(f_path).delete_prefix(proj_path + "/")
end
end
end
@files_list = [{ :file => "..", :isdir => true, :fname => fn }] + @files_list
end
@page_name = "Список пакетов для репозитория #{prj_info[:projname]}"
@proj_info = prj_info
@file_name = filepath
erb :repoinfo
else
print_error_page(503, "Файл не существует")
end
end
end
get "/prjdgit/: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)
@page_name = "Удалить репозиторий #{git_info[:reponame]} из проекта #{prj_info[:projname]} "
@proj_name = prj_info[:projname]
@git_name = git_info[:reponame]
@proj_id = params["id"]
@git_id = params["git_id"]
erb :deletegitprj
end
end
end
end
post "/prjdgit/: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)
if params["cancel"].nil? && params["delete"] == "delete" && !params["isdelete"].nil?
err = prj.delete_git_from_project(params["id"], params["git_id"])
unless err.nil?
session[:prj_modal_info] = "Ошибка удаления git репозитория из проекта"
session[:prj_modal_text] = err
end
end
redirect "/prjedit/#{params["id"]}"
end
end
end
end
get "/prjgitbld/: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"])
git_info = repo.get_repo_short_info_by_id(params["git_id"].to_i)
@git_data = git_info
@prj = prj_info
@page_name = "Список всех сборок для проекта #{prj_info[:projname]} и репозитория #{git_info[:reponame]}"
builds_lst = db.get_builds_for_project_git(params["id"], params["git_id"])
if params["p"].nil?
@page = 1
else
@page = params["p"].to_i
if @page < 1
@page = 1
else
@page = @page + 1
end
end
if builds_lst.nil?
builds_lst = []
end
items_per_page = cfg.get_items_per_page
@builds_list = builds_lst[(@page - 1) * items_per_page, items_per_page]
@max_pages = builds_lst.length / items_per_page
if (@max_pages * items_per_page) != builds_lst.length
@max_pages = @max_pages + 1
end
erb :prjbuildslistgit
end
end
end
not_found do
status 404
@page_name = "Кто-то потерялся"

@ -326,4 +326,21 @@ class DBase
def get_rpms()
Rpms.order(:id).all
end
def get_builds_for_project(prj_id)
$DDB["select t1.id as buildid, t1.create_at as createat, t1.result as state, t2.reponame as reponame, t2.id as gitid, t3.id as projid, t3.projname as prjname, count(*) as pkgcnt from buildtask as t1 join repos as t2 on t1.repo_id = t2.id join projects as t3 on t1.proj_id = t3.id join build_rpm as t4 on t4.build_id = t1.id where t1.proj_id = ? group by buildid, createat, state, reponame, projid, prjname, gitid order by t1.id", prj_id.to_i].all
end
def get_builds_for_project_git(prj_id, git_id)
$DDB["select t1.id as buildid, t1.create_at as createat, t1.result as state, t2.reponame as reponame, t2.id as gitid, t3.id as projid, t3.projname as prjname, count(*) as pkgcnt from buildtask as t1 join repos as t2 on t1.repo_id = t2.id join projects as t3 on t1.proj_id = t3.id join build_rpm as t4 on t4.build_id = t1.id where t1.proj_id = ? and t1.repo_id = ? group by buildid, createat, state, reponame, projid, prjname, gitid order by t1.id", prj_id.to_i, git_id.to_i].all
end
def get_builds_for_project_git_rpm(prj_id, git_id)
$DDB["select t3.savepath, t3.signpath, t3.sign from buildtask as t1 join build_rpm as t2 on t2.build_id = t1.id join rpms as t3 on t3.id = t2.rpm_id where t1.proj_id = ? and t1.repo_id = ?", prj_id.to_i, git_id.to_i].all
end
def delete_git_from_project(prj_id, git_id)
ReposProjects.where(proj_id: prj_id.to_i, repo_id: git_id.to_i).delete
ProjectsReposSpec.where(proj_id: prj_id.to_i, repo_id: git_id.to_i).delete
end
end

@ -211,8 +211,8 @@ class MockManager
FileUtils.cp_r(item[:src], item[:dst], verbose: true, remove_destination: true)
@db.save_rpm(@build_id, item[:dst], item[:name], @git_id)
@log.info("Копируется пакет #{item[:src]} в репозиторий #{item[:dst]}")
repo.create_repo
end
repo.create_repo
end
end
end

@ -65,6 +65,11 @@ class ProjectsActions
fname
end
def get_project_repo(id)
proj_path = get_project_path(id)
File.join(proj_path, PROJECTS_STRUCTURE[:REPO])
end
def get_project_path_git(id, gitname)
proj_path = get_project_path(id)
File.join(proj_path, PROJECTS_STRUCTURE[:SRC], gitname)
@ -314,4 +319,25 @@ class ProjectsActions
end
bld_id
end
def delete_git_from_project(prj_id, git_id)
@error = nil
builds_lst = db.get_builds_for_project_git(prj_id, git_id)
active_build = false
builds_lst.each do |item|
if item[:state] == 0
active_build = true
break
end
end
if active_build
@error = "Нельзя удалить git репозиторий с незавершенными сборками"
else
git_name = @db.get_repo_info_by_id(git_id)
git_source = File.join(proj_path, PROJECTS_STRUCTURE[:SRC], git_name[:reponame])
FileUtils.rm_rf(git_source, secure: true)
@db.delete_git_from_project(prj_id, git_id)
end
@error
end
end

@ -24,7 +24,7 @@
</div>
<div class="col-8">
<div class="hstack gap-3">
<div class="p-2">Содержимое отчета <%= @file_disp %> <a href="/buildinfofraw/?file=<%= ERB::Util.url_encode(@file_disp_raw) %>"><i class="bi bi-filetype-raw"></i></a></div>
<div class="p-2">Содержимое отчета <%= @file_disp %> <a href="/buildinfofraw?file=<%= ERB::Util.url_encode(@file_disp_raw) %>"><i class="bi bi-filetype-raw"></i></a></div>
</div>
<div class="border rounded-3 p-2 overflow-x-scroll">
<% @file_content.each do |item| %>

@ -0,0 +1,18 @@
<%= erb :header %>
<div class="container">
<h2 class="text-center">Удаление git проекта <%= @git_name %> из <%= @proj_name %></h2>
<form action="/prjdgit/<%= ERB::Util.url_encode(@proj_id) %>/<%= ERB::Util.url_encode(@git_id) %>" method="post">
<div class="form-check form-switch text-center pb-3">
<input class="form-check-input" type="checkbox" role="switch" id="isdelete" name="isdelete">
<label class="form-check-label" for="isdelete">
Вы уверены, что хотите удалить данный git репозиторий?<br />
Все rpm пакеты собранные из данного репозитория будут удалены
</label>
</div>
<div class="mb-3 text-center">
<button type="submit" class="btn btn-primary" name="cancel" value="cancel">Отменить</button>
<button type="submit" class="btn btn-danger" name="delete" value="delete">Удалить</button>
</div>
</form>
</div>
<%= erb :footer %>

@ -0,0 +1,64 @@
<%= erb :header %>
<div class="container">
<h2><a href="/prjedit/<%= ERB::Util.url_encode(@prj[:id]) %>"><%= @prj[:projname] %></a></h2>
<table class="table table-striped table-hover">
<thead>
<tr>
<th scope="col">Номер сборки</th>
<th scope="col" class="text-center">Проект</th>
<th scope="col" class="text-center">git репозиторий</th>
<th scope="col" class="text-center">Дата сборки</th>
<th scope="col" class="text-center">Число собранных пакетов</th>
<th scope="col" class="text-center">Состояние</th>
<th scope="col" class="text-center">Перейти к сборке</th>
</tr>
</thead>
<tbody>
<% @builds_list.each do |item| %>
<%
case item[:state]
when 0
st = "Идет сборка"
cl = "text-bg-secondary"
when 1
st = "Ошибка сборки"
cl = "text-bg-danger"
when 2
st = "Сборка успешно завершена"
cl = "text-bg-success"
else
st = "Неизвестно"
cl = "text-bg-light"
end
%>
<tr>
<td scope="row"><%= item[:buildid] %></td>
<td class="text-center"><a href="/prjedit/<%= ERB::Util.url_encode(item[:projid]) %>"><%= item[:prjname] %></a></td>
<td class="text-center"><a href="/prjgitf/<%= ERB::Util.url_encode(item[:projid]) %>/<%= ERB::Util.url_encode(item[:gitid]) %>"><%= item[:reponame] %></a></td>
<td class="text-center"><%= item[:createat] %></td>
<td class="text-center"><%= item[:pkgcnt] %></td>
<td class="text-center <%= cl %>">
<%= st %>
</td>
<td class="text-center"><a href="/buildinfof/<%= ERB::Util.url_encode(item[:buildid]) %>">Детальнее</a></td>
</tr>
<% end %>
</tbody>
</table>
</div>
<div class="container">
<nav aria-label="Навигация по доступным сборкам">
<ul class="pagination pagination-sm justify-content-center">
<% @max_pages.times.each do |item| %>
<% if (item+1) == @page %>
<li class="page-item active" aria-current="page">
<span class="page-link"><%= item+1 %></span>
</li>
<% else %>
<li class="page-item"><a class="page-link" href="/gitpackages/<%= ERB::Util.url_encode(@git_id) %>/?p=<%= item+1 %>"><%= item+1 %></a></li>
<% end %>
<% end %>
</ul>
</nav>
</div>
<%= erb :footer %>

@ -0,0 +1,64 @@
<%= erb :header %>
<div class="container">
<h3>Проект <a href="/prjedit/<%= ERB::Util.url_encode(@prj[:id]) %>"><%= @prj[:projname] %></a> для git репозитория <%= @git_data[:reponame] %> </h3>
<table class="table table-striped table-hover">
<thead>
<tr>
<th scope="col">Номер сборки</th>
<th scope="col" class="text-center">Проект</th>
<th scope="col" class="text-center">git репозиторий</th>
<th scope="col" class="text-center">Дата сборки</th>
<th scope="col" class="text-center">Число собранных пакетов</th>
<th scope="col" class="text-center">Состояние</th>
<th scope="col" class="text-center">Перейти к сборке</th>
</tr>
</thead>
<tbody>
<% @builds_list.each do |item| %>
<%
case item[:state]
when 0
st = "Идет сборка"
cl = "text-bg-secondary"
when 1
st = "Ошибка сборки"
cl = "text-bg-danger"
when 2
st = "Сборка успешно завершена"
cl = "text-bg-success"
else
st = "Неизвестно"
cl = "text-bg-light"
end
%>
<tr>
<td scope="row"><%= item[:buildid] %></td>
<td class="text-center"><a href="/prjedit/<%= ERB::Util.url_encode(item[:projid]) %>"><%= item[:prjname] %></a></td>
<td class="text-center"><a href="/prjgitf/<%= ERB::Util.url_encode(item[:projid]) %>/<%= ERB::Util.url_encode(item[:gitid]) %>"><%= item[:reponame] %></a></td>
<td class="text-center"><%= item[:createat] %></td>
<td class="text-center"><%= item[:pkgcnt] %></td>
<td class="text-center <%= cl %>">
<%= st %>
</td>
<td class="text-center"><a href="/buildinfof/<%= ERB::Util.url_encode(item[:buildid]) %>">Детальнее</a></td>
</tr>
<% end %>
</tbody>
</table>
</div>
<div class="container">
<nav aria-label="Навигация по доступным сборкам">
<ul class="pagination pagination-sm justify-content-center">
<% @max_pages.times.each do |item| %>
<% if (item+1) == @page %>
<li class="page-item active" aria-current="page">
<span class="page-link"><%= item+1 %></span>
</li>
<% else %>
<li class="page-item"><a class="page-link" href="/gitpackages/<%= ERB::Util.url_encode(@git_id) %>/?p=<%= item+1 %>"><%= item+1 %></a></li>
<% end %>
<% end %>
</ul>
</nav>
</div>
<%= erb :footer %>

@ -0,0 +1,36 @@
<%= erb :header %>
<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">
<a href="/prjedit/<%= ERB::Util.url_encode(@proj_info[:id]) %>"><%= @proj_info[:projname] %></a>
</h3>
<div class="list-group">
<% @files_list.each do |item| %>
<% if item[:isdir] %>
<% if item[:file] == ".." %>
<a href="/prjrpm/<%= ERB::Util.url_encode(@proj_info[:id]) %>?p=<%= ERB::Util.url_encode(item[:fname]) %>" class="list-group-item list-group-item-action list-group-item-success"><%= item[:file] %></a>
<% else %>
<a href="/prjrpm/<%= ERB::Util.url_encode(@proj_info[:id]) %>?p=<%= ERB::Util.url_encode(item[:file]) %>" class="list-group-item list-group-item-action list-group-item-success"><%= item[:file] %></a>
<% end %>
<% else %>
<a href="/prjrpm/<%= ERB::Util.url_encode(@proj_info[:id]) %>?p=<%= ERB::Util.url_encode(item[:file]) %>" class="list-group-item list-group-item-action list-group-item-light"><%= item[:file] %></a>
<% end %>
<% end %>
</div>
</div>
<div class="col-8">
<div class="mb-2 p-2 bg-success-subtle rounded-2 text-sm-start"><%= @file_name %>
<% unless @raw.nil? %>
<a href="/buildinfofraw?file=<%= ERB::Util.url_encode(@raw) %>"><i class="bi bi-filetype-raw"></i></a>
<% end %>
</div>
<% @file_content.each do |data| %>
<div class="row">
<div class="col-12"><%= data %></div>
</div>
<% end %>
</div>
</div>
</div>
<%= erb :footer %>
Loading…
Cancel
Save