2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-11-11 17:13:09 +00:00
|
|
|
class ProductBuildList < ActiveRecord::Base
|
|
|
|
BUILD_STARTED = 2
|
|
|
|
BUILD_COMPLETED = 0
|
|
|
|
BUILD_FAILED = 1
|
|
|
|
|
2012-03-30 12:26:28 +01:00
|
|
|
STATUSES = [ BUILD_STARTED,
|
|
|
|
BUILD_COMPLETED,
|
|
|
|
BUILD_FAILED
|
|
|
|
]
|
|
|
|
|
|
|
|
HUMAN_STATUSES = { BUILD_STARTED => :build_started,
|
|
|
|
BUILD_COMPLETED => :build_completed,
|
|
|
|
BUILD_FAILED => :build_failed
|
|
|
|
}
|
|
|
|
|
2011-11-11 17:13:09 +00:00
|
|
|
belongs_to :product
|
|
|
|
|
2012-04-03 21:32:57 +01:00
|
|
|
validates :product_id, :status, :presence => true
|
2011-11-11 17:13:09 +00:00
|
|
|
validates :status, :inclusion => { :in => [BUILD_STARTED, BUILD_COMPLETED, BUILD_FAILED] }
|
|
|
|
|
2012-04-03 21:32:57 +01:00
|
|
|
attr_accessor :base_url
|
|
|
|
attr_accessible :status, :notified_at, :base_url
|
|
|
|
attr_readonly :product_id
|
|
|
|
|
|
|
|
|
2011-11-11 17:13:09 +00:00
|
|
|
scope :default_order, order('notified_at DESC')
|
2012-03-30 12:26:28 +01:00
|
|
|
scope :for_status, lambda {|status| where(:status => status) }
|
|
|
|
scope :for_user, lambda { |user| where(:user_id => user.id) }
|
|
|
|
scope :scoped_to_product_name, lambda {|product_name| joins(:product).where('products.name LIKE ?', "%#{product_name}%")}
|
|
|
|
scope :recent, order("#{table_name}.updated_at DESC")
|
2011-11-11 17:13:09 +00:00
|
|
|
|
|
|
|
after_create :xml_rpc_create
|
2012-02-29 11:15:49 +00:00
|
|
|
after_destroy :xml_delete_iso_container
|
2011-11-11 17:13:09 +00:00
|
|
|
|
2012-02-27 16:21:56 +00:00
|
|
|
def container_path
|
|
|
|
"/downloads/#{product.platform.name}/product/#{id}/"
|
|
|
|
end
|
|
|
|
|
2011-11-11 17:13:09 +00:00
|
|
|
def event_log_message
|
2011-11-11 19:11:27 +00:00
|
|
|
{:product => product.name}.inspect
|
2011-11-11 17:13:09 +00:00
|
|
|
end
|
|
|
|
|
2012-03-30 12:26:28 +01:00
|
|
|
def self.human_status(status)
|
|
|
|
I18n.t("layout.product_build_lists.statuses.#{HUMAN_STATUSES[status]}")
|
|
|
|
end
|
|
|
|
|
|
|
|
def human_status
|
|
|
|
self.class.human_status(status)
|
|
|
|
end
|
|
|
|
|
2011-11-11 17:13:09 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
def xml_rpc_create
|
2011-11-28 21:13:59 +00:00
|
|
|
result = ProductBuilder.create_product self
|
2011-11-11 17:13:09 +00:00
|
|
|
if result == ProductBuilder::SUCCESS
|
|
|
|
return true
|
|
|
|
else
|
2012-04-02 18:39:43 +01:00
|
|
|
raise "Failed to create product_build_list #{id} inside platform #{product.platform.name} tar url #{tar_url} with code #{result}."
|
2012-02-29 11:15:49 +00:00
|
|
|
end
|
|
|
|
end
|
2012-03-31 00:37:54 +01:00
|
|
|
|
2012-02-29 11:15:49 +00:00
|
|
|
def xml_delete_iso_container
|
2012-02-29 12:00:02 +00:00
|
|
|
result = ProductBuilder.delete_iso_container self
|
2012-02-29 11:15:49 +00:00
|
|
|
if result == ProductBuilder::SUCCESS
|
|
|
|
return true
|
|
|
|
else
|
2012-04-02 18:39:43 +01:00
|
|
|
raise "Failed to destroy product_build_list #{id} inside platform #{product.platform.name} with code #{result}."
|
2011-11-11 17:13:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|