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

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