From b39ccea0d56eeeeea10822b7632877d13306b723 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 9 Nov 2012 17:08:56 +0400 Subject: [PATCH] add show logs in real time --- .../product_build_lists_controller.rb | 12 ++++++-- app/models/product.rb | 2 +- app/models/product_build_list.rb | 25 +++++++--------- .../_product_build_list.html.haml | 4 +-- .../product_build_lists/new.html.haml | 8 ++--- .../product_build_lists/show.html.haml | 29 +++++++++++-------- app/views/platforms/products/_form.html.haml | 8 +++++ .../locales/models/product_build_list.en.yml | 3 +- .../locales/models/product_build_list.ru.yml | 3 +- ...integrate_new_iso_builder_with_products.rb | 8 +++++ db/schema.rb | 2 ++ 11 files changed, 65 insertions(+), 39 deletions(-) diff --git a/app/controllers/platforms/product_build_lists_controller.rb b/app/controllers/platforms/product_build_lists_controller.rb index 56dc790d9..7b1666545 100644 --- a/app/controllers/platforms/product_build_lists_controller.rb +++ b/app/controllers/platforms/product_build_lists_controller.rb @@ -11,12 +11,18 @@ class Platforms::ProductBuildListsController < Platforms::BaseController before_filter :find_product_build_list, :only => [:status_build] def new - @project = @product_build_list.product.project - raise ActiveRecord::RecordNotFound unless @project - @arches = Arch.recent.map{ |a| [a.name, a.id] } + product = @product_build_list.product + @product_build_list.params = product.params + @product_build_list.main_script = product.main_script + @product_build_list.project = product.project + unless @product_build_list.project + flash[:error] = t('flash.product_build_list.no_project') + redirect_to edit_platform_product_path(@platform, @product) + end end def show + @logs = JSON.parse(Resque.redis.get("abfworker::iso-worker-#{@product_build_list.id}") || '[]') end def create diff --git a/app/models/product.rb b/app/models/product.rb index e7203928e..8d296867a 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -8,7 +8,7 @@ class Product < ActiveRecord::Base scope :recent, order("name ASC") - attr_accessible :name, :description, :project_id + attr_accessible :name, :description, :project_id, :main_script, :params attr_readonly :platform_id def full_clone(attrs = {}) diff --git a/app/models/product_build_list.rb b/app/models/product_build_list.rb index 72600c47b..4e6b82aa1 100644 --- a/app/models/product_build_list.rb +++ b/app/models/product_build_list.rb @@ -63,8 +63,6 @@ class ProductBuildList < ActiveRecord::Base protected def xml_rpc_create - # TODO: run ISO worker - # result = ProductBuilder.create_product self file_name = "#{project.owner.uname}-#{project.name}-#{commit_hash}" srcpath = url_helpers.archive_url( project.owner, @@ -75,33 +73,30 @@ class ProductBuildList < ActiveRecord::Base ) options = { :id => id, - :srcpath => 'http://dl.dropbox.com/u/945501/avokhmin-test-iso-script-f94caef701bf234505ef107a02e309037a9a57a4.tar.gz', + # TODO: revert changes + :srcpath => 'http://dl.dropbox.com/u/945501/avokhmin-test-iso-script-5d9b463d4e9c06ea8e7c89e1b7ff5cb37e99e27f.tar.gz', :params => params, :main_script => main_script } - # if result == ProductBuilder::SUCCESS - Resque.push( 'iso_worker', 'class' => 'AbfWorker::IsoWorker', 'args' => [options] ) return true - # if Resque.enqueue(AbfWorker::IsoWorker, options) - # return true - # else - # raise "Failed to create product_build_list #{id} inside platform #{product.platform.name} with params: #{options.inspect}" - # end end def xml_delete_iso_container # TODO: write new worker for delete - # result = ProductBuilder.delete_iso_container self - result = ProductBuilder::SUCCESS - if result == ProductBuilder::SUCCESS - return true + if project + raise "Failed to destroy product_build_list #{id} inside platform #{product.platform.name} (Not Implemented)." else - raise "Failed to destroy product_build_list #{id} inside platform #{product.platform.name} with code #{result}." + result = ProductBuilder.delete_iso_container self + if result == ProductBuilder::SUCCESS + return true + else + raise "Failed to destroy product_build_list #{id} inside platform #{product.platform.name} with code #{result}." + end end end end diff --git a/app/views/platforms/product_build_lists/_product_build_list.html.haml b/app/views/platforms/product_build_lists/_product_build_list.html.haml index 7885f9779..3b1765fc1 100644 --- a/app/views/platforms/product_build_lists/_product_build_list.html.haml +++ b/app/views/platforms/product_build_lists/_product_build_list.html.haml @@ -7,7 +7,7 @@ - else %td= pbl.id %td= pbl.human_status - %td= link_to nil, pbl.container_path + %td= link_to(nil, pbl.container_path) unless pbl.project %td= link_to pbl.product.name, platform_product_path(platform, product) - %td= link_to image_tag('x.png'), platform_product_product_build_list_path(platform, product, pbl), :method => :delete, :confirm => t("layout.confirm") if can?(:destroy, pbl) && pbl.can_destroy? + %td= link_to image_tag('x.png'), platform_product_product_build_list_path(platform, product, pbl), :method => :delete, :confirm => t("layout.confirm") if can?(:destroy, pbl) && pbl.can_destroy? && !pbl.project %td= l(pbl.updated_at, :format => :long) \ No newline at end of file diff --git a/app/views/platforms/product_build_lists/new.html.haml b/app/views/platforms/product_build_lists/new.html.haml index e74a02eab..0621346de 100644 --- a/app/views/platforms/product_build_lists/new.html.haml +++ b/app/views/platforms/product_build_lists/new.html.haml @@ -2,14 +2,14 @@ = render 'submenu' %h3= t("layout.product_build_lists.main_data") - -= form_for @product_build_list, :url => platform_product_product_build_lists_path(@platform, @product), :html => {:class => :form} do |f| +- pbl = @product_build_list += form_for pbl, :url => platform_product_product_build_lists_path(@platform, @product), :html => {:class => :form} do |f| .leftlist= f.label :project, t("activerecord.attributes.product_build_list.project"), :class => :label - .rightlist= @product_build_list.product.project.try(:name_with_owner) + .rightlist= pbl.project.name_with_owner .both .leftlist= f.label :project_version, t("activerecord.attributes.product_build_list.project_version"), :class => :label - .rightlist= f.select :project_version, versions_for_group_select(@project), :selected => params[:product_build_lists].try(:fetch, :project_version) || "latest_" + @project.default_branch + .rightlist= f.select :project_version, versions_for_group_select(pbl.project), :selected => params[:product_build_lists].try(:fetch, :project_version) || "latest_" + pbl.project.default_branch .both .leftlist= f.label :main_script, t("activerecord.attributes.product_build_list.main_script"), :class => :label diff --git a/app/views/platforms/product_build_lists/show.html.haml b/app/views/platforms/product_build_lists/show.html.haml index 7fc60ce0e..e7db880d7 100644 --- a/app/views/platforms/product_build_lists/show.html.haml +++ b/app/views/platforms/product_build_lists/show.html.haml @@ -15,16 +15,12 @@ .rightlist= pbl.human_status .both -.leftlist= t("activerecord.attributes.product_build_list.container_path") -.rightlist= link_to nil, pbl.container_path -.both - .leftlist= t("activerecord.attributes.product_build_list.product") .rightlist= link_to pbl.product.name, platform_product_path(platform, product) .both .leftlist= t("activerecord.attributes.product_build_list.project") -.rightlist= pbl.project.name_with_owner +.rightlist= link_to pbl.project.name_with_owner, project_path(pbl.project) .both .leftlist= t("activerecord.attributes.product_build_list.project_version") @@ -39,14 +35,25 @@ .rightlist= pbl.params .both -.leftlist= t("layout.product_build_lists.action") -.rightlist= link_to image_tag('x.png'), platform_product_product_build_list_path(platform, product, pbl), :method => :delete, :confirm => t("layout.confirm") if can?(:destroy, pbl) && pbl.can_destroy? -.both - .leftlist= t("activerecord.attributes.product_build_list.notified_at") .rightlist= l(pbl.updated_at, :format => :long) .both +- if @logs.present? + %h3= t("layout.product_build_lists.logs") + %table.tablesorter.width565{:cellpadding => "0", :cellspacing => "0"} + %thead + %tr + %th= '#' + %th + %tbody + - @logs.each do |item| + %tr + %td= item[0] + %td= item[1] + + .both + %h3= t("layout.product_build_lists.results") - unless pbl.results.present? %h4.nomargin= t("layout.product_build_lists.no_results") @@ -56,14 +63,12 @@ %tr %th= t("activerecord.attributes.product_build_list/results.file_name") %th= t("activerecord.attributes.product_build_list/results.sha1") - %th= t("activerecord.attributes.product_build_list/results.link") %tbody - pbl.results.each do |item| %tr - %td= item['file_name'] - sha1 = item['sha1'] + %td= link_to item['file_name'], "http://file-store.rosalinux.ru/api/v1/file_stores/#{sha1}" %td= sha1 - %td= link_to t("activerecord.attributes.product_build_list/results.link"), "http://file-store.rosalinux.ru/api/v1/file_stores/#{sha1}" .both diff --git a/app/views/platforms/products/_form.html.haml b/app/views/platforms/products/_form.html.haml index 5fcecc1e8..3bfdd9888 100644 --- a/app/views/platforms/products/_form.html.haml +++ b/app/views/platforms/products/_form.html.haml @@ -10,6 +10,14 @@ .rightlist= f.autocomplete_field :project, autocomplete_project_platform_products_path(@platform), :id_element => 'src_project_id', :name => 'src_project', :value => @product.project.try(:name_with_owner) .both +.leftlist= f.label :main_script, t("activerecord.attributes.product_build_list.main_script"), :class => :label +.rightlist= f.text_field :main_script +.both + +.leftlist= f.label :params, t("activerecord.attributes.product_build_list.params"), :class => :label +.rightlist= f.text_field :params +.both + .button_block = submit_tag t("layout.save") %span.text_button_padding= t("layout.or") diff --git a/config/locales/models/product_build_list.en.yml b/config/locales/models/product_build_list.en.yml index 6baf8374b..8487cb6c9 100644 --- a/config/locales/models/product_build_list.en.yml +++ b/config/locales/models/product_build_list.en.yml @@ -1,6 +1,7 @@ en: layout: product_build_lists: + logs: Logs results: Results work_env: Work environment iso_builder_folder: folder with contents of the GIT project @@ -42,9 +43,9 @@ en: product_build_list/results: file_name: File name sha1: SHA1 - link: Link flash: product_build_list: + no_project: Project for build should be exist delete: Product build list deleted delete_error: Unable to delete product build list \ No newline at end of file diff --git a/config/locales/models/product_build_list.ru.yml b/config/locales/models/product_build_list.ru.yml index 1f0a919f9..9c879d88d 100644 --- a/config/locales/models/product_build_list.ru.yml +++ b/config/locales/models/product_build_list.ru.yml @@ -1,6 +1,7 @@ ru: layout: product_build_lists: + logs: Логи results: Результаты work_env: Рабочее пространство iso_builder_folder: папка с содержимым GIT проекта @@ -42,10 +43,10 @@ ru: product_build_list/results: file_name: Имя файла sha1: SHA1 - link: Ссылка flash: product_build_list: + no_project: Проект для сборки должен присутствовать delete: Сборочный лист продукта удален delete_error: Не удалось удалить cборочный лист продукта diff --git a/db/migrate/20121106113338_integrate_new_iso_builder_with_products.rb b/db/migrate/20121106113338_integrate_new_iso_builder_with_products.rb index 2cf75faf6..5c8f0ce7f 100644 --- a/db/migrate/20121106113338_integrate_new_iso_builder_with_products.rb +++ b/db/migrate/20121106113338_integrate_new_iso_builder_with_products.rb @@ -18,7 +18,11 @@ class IntegrateNewIsoBuilderWithProducts < ActiveRecord::Migration add_column :product_build_lists, :commit_hash, :string add_column :product_build_lists, :params, :string + add_column :products, :params, :string + add_column :product_build_lists, :main_script, :string + add_column :products, :main_script, :string + add_column :product_build_lists, :results, :text end @@ -41,7 +45,11 @@ class IntegrateNewIsoBuilderWithProducts < ActiveRecord::Migration remove_column :product_build_lists, :commit_hash remove_column :product_build_lists, :params + remove_column :products, :params + remove_column :product_build_lists, :main_script + remove_column :products, :main_script + remove_column :product_build_lists, :results end end diff --git a/db/schema.rb b/db/schema.rb index 86cdd0711..00c840ef2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -298,6 +298,8 @@ ActiveRecord::Schema.define(:version => 20121106113338) do t.datetime "updated_at" t.text "description" t.integer "project_id" + t.string "params" + t.string "main_script" end create_table "project_imports", :force => true do |t|