Added list of uploaded rpm

This commit is contained in:
Alexey Berezhok
2026-04-18 00:11:36 +03:00
parent 6139670677
commit 0828293f36
9 changed files with 171 additions and 2 deletions

View File

@@ -8,7 +8,6 @@
ПО может быть установлено на следующих ОС:
* MSVSphere 9
* Almalinux 9
* RockyLinux 9
* Centos 9 Stream

85
app.rb
View File

@@ -1831,6 +1831,91 @@ post "/prjsnap_restore/:id" do
end
end
get "/prjuplrpm/: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 = []
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:"
begin
rpm_info.changelog.first(10).each do |entry|
@file_content << "#{entry.time} #{entry.name}"
@file_content << "#{entry.text}"
@file_content << "---------------"
end
rescue
# Если есть ошибка с undefined local variable or method, пропускаем changelog
@file_content << "Changelog недоступен"
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
end
@files_list = prj.get_project_uploaded_rpms(params["id"]).map do |item|
{ :file => item[:rpm_path].delete_prefix(proj_path + "/"), :isdir => false, :create_time => item[:create_at] }
end
@page_name = "Список загруженных rpm пакетов для проекта #{prj_info[:projname]}"
@proj_info = prj_info
@file_name = filepath
erb :rpmuploadinfo
else
print_error_page(503, "Файл не существует")
end
end
end
get "/sanitize" do
#Подчистим гит проекты, которые есть в базе, но нет в файловой системе

View File

@@ -120,4 +120,12 @@ class IniConfig
"repoview"
end
end
def get_time_zone
unless @config["timezone"]["zone"].nil?
@config["timezone"]["zone"].to_s
else
"Europe/Moscow"
end
end
end

View File

@@ -1,6 +1,12 @@
require "sequel"
cfg_internal = IniConfig.new()
# Настройте Sequel для использования нужного часового пояса
Sequel.extension :named_timezones
Sequel.database_timezone = :utc
Sequel.application_timezone = cfg_internal.get_time_zone
$DDB = Sequel.connect(cfg_internal.get_db)
class Repos < Sequel::Model(:repos)
@@ -33,6 +39,9 @@ end
class BuildRpms < Sequel::Model(:build_rpm)
end
class RpmUploaded < Sequel::Model(:rpm_uploaded)
end
class DBase
attr :error, :last_id, :cfg
@@ -360,6 +369,7 @@ class DBase
count = count + 1
end
return 1 if count > 0
RpmUploaded.where(proj_id: prj_id.to_i).delete
ReposProjects.where(proj_id: prj_id.to_i).delete
ProjectsReposSpec.where(proj_id: prj_id.to_i).delete
builds = BuildTask.where(proj_id: prj_id.to_i)
@@ -412,4 +422,13 @@ class DBase
def update_build_task_end_time(build_id)
BuildTask.where(id: build_id.to_i).update(buildstop: DateTime.now)
end
def add_custom_rpm_to_proj(proj_id, rpm_name, rpm_path)
id = RpmUploaded.insert(rpm: rpm_name, rpm_path: rpm_path, proj_id: proj_id.to_i)
@last_id = id
end
def get_project_uploaded_rpms(proj_id)
RpmUploaded.where(proj_id: proj_id.to_i)
end
end

View File

@@ -572,6 +572,17 @@ class ProjectsActions
return "Ошибка при создании файла: #{e.message}"
end
@db.add_custom_rpm_to_proj(id, File.basename(rpm_file[:filename]), target_file)
nil
end
def get_project_uploaded_rpms(id)
list = []
rpm_list = @db.get_project_uploaded_rpms(id)
rpm_list.each do |item|
list << item if File.exist?(item[:rpm_path])
end
list
end
end

View File

@@ -26,4 +26,7 @@ items_per_page = 30
path = "keys"
[repoview]
path = "repoview"
path = "repoview"
[timezone]
zone="Europe/Moscow"

View File

@@ -0,0 +1,14 @@
require "sequel"
Sequel.migration do
change do
create_table(:rpm_uploaded) do
primary_key :id
String :rpm, :null => false
String :rpm_path, :null => false
Datetime :create_at, default: Sequel.lit("CURRENT_TIMESTAMP")
foreign_key :proj_id, :projects, :key => :id
end
end
end

View File

@@ -48,6 +48,8 @@
class="bi bi-archive"></i><span class="ms-2">Добавить внутренний репозиторий из другого проекта</span></a>
<a href="/prjaddrpm/<%= ERB::Util.url_encode(@proj_id) %>" class="list-group-item list-group-item-action list-group-item-dark icon-link"><i
class="bi bi-bag-dash"></i><span class="ms-2">Добавить бинарный пакет в репозиторий</span></a>
<a href="/prjuplrpm/<%= ERB::Util.url_encode(@proj_id) %>" class="list-group-item list-group-item-action list-group-item-dark icon-link"><i
class="bi bi-folder-symlink"></i><span class="ms-2">Посмотреть список загруженных rpm пакетов</span></a>
<a href="/prjrpm/<%= ERB::Util.url_encode(@proj_id) %>" class="list-group-item list-group-item-action list-group-item-dark icon-link"><i
class="bi bi-box"></i><span class="ms-2">Список всех
пакетов</span></a>

28
views/rpmuploadinfo.erb Normal file
View File

@@ -0,0 +1,28 @@
<%= 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| %>
<a href="/prjuplrpm/<%= 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] %>(<%= item[:create_time] %>)</a>
<% 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 %>