Added projects. Part 2

This commit is contained in:
alexey
2025-02-24 23:54:28 +03:00
parent e68e781759
commit b72764d347
6 changed files with 153 additions and 6 deletions

27
classes/configs.rb Normal file
View File

@@ -0,0 +1,27 @@
require_relative "utilities"
class ConfigsList
attr :error, :cfg
def initialize(cfg)
@cfg = cfg
end
def get_configs
hide_list = @cfg.get_configs_hide
select_list = @cfg.get_configs_selected
list_global = Dir["/etc/mock/*.cfg"].map { |item| [File.dirname(item), File.basename(item, ".cfg"), item] }.reject { |item| check_partname_in_array(item[1], hide_list) }
if list_global.nil?
list_global = []
end
list_local = Dir["~/.config/mock/*.cfg"].map { |item| [File.dirname(item), File.basename(item, ".cfg"), item] }
if list_local.nil?
list_local = []
end
list_selected = (list_global + list_local).select { |item| check_partname_in_array(item[1], select_list) }
if list_selected.nil?
list_selected = []
end
{ :global => list_global, :local => list_local, :selected => list_selected }
end
end

View File

@@ -118,4 +118,16 @@ class DBase
def proj_list
Projects.order(:id).all
end
def proj_create(proj_name, proj_descr)
@error = nil
data = Projects.where(projname: project_name).first
if data.nil?
id = Projects.insert(projname: project_name, descr: description, public: 1)
@last_id = id
else
@error = "Данный проект уже существует"
end
@error
end
end

View File

@@ -1,4 +1,3 @@
require "sqlite3"
require "rugged"
require "fileutils"
require_relative "db"

View File

@@ -1,5 +1,14 @@
require "fileutils"
require_relative "db"
PROJECTS_STRUCTURE = {
:REPO => "repo",
:LOGS => "logs",
:CONFIGS => "configs",
:SRCPRP => "srcprp",
:SIGNED => "signed",
}
class ProjectsActions
attr :path, :error, :db
@@ -27,4 +36,40 @@ class ProjectsActions
end
prj
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
Dir.mkdir(fname)
created = false
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(@path, PROJECTS_STRUCTURE[:CONFIGS], project_name)
FileUtils.cp(configuration, conf_path)
@error = @db.proj_create(project_name, description)
if @error.nil?
created = true
end
else
ret_val = 1
@error = "Конфигурация #{configuration} не существует"
end
unless created
FileUtils.rm_rf(fname, secure: true)
end
end
end
ret_val
end
end