This commit is contained in:
Timothy N. Tsvetkov 2011-04-07 17:21:47 +04:00
commit 0370ee4f9c
4 changed files with 85 additions and 8 deletions

View File

@ -5,7 +5,8 @@ class Platform < ActiveRecord::Base
validates :name, :presence => true, :uniqueness => true
validates :unixname, :uniqueness => true, :presence => true, :format => { :with => /^[a-zA-Z0-9\-.]+$/ }, :allow_nil => false, :allow_blank => false
before_create :create_directory
before_create :xml_rpc_create
before_destroy :xml_rpc_destroy
def path
build_path(unixname)
@ -31,13 +32,35 @@ class Platform < ActiveRecord::Base
File.join(APP_CONFIG['root_path'], dir)
end
def git_path(dir)
File.join(build_path(dir), 'git')
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))
FileUtils.mv(build_path(unixname_was), build_path(unixname))
end
end
def xml_rpc_create
result = BuildServer.add_platform name, build_path(unixname), [], git_path(unixname)
if result == BuildServer::SUCCESS
return true
else
raise "Failed to create platform #{name}. Path: #{build_path(unixname)}"
end
end
def xml_rpc_destroy
result = BuildServer.delete_platform name
if result == BuildServer::SUCCESS
return true
else
raise "Failed to delete platform #{name}."
end
end
end

View File

@ -9,7 +9,9 @@ class Project < ActiveRecord::Base
scope :recent, order("name ASC")
before_create :create_directory, :create_git_repo
#before_create :create_directory, :create_git_repo
before_create :xml_rpc_create, :create_git_repo
before_destroy :xml_rpc_destroy
# Redefining a method from Project::HasRepository module to reflect current situation
def git_repo_path
@ -27,13 +29,21 @@ class Project < ActiveRecord::Base
return p
end
def add_to_repository(platf, repo)
result = BuildServer.add_to_repo(repository.name, platf.name)
if result == BuildServer::SUCCESS
return true
else
raise "Failed to add project #{name} to repo #{repo.name)} of platform #{platf.name}."
end
end
protected
def build_path(dir)
File.join(repository.path, dir)
end
#TODO: Spec me
def create_directory
exists = File.exists?(path) && File.directory?(path)
raise "Directory #{path} already exists" if exists
@ -47,4 +57,22 @@ class Project < ActiveRecord::Base
def create_git_repo
Git::Repository.create(git_repo_path)
end
def xml_rpc_create
result = BuildServer.create_project name, platform.name, repository.name
if result == BuildServer::SUCCESS
return true
else
raise "Failed to create project #{name} (repo #{repository.name)}) inside platform #{platform.name}."
end
end
def xml_rpc_destroy
result = BuildServer.delete_project name, platform.name, repository.name
if result == BuildServer::SUCCESS
return true
else
raise "Failed to delete repository #{name} (repo #{repository.name)}) inside platform #{platform.name}."
end
end
end

View File

@ -7,7 +7,8 @@ class Repository < ActiveRecord::Base
scope :recent, order("name ASC")
before_create :create_directory
before_create :xml_rpc_create
before_destroy :xml_rpc_destroy
def path
build_path(unixname)
@ -27,7 +28,6 @@ class Repository < ActiveRecord::Base
File.join(platform.path, dir)
end
#TODO: Spec me
def create_directory
exists = File.exists?(path) && File.directory?(path)
raise "Directory #{path} already exists" if exists
@ -38,5 +38,23 @@ class Repository < ActiveRecord::Base
FileUtils.mv(build_path(unixname_was), buildpath(unixname))
end
end
def xml_rpc_create
result = BuildServer.create_repo name, platform.name
if result == BuildServer::SUCCESS
return true
else
raise "Failed to create repository #{name} inside platform #{platform.name}."
end
end
def xml_rpc_destroy
result = BuildServer.delete_repo name, platform.name
if result == BuildServer::SUCCESS
return true
else
raise "Failed to delete repository #{name} inside platform #{platform.name}."
end
end
end

View File

@ -16,7 +16,7 @@ class BuildServer
SRPM_NOT_FOUND = 12800
def self.client
@@client ||= XMLRPC::Client.new(:host => AppConfig['build_server_ip'], :port => AppConfig['build_server_port'], :path => AppConfig['build_server_path'])
@@client ||= XMLRPC::Client.new3(:host => APP_CONFIG['build_server_ip'], :port => APP_CONFIG['build_server_port'], :path => APP_CONFIG['build_server_path'])
end
@ -29,18 +29,26 @@ class BuildServer
self.client.call('delete_platform', name)
end
def self.clone_platform new_name, old_name, new_root_folder
self.client.call('clone_platform', new_name, old_name, new_root_folder)
end
def self.create_repo name, platform_name
self.client.call('create_repo', name, platform_name)
self.client.call('create_repository', name, platform_name)
end
def self.delete_repo name, platform_name
self.client.call('delete_repository', name, platform_name)
end
def self.clone_repo new_name, old_name, new_platform_name
self.client.call('clone_repo', new_name, old_name, new_platform_name)
end
def self.publish_container container_id
self.client.call('publish_container', container_id)
end