From 0828293f361ee8fb8df5e705c732fd1555c1123a Mon Sep 17 00:00:00 2001 From: Alexey Berezhok Date: Sat, 18 Apr 2026 00:11:36 +0300 Subject: [PATCH] Added list of uploaded rpm --- README.md | 1 - app.rb | 85 +++++++++++++++++++ classes/config.rb | 8 ++ classes/db.rb | 19 +++++ classes/projects.rb | 11 +++ config.ini | 5 +- .../202604170000000_create_uploaded_rpm.rb | 14 +++ views/prjinfo.erb | 2 + views/rpmuploadinfo.erb | 28 ++++++ 9 files changed, 171 insertions(+), 2 deletions(-) create mode 100644 db/migrations/202604170000000_create_uploaded_rpm.rb create mode 100644 views/rpmuploadinfo.erb diff --git a/README.md b/README.md index 1d3dd1a..360f8a1 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,6 @@ ПО может быть установлено на следующих ОС: -* MSVSphere 9 * Almalinux 9 * RockyLinux 9 * Centos 9 Stream diff --git a/app.rb b/app.rb index 6768d51..0035885 100644 --- a/app.rb +++ b/app.rb @@ -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 #Подчистим гит проекты, которые есть в базе, но нет в файловой системе diff --git a/classes/config.rb b/classes/config.rb index 003d557..2850125 100644 --- a/classes/config.rb +++ b/classes/config.rb @@ -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 diff --git a/classes/db.rb b/classes/db.rb index 0f52a9b..bf15bc8 100644 --- a/classes/db.rb +++ b/classes/db.rb @@ -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 diff --git a/classes/projects.rb b/classes/projects.rb index c81d463..c506ab2 100644 --- a/classes/projects.rb +++ b/classes/projects.rb @@ -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 diff --git a/config.ini b/config.ini index 94e36f9..b912b59 100644 --- a/config.ini +++ b/config.ini @@ -26,4 +26,7 @@ items_per_page = 30 path = "keys" [repoview] -path = "repoview" \ No newline at end of file +path = "repoview" + +[timezone] +zone="Europe/Moscow" diff --git a/db/migrations/202604170000000_create_uploaded_rpm.rb b/db/migrations/202604170000000_create_uploaded_rpm.rb new file mode 100644 index 0000000..e93a919 --- /dev/null +++ b/db/migrations/202604170000000_create_uploaded_rpm.rb @@ -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 diff --git a/views/prjinfo.erb b/views/prjinfo.erb index 378b987..ae82a66 100644 --- a/views/prjinfo.erb +++ b/views/prjinfo.erb @@ -48,6 +48,8 @@ class="bi bi-archive">Добавить внутренний репозиторий из другого проекта Добавить бинарный пакет в репозиторий + Посмотреть список загруженных rpm пакетов Список всех пакетов diff --git a/views/rpmuploadinfo.erb b/views/rpmuploadinfo.erb new file mode 100644 index 0000000..ab9480c --- /dev/null +++ b/views/rpmuploadinfo.erb @@ -0,0 +1,28 @@ +<%= erb :header %> +