Added projects. Part 2
This commit is contained in:
27
classes/configs.rb
Normal file
27
classes/configs.rb
Normal 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
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
require "sqlite3"
|
||||
require "rugged"
|
||||
require "fileutils"
|
||||
require_relative "db"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user