From 58f8ce453e3c4d9f1e3a277a7971b962a0d7a1bc Mon Sep 17 00:00:00 2001 From: Alexey Nayden Date: Thu, 7 Apr 2011 13:10:46 +0400 Subject: [PATCH] Platform create/delete RPC calls --- app/models/platform.rb | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/app/models/platform.rb b/app/models/platform.rb index a60902a8c..4f8f8dd07 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -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