Directory creation for projects/platforms
This commit is contained in:
parent
ba117737b7
commit
5ce300adb9
|
@ -5,16 +5,25 @@ class Platform < ActiveRecord::Base
|
||||||
validate :name, :presence => true, :uniqueness => true
|
validate :name, :presence => true, :uniqueness => true
|
||||||
validate :unixname, :uniqueness => true, :presence => true, :format => { :with => /^[a-zA-Z0-9\-.]+$/ }, :allow_nil => false, :allow_blank => false
|
validate :unixname, :uniqueness => true, :presence => true, :format => { :with => /^[a-zA-Z0-9\-.]+$/ }, :allow_nil => false, :allow_blank => false
|
||||||
|
|
||||||
before_validation :generate_unixname
|
before_create :create_directory
|
||||||
|
|
||||||
def path
|
def path
|
||||||
File.join(APP_CONFIG['root_path'], unixname)
|
build_path(unixname)
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def generate_unixname
|
def build_path(dir)
|
||||||
self.unixname = name.gsub(/[^a-zA-Z0-9\-.]/, '-')
|
File.join(APP_CONFIG['root_path'], dir)
|
||||||
#TODO: Fix non-unique unixname
|
end
|
||||||
|
|
||||||
|
def create_directory
|
||||||
|
exists = File.exists?(path) && File.directory?(path)
|
||||||
|
raise "Directory #{path} already exists" if exists
|
||||||
|
if new_record?
|
||||||
|
FileUtils.mkdir_p(path)
|
||||||
|
elsif unixname_changed?
|
||||||
|
FileUtils.mv(build_path(unixname_was), buildpath(unixname))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,23 +4,33 @@ class Project < ActiveRecord::Base
|
||||||
validate :name, :uniqueness => true, :presence => true, :allow_nil => false, :allow_blank => false
|
validate :name, :uniqueness => true, :presence => true, :allow_nil => false, :allow_blank => false
|
||||||
validate :unixname, :uniqueness => true, :presence => true, :format => { :with => /^[a-zA-Z0-9\-.]+$/ }, :allow_nil => false, :allow_blank => false
|
validate :unixname, :uniqueness => true, :presence => true, :format => { :with => /^[a-zA-Z0-9\-.]+$/ }, :allow_nil => false, :allow_blank => false
|
||||||
|
|
||||||
before_validation :generate_unixname
|
|
||||||
|
|
||||||
include Project::HasRepository
|
include Project::HasRepository
|
||||||
|
|
||||||
|
before_create :create_directory
|
||||||
|
|
||||||
# Redefining a method from Project::HasRepository module to reflect current situation
|
# Redefining a method from Project::HasRepository module to reflect current situation
|
||||||
def git_repo_path
|
def git_repo_path
|
||||||
@git_repo_path ||= File.join(APP_CONFIG['root_path'], platform.unixname, unixname, unixname + '.git')
|
@git_repo_path ||= File.join(APP_CONFIG['root_path'], platform.unixname, unixname, unixname + '.git')
|
||||||
end
|
end
|
||||||
|
|
||||||
def path
|
def path
|
||||||
File.join(APP_CONFIG['root_path'], platform.unixname, unixname)
|
build_path(unixname)
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def generate_unixname
|
def build_path(dir)
|
||||||
self.unixname = name.gsub(/[^a-zA-Z0-9\-.]/, '-')
|
File.join(APP_CONFIG['root_path'], platform.unixname, dir)
|
||||||
#TODO: Fix non-unique unixname
|
end
|
||||||
|
|
||||||
|
#TODO: Spec me
|
||||||
|
def create_directory
|
||||||
|
exists = File.exists?(path) && File.directory?(path)
|
||||||
|
raise "Directory #{path} already exists" if exists
|
||||||
|
if new_record?
|
||||||
|
FileUtils.mkdir_p(path)
|
||||||
|
elsif unixname_changed?
|
||||||
|
FileUtils.mv(build_path(unixname_was), buildpath(unixname))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
%p
|
%p
|
||||||
= f.label :name
|
= f.label :name
|
||||||
= f.text_field :name
|
= f.text_field :name
|
||||||
|
%p
|
||||||
|
= f.label :unixname
|
||||||
|
= f.text_field :unixname
|
||||||
%p
|
%p
|
||||||
= f.label :parent_platform_id
|
= f.label :parent_platform_id
|
||||||
= f.select :parent_platform_id, @platforms.map { |p| [p.name, p.id] }, :include_blank => true
|
= f.select :parent_platform_id, @platforms.map { |p| [p.name, p.id] }, :include_blank => true
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
%p
|
%p
|
||||||
= f.label :name
|
= f.label :name
|
||||||
= f.text_field :name
|
= f.text_field :name
|
||||||
|
%p
|
||||||
|
= f.label :unixname
|
||||||
|
= f.text_field :unixname
|
||||||
%p
|
%p
|
||||||
= f.submit t('layout.create')
|
= f.submit t('layout.create')
|
||||||
= link_to t('layout.cancel'), platform_path(@platform)
|
= link_to t('layout.cancel'), platform_path(@platform)
|
||||||
|
|
|
@ -17,7 +17,7 @@ TEST_USERS.each do |tuser|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
TEST_PLATFORMS = %w(cooker Mandriva2010.10 Mandriva2011.4)
|
TEST_PLATFORMS = %w(cooker Mandriva2010-10 Mandriva2011.4)
|
||||||
TEST_PROJECTS = %w(gcc glibc mysql-dev ruby ruby1.9 mc mesa avrdude vim gvim openssh-server openssh nethack binutils build-essentials rpm rpmtools ffmpeg mkvtoolnix libogg mpg123 openbox openoffice.org)
|
TEST_PROJECTS = %w(gcc glibc mysql-dev ruby ruby1.9 mc mesa avrdude vim gvim openssh-server openssh nethack binutils build-essentials rpm rpmtools ffmpeg mkvtoolnix libogg mpg123 openbox openoffice.org)
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ TEST_PLATFORMS.each do |platform|
|
||||||
p = Platform.find_or_create_by_name(platform)
|
p = Platform.find_or_create_by_name(platform)
|
||||||
TEST_PROJECTS.each do |project|
|
TEST_PROJECTS.each do |project|
|
||||||
pr = Project.find_or_initialize_by_platform_id_and_name(p.id, project)
|
pr = Project.find_or_initialize_by_platform_id_and_name(p.id, project)
|
||||||
|
pr.unixname = pr.name
|
||||||
puts "#{project} added to #{platform}" if pr.new_record?
|
puts "#{project} added to #{platform}" if pr.new_record?
|
||||||
pr.save!
|
pr.save!
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue