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 :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
|
||||
File.join(APP_CONFIG['root_path'], unixname)
|
||||
build_path(unixname)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def generate_unixname
|
||||
self.unixname = name.gsub(/[^a-zA-Z0-9\-.]/, '-')
|
||||
#TODO: Fix non-unique unixname
|
||||
def build_path(dir)
|
||||
File.join(APP_CONFIG['root_path'], dir)
|
||||
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
|
||||
|
|
|
@ -4,23 +4,33 @@ class Project < ActiveRecord::Base
|
|||
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
|
||||
|
||||
before_validation :generate_unixname
|
||||
|
||||
include Project::HasRepository
|
||||
|
||||
before_create :create_directory
|
||||
|
||||
# Redefining a method from Project::HasRepository module to reflect current situation
|
||||
def git_repo_path
|
||||
@git_repo_path ||= File.join(APP_CONFIG['root_path'], platform.unixname, unixname, unixname + '.git')
|
||||
end
|
||||
|
||||
def path
|
||||
File.join(APP_CONFIG['root_path'], platform.unixname, unixname)
|
||||
build_path(unixname)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def generate_unixname
|
||||
self.unixname = name.gsub(/[^a-zA-Z0-9\-.]/, '-')
|
||||
#TODO: Fix non-unique unixname
|
||||
def build_path(dir)
|
||||
File.join(APP_CONFIG['root_path'], platform.unixname, dir)
|
||||
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
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
%p
|
||||
= f.label :name
|
||||
= f.text_field :name
|
||||
%p
|
||||
= f.label :unixname
|
||||
= f.text_field :unixname
|
||||
%p
|
||||
= f.label :parent_platform_id
|
||||
= f.select :parent_platform_id, @platforms.map { |p| [p.name, p.id] }, :include_blank => true
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
%p
|
||||
= f.label :name
|
||||
= f.text_field :name
|
||||
%p
|
||||
= f.label :unixname
|
||||
= f.text_field :unixname
|
||||
%p
|
||||
= f.submit t('layout.create')
|
||||
= link_to t('layout.cancel'), platform_path(@platform)
|
||||
|
|
|
@ -17,7 +17,7 @@ TEST_USERS.each do |tuser|
|
|||
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)
|
||||
|
||||
|
||||
|
@ -25,6 +25,7 @@ TEST_PLATFORMS.each do |platform|
|
|||
p = Platform.find_or_create_by_name(platform)
|
||||
TEST_PROJECTS.each do |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?
|
||||
pr.save!
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue