Merge pull request #238 from abf/rosa-build:231-increase-time-of-build-for-Cooker-ARM-packages

#231, #230: Add extra settings for main platforms
This commit is contained in:
avm 2013-07-25 14:33:51 +04:00
commit 8117bd1561
19 changed files with 166 additions and 19 deletions

View File

@ -21,6 +21,7 @@ $(document).ready(function() {
extra_repos.show();
} else {
all_repositories.attr('disabled', 'disabled');
updatedDefaultArches(selected_option);
extra_repos.hide();
var parent = build_platform.parent();
parent.find('input').removeAttr('disabled');
@ -77,6 +78,13 @@ $(document).ready(function() {
});
});
function updatedDefaultArches(selected_option) {
$('input[name="arches[]"]').removeAttr('checked');
_.each(selected_option.attr('default_arches').split(' '), function(id){
$('#arches_' + id).attr('checked', 'checked');
});
}
function updateExtraReposAndBuildLists(save_to_platform_id) {
$.each($('.autocomplete-form'), function() {
var form = $(this);

View File

@ -42,11 +42,11 @@ class Platforms::PlatformsController < Platforms::BaseController
@admin_id = params[:admin_id]
@admin_uname = params[:admin_uname]
if @platform.update_attributes(
:owner => @admin_id.blank? ? get_owner : User.find(@admin_id),
:description => params[:platform][:description],
:released => (params[:platform][:released] || @platform.released)
)
platform_params = params[:platform] || {}
platform_params = platform_params.slice(:description, :platform_arch_settings_attributes, :released)
platform_params[:owner] = User.find(@admin_id) if @admin_id.present?
if @platform.update_attributes(platform_params)
flash[:notice] = I18n.t("flash.platform.saved")
redirect_to @platform
else

View File

@ -19,6 +19,20 @@ module BuildListsHelper
.joins(:repositories).uniq
end
def save_to_repositories(project)
project.repositories.collect do |r|
[
"#{r.platform.name}/#{r.name}",
r.id,
{
:publish_without_qa => r.publish_without_qa? ? 1 : 0,
:platform_id => r.platform.id,
:default_arches => r.platform.platform_arch_settings.by_default.pluck(:arch_id).join(' ')
}
]
end
end
def mass_build_options(selected_id)
options_from_collection_for_select(
MassBuild.recent.limit(15),

View File

@ -10,4 +10,15 @@ module PlatformsHelper
platform.released? ? "#{platform.name} #{I18n.t("layout.platforms.released_suffix")}" : platform.name
end
def platform_arch_settings(platform)
settings = platform.platform_arch_settings
settings |= Arch.where('id not in (?)', settings.pluck(:arch_id)).map do |arch|
platform.platform_arch_settings.build(
:arch_id => arch.id,
:time_living => PlatformArchSetting::DEFAULT_TIME_LIVING
)
end
settings.sort_by{ |s| s.arch.name }
end
end

View File

@ -413,7 +413,7 @@ class BuildList < ActiveRecord::Base
{
:id => id,
:arch => arch.name,
:time_living => 43200, # 12 hours
:time_living => (build_for_platform.platform_arch_settings.by_arch(arch).first.try(:time_living) || PlatformArchSetting::DEFAULT_TIME_LIVING),
:distrib_type => build_for_platform.distrib_type,
:git_project_address => git_project_address,
:commit_hash => commit_hash,

View File

@ -8,7 +8,8 @@ class Platform < ActiveRecord::Base
has_many :repositories, :dependent => :destroy
has_many :products, :dependent => :destroy
has_many :tokens, :as => :subject, :dependent => :destroy
has_many :tokens, :as => :subject, :dependent => :destroy
has_many :platform_arch_settings, :dependent => :destroy
has_many :relations, :as => :target, :dependent => :destroy
has_many :actors, :as => :target, :class_name => 'Relation', :dependent => :destroy
@ -53,7 +54,8 @@ class Platform < ActiveRecord::Base
scope :main, by_type('main')
scope :personal, by_type('personal')
attr_accessible :name, :distrib_type, :parent_platform_id, :platform_type, :owner, :visibility, :description, :released
accepts_nested_attributes_for :platform_arch_settings, :allow_destroy => true
attr_accessible :name, :distrib_type, :parent_platform_id, :platform_type, :owner, :visibility, :description, :released, :platform_arch_settings_attributes
attr_readonly :name, :distrib_type, :parent_platform_id, :platform_type
include Modules::Models::Owner

View File

@ -0,0 +1,19 @@
# -*- encoding : utf-8 -*-
class PlatformArchSetting < ActiveRecord::Base
DEFAULT_TIME_LIVING = 43200 # seconds, 12 hours
MIN_TIME_LIVING = 600 # seconds, 10 minutes
MAX_TIME_LIVING = 172800 # seconds, 48 hours
include Modules::Models::TimeLiving
belongs_to :arch
belongs_to :platform
validates :arch_id, :platform_id, :presence => true
validates :platform_id, :uniqueness => {:scope => :arch_id}
scope :by_arch, lambda {|arch| where(:arch_id => arch) if arch.present?}
scope :by_default, where(:default => true)
attr_accessible :arch_id, :platform_id, :default
end

View File

@ -26,10 +26,26 @@
= hidden_field_tag 'admin_id', @admin_id, :id => 'admin_id_field'
.both
%h3= t('layout.platform_arch_settings.extra_settings')
%table.tablesorter{:cellpadding => "0", :cellspacing => "0"}
%thead
%tr
%th.lpadding16= t("activerecord.models.arch")
%th.lpadding16= t("activerecord.attributes.platform_arch_setting.default")
%th.lpadding16= t("activerecord.attributes.platform_arch_setting.time_living")
%tbody
- platform_arch_settings(@platform).each do |setting|
%tr{:class => cycle("odd", "even")}
= f.fields_for :platform_arch_settings, setting do |s_form|
%td
= setting.arch.name
= s_form.hidden_field :arch_id
%td.center= s_form.check_box :default, :class => 'check_box'
%td.right= s_form.text_field :time_living, :value => setting.time_living / 60, :class => 'text_field', :size => 10
.both
.button_block
= submit_tag t('layout.save'), :data => {'disable-with' => t('layout.saving')}
-#%input.button{:type => "submit", :class => "button"}
-#= image_tag("choose.png", :alt => t("layout.save"))
-#= t("layout.clone")
= f.submit t('layout.save'), :data => {'disable-with' => t('layout.saving')}
%span.text_button_padding= t("layout.or")
= link_to t("layout.cancel"), @platform.new_record? ? root_path : platform_path(@platform), :class => "button"

View File

@ -9,7 +9,7 @@
.offset25= render 'include_repos', :platform => pl
%section.right
%h3= t("activerecord.attributes.build_list.save_to_repository")
.lineForm= f.select :save_to_repository_id, @project.repositories.collect{|r| ["#{r.platform.name}/#{r.name}", r.id, {:publish_without_qa => r.publish_without_qa? ? 1 : 0, :platform_id => r.platform.id}]}
.lineForm= f.select :save_to_repository_id, save_to_repositories(@project)
%h3= t("activerecord.attributes.build_list.project_version")
.lineForm= f.select :project_version, versions_for_group_select(@project), :selected => params[:build_list].try(:fetch, :project_version) || @project.default_branch
%h3= t("activerecord.attributes.build_list.arch")

View File

@ -79,6 +79,8 @@ en:
models:
platform: Platform
attributes:
platform/platform_arch_settings:
time_living: Max time build (in minutes)
platform:
name: Name
description: Description

View File

@ -79,6 +79,8 @@ ru:
models:
platform: Платформа
attributes:
platform/platform_arch_settings:
time_living: Максимальное время сборки (в минутах)
platform:
name: Название
description: Описание

View File

@ -0,0 +1,13 @@
en:
layout:
platform_arch_settings:
extra_settings: Extra settings
flash:
platform_arch_settings:
activerecord:
attributes:
platform_arch_setting:
default: Use by default at build
time_living: Max time build (in minutes)

View File

@ -0,0 +1,13 @@
ru:
layout:
platform_arch_settings:
extra_settings: Дополнительные настройки
flash:
platform_arch_settings:
activerecord:
attributes:
platform_arch_setting:
default: Использовать по умолчанию при сборке
time_living: Максимальное время сборки (в минутах)

View File

@ -1,4 +1,4 @@
en:
flash:
time_living:
numericality_error: must be 2 to 720 minutes
numericality_error: must be %{min} to %{max} minutes

View File

@ -1,4 +1,4 @@
ru:
flash:
time_living:
numericality_error: должно быть от 2 до 720 минут
numericality_error: должно быть от %{min} до %{max} минут

View File

@ -0,0 +1,29 @@
class CreatePlatformArchSettings < ActiveRecord::Migration
def up
create_table :platform_arch_settings do |t|
t.integer :platform_id, :null => false
t.integer :arch_id, :null => false
t.integer :time_living, :null => false
t.boolean :default
t.timestamps
end
add_index :platform_arch_settings, [:platform_id, :arch_id], :unique => true
arch_ids = Arch.where(:name => %w(i586 x86_64)).pluck(:id)
Platform.main.each do |platform|
arch_ids.each do |arch_id|
platform.platform_arch_settings.create(
:arch_id => arch_id,
:default => true,
:time_living => PlatformArchSetting::DEFAULT_TIME_LIVING / 60
)
end
end
end
def down
drop_table :platform_arch_settings
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130717112337) do
ActiveRecord::Schema.define(:version => 20130724105821) do
create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false
@ -294,6 +294,17 @@ ActiveRecord::Schema.define(:version => 20130717112337) do
t.text "extra_build_lists"
end
create_table "platform_arch_settings", :force => true do |t|
t.integer "platform_id", :null => false
t.integer "arch_id", :null => false
t.integer "time_living", :null => false
t.boolean "default"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "platform_arch_settings", ["platform_id", "arch_id"], :name => "index_platform_arch_settings_on_platform_id_and_arch_id", :unique => true
create_table "platforms", :force => true do |t|
t.string "description"
t.string "name", :null => false

View File

@ -11,9 +11,16 @@ module Modules
}, :presence => true
validate lambda {
# MIN_TIME_LIVING <= time_living <= MAX_TIME_LIVING or
# 2 min <= time_living <= 12 hours
if 120 > time_living.to_i || time_living.to_i > 43200
errors.add(:time_living, I18n.t('flash.time_living.numericality_error'))
# time_living in seconds
min = self.class.const_defined?(:MIN_TIME_LIVING) ? self.class::MIN_TIME_LIVING : 120
max = self.class.const_defined?(:MAX_TIME_LIVING) ? self.class::MAX_TIME_LIVING : 43200
if min > time_living.to_i || time_living.to_i > max
errors.add :time_living, I18n.t('flash.time_living.numericality_error',
:min => (min / 60),
:max => (max / 60)
)
end
}