From dce4e76da1ee4fdfd892a2228e8001565677e8f3 Mon Sep 17 00:00:00 2001 From: Alexey Nayden Date: Mon, 11 Apr 2011 20:55:52 +0400 Subject: [PATCH] Product management. Step 1 --- app/controllers/products_controller.rb | 24 ++ app/models/platform.rb | 7 + app/models/product.rb | 9 +- app/views/platforms/show.html.haml | 22 ++ app/views/products/_form.html.haml | 23 ++ app/views/products/new.html.haml | 12 + config/initializers/default_product_files.rb | 238 ++++++++++++++++++ config/locales/ru.yml | 23 +- .../20110411125015_add_fields_to_products.rb | 15 ++ db/schema.rb | 6 +- 10 files changed, 373 insertions(+), 6 deletions(-) create mode 100644 app/views/products/_form.html.haml create mode 100644 app/views/products/new.html.haml create mode 100644 config/initializers/default_product_files.rb create mode 100644 db/migrate/20110411125015_add_fields_to_products.rb diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index a633719f1..4e82da3fe 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -1,6 +1,7 @@ class ProductsController < ApplicationController before_filter :authenticate_user!, :except => [:product_begin, :product_end] before_filter :find_product_by_name, :only => [:product_begin, :product_end] + before_filter :find_platform, :except => [:product_begin, :product_end] def product_begin @product.build_status = Product::STATUS::BUILDING @@ -17,10 +18,33 @@ class ProductsController < ApplicationController render :nothing => true, :status => 200 end + + def new + @product = @platform.products.new + @product.ks = DEFAULT_KS + @product.menu = DEFAULT_MENU + @product.counter = DEFAULT_COUNTER + @product.build = DEFAULT_BUILD + end + + def create + @product = @platform.products.new params[:product] + if @product.save + flash[:notice] = '' + redirect_to @platform + else + flash[:error] = '' + render :action => :new + end + end protected def find_product_by_name @product = Product.find_by_name params[:product_name] end + + def find_platform + @platform = Platform.find params[:platform_id] + end end diff --git a/app/models/platform.rb b/app/models/platform.rb index bb1566114..b1da53c3c 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -8,6 +8,7 @@ class Platform < ActiveRecord::Base before_create :xml_rpc_create before_destroy :xml_rpc_destroy + before_update :check_freezing def path @@ -65,4 +66,10 @@ class Platform < ActiveRecord::Base raise "Failed to delete platform #{name}." end end + + def check_freezing + if released_changed? + BuildServer.freeze_platform self.name + end + end end diff --git a/app/models/product.rb b/app/models/product.rb index 51661c3b8..87e91e548 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,11 +1,14 @@ class Product < ActiveRecord::Base + NEVER_BUILT = 2 + BUILD_COMPLETED = 0 + BUILD_FAILED = 1 + + validates :name, :presence => true, :uniqueness => true validates :platform_id, :presence => true validates :build_status, :inclusion => { :in => [ NEVER_BUILT, BUILD_COMPLETED, BUILD_FAILED ] } belongs_to :platform - NEVER_BUILT = 2 - BUILD_COMPLETED = 0 - BUILD_FAILED = 1 + scope :recent, order("name ASC") end diff --git a/app/views/platforms/show.html.haml b/app/views/platforms/show.html.haml index 21ee4f885..a99777e3d 100644 --- a/app/views/platforms/show.html.haml +++ b/app/views/platforms/show.html.haml @@ -60,5 +60,27 @@ .actions-bar.wat-cf .actions +%a{ :name => "producs" } +.block + .secondary-navigation + %ul.wat-cf + %li.first.active= link_to t("layout.products.list"), platform_path(@platform) + "#products" + %li= link_to t("layout.products.new"), new_platform_product_path(@platform) + .content + %h2.title + = t("layout.products.list_header") + .inner + %table.table + %tr + %th.first= t("activerecord.attributes.product.name") + %th.last   + - @platform.products.recent.each do |product| + %tr{:class => cycle("odd", "even")} + %td + = link_to product.name, platform_product_path(@platform, product) + %td.last + #{link_to t("layout.show"), platform_product_path(@platform, product)} | #{link_to t("layout.delete"), platform_product_path(@platform, product), :method => :delete, :confirm => t("layout.products.confirm_delete")} + .actions-bar.wat-cf + .actions -#- content_for :sidebar do diff --git a/app/views/products/_form.html.haml b/app/views/products/_form.html.haml new file mode 100644 index 000000000..a96fa0e3e --- /dev/null +++ b/app/views/products/_form.html.haml @@ -0,0 +1,23 @@ +.group + = f.label :name, t("activerecord.attributes.product.name"), :class => :label + = f.text_field :name, :class => 'text_field' +.group + = f.label :build, t("activerecord.attributes.product.build"), :class => :label + = f.text_area :build, :class => 'text_field', :cols => 80 +.group + = f.label :counter, t("activerecord.attributes.product.counter"), :class => :label + = f.text_area :counter, :class => 'text_field', :cols => 80 +.group + = f.label :ks, t("activerecord.attributes.product.ks"), :class => :label + = f.text_area :ks, :class => 'text_field', :cols => 80 +.group + = f.label :menu, t("activerecord.attributes.product.menu"), :class => :label + = f.text_area :menu, :class => 'text_field', :cols => 80 + +.group.navform.wat-cf + %button.button{:type => "submit"} + = image_tag("web-app-theme/icons/tick.png", :alt => t("layout.save")) + = t("layout.save") + %span.text_button_padding= t("layout.or") + = link_to t("layout.cancel"), platform_path(@platform), :class => "text_button_padding link_button" + diff --git a/app/views/products/new.html.haml b/app/views/products/new.html.haml new file mode 100644 index 000000000..3b503559d --- /dev/null +++ b/app/views/products/new.html.haml @@ -0,0 +1,12 @@ +.block + .secondary-navigation + %ul.wat-cf + %li.first= link_to @platform.name, platform_path(@platform) + "#products" + %li.active= link_to t("layout.products.new"), new_platform_product_path(@platform) + .content + %h2.title= t("layout.products.new_header") + .inner + = form_for [@platform, @product], :html => { :class => :form } do |f| + = render :partial => "form", :locals => {:f => f} + +-#- content_for :sidebar, render(:partial => 'sidebar') diff --git a/config/initializers/default_product_files.rb b/config/initializers/default_product_files.rb new file mode 100644 index 000000000..6222e022c --- /dev/null +++ b/config/initializers/default_product_files.rb @@ -0,0 +1,238 @@ +DEFAULT_KS = <<-eos +timezone Europe/Moscow +auth --useshadow --enablemd5 +selinux --disabled +firewall --enabled +firstboot --enabled +part / --size 8692 + +services --enabled=acpid,alsa,atd,atieventsd,avahi-daemon,dm,haldaemon,iptables,ip6tables,irqbalance,mandi,messagebus,msec,netfs,network,network-up,numlock,partmon,resolvconf,rpcbind,rsyslog,shorewall,sound,stop-bootlogd,udev-post,cups,mandrake_everytime,mandrake_firsttime +services --disabled=kudzu,sshd,crond,auditd,autofs,fuse,pptp,pppoe,ntpd + +repo --name=Main --baseurl=http://10.3.0.12/iso/repository/rpm/external/mdv/cooker/cooker/media/main/release/ +#repo --name=Non-Free --baseurl=file:///mnt/BIG/devel/cooker/#ARCH#/media/non-free/release +#repo --name=Livecd --baseurl=file:///home/LIVE/rpm/i586/ +repo --name=Rosa.add --baseurl=http://10.3.0.12/iso/repository/Projects/mdv/sasha/ROSA.add.2011/RPMS +#repo --name=Contrib --baseurl=http://10.3.0.12/iso/repository/rpm/external/mdv/cooker/cooker/media/contrib/release/ + +%packages +%include #PATH#/mdv-kde-one.lst.3 +#%include #PATH#/mdv-base.lst +%end + +%post + +echo "ROSA Desktop 2011.beta" > /etc/redhat-release +echo "ROSA Desktop 2011.beta" > /etc/issue +echo "ROSA Desktop 2011.beta" > /etc/issue.net +echo "ROSA Desktop 2011.beta" > /etc/system-release + + +#### WORKAROUND FOR DBUS ### +/usr/sbin/useradd messagebus -d / -s /bin/false +#### END OF IT #### + +echo "" +/bin/ls -l /boot/ +echo "" +echo "###################################### Make initrd symlink >> " +echo "" + +/usr/sbin/update-alternatives --set mkinitrd /sbin/mkinitrd-dracut +rm -rf /boot/initrd-* + + +# adding life user +/usr/sbin/adduser live +/usr/bin/passwd -d live +/bin/mkdir -p /home/live +/bin/cp -rfT /etc/skel /home/live/ +/bin/chown -R live:live /home/live + + +# ldetect stuff +/usr/sbin/update-ldetect-lst + +# setting up network manager by default +pushd /etc/sysconfig/network-scripts +for iface in eth0 wlan0; do + cat > ifcfg-$iface << EOF +DEVICE=eth0 +ONBOOT=yes +NM_CONTROLLED=yes +EOF +done +popd +#### workaround for NETWORKMANAGER + +systemctl enable networkmanager.service + +### END OF IT + +# kde look-and-feel, should do into kde-common package +#sed -i 's/widgetStyle=iaorakde/widgetStyle=qtcurve/g' /var/lib/mandriva/kde4-profiles/common/share/config/kdeglobals +#sed -i 's/colorScheme=Ia Ora Smooth/colorScheme=Norway/g' /var/lib/mandriva/kde4-profiles/common/share/config/kdeglobals + +# default background +pushd /usr/share/mdk/backgrounds/ +ln -s rosa.jpg default.jpg +#popd + +# mtab +pushd /etc/ +ln -sf /proc/mounts mtab +popd + +# + +# +# kernel +# + +# +# Sysfs must be mounted for dracut to work! +# +mount -t sysfs /sys /sys + +pushd /lib/modules/ +KERNEL=$(echo *) +popd +echo +echo Generating kernel. System kernel is `uname -r`, installed kernels are: +rpm -qa kernel-* +echo Detected kernel version: $KERNEL + +/sbin/dracut --add-drivers "sr-mod" /boot/initramfs-$KERNEL.img $KERNEL +ls -l /boot/ + +echo + +# +# +# +# echo +# echo +# echo "Giving you a shell to fix stuff, good luck!" +# echo +# echo +# echo + +# /bin/bash + +echo "" +echo "###################################### Build ISO >> " +echo "" + +%post --nochroot + + cp -rfT #PATH#/extraconfig/etc $INSTALL_ROOT/etc/ + + cp -f #PATH#/root/GPL $LIVE_ROOT/ + mkdir -p $LIVE_ROOT/Addons + cp /usr/bin/livecd-iso-to-disk $LIVE_ROOT/Addons/ + chmod +x $LIVE_ROOT/Addons/livecd-iso-to-disk + rpm --root $INSTALL_ROOT -qa | sort > $LIVE_ROOT/rpm.lst + +%end + +eos + +DEFAULT_MENU=<<-eos + + + + Welcome to + + + ROSA 2011 Beta + + + vga=788 + desktop + nopat + rd_NO_LUKS + rd_NO_MD + noiswmd + splash=silent + + + vga=788 + desktop + nopat + rd_NO_LUKS + rd_NO_MD + noiswmd + splash=silent + install + + + /home/LIVE/ROSA.2011/welcome.jpg + + + /home/LIVE/ROSA.2011/cyra8x16.psf + + +eos + +DEFAULT_COUNTER=<<-eos +63 +eos + +DEFAULT_BUILD=<<-eos +#!/bin/sh + +#ARCHS="i586 x86_64" +#ARCHS="i586" + +#if [ ! "$UID" = "0" ]; then# +# echo "Restarting as root.." +# exec sudo $0 +#fi + +# a temporary hack to make python 2.6 work +export PYTHONPATH=/usr/lib/python2.6/site-packages/ + +DIRNAME=$(dirname $0) +cd $DIRNAME + +build_root="/home/LIVE/" + +d=`date +%Y.%m.%d-%H.%M` + +product_id="ROSA.2011" +product_name_file="${build_root}/${product_id}/.name.txt" ; touch ${product_name_file} + +#ks="${build_root}/${product_id}/.ks" + +ks="${build_root}/${product_id}/.ks" +counter="${build_root}/${product_id}/.counter" +menu="${build_root}/${product_id}/.menu.xml" + +touch ${counter} + +i=`cat ${counter}` +i=`expr $i + 1` + +echo $i > ${counter} + +echo "$i.$d" > ${build_root}/${product_id}/version.txt + +# build different architectures + +#for arch in $ARCHS; do + cp -f ${ks}.template ${ks} +# sed -i -e "s:#ARCH#:$arch:g" ${ks} + sed -i -e "s:#PATH#:${build_root}/${product_id}:g" ${ks} + sed -i -e "s:#PATH#:${build_root}/${product_id}:g" ${menu} + + mkdir -p $build_root/iso/${product_id}/ + # run with lower priority + livecd-creator --config=${ks} --fslabel=${product_id}.$i --menu-config=${build_root}/${product_id}/.menu.xml + + mv ${product_id}.$i.iso $build_root/iso/${product_id}/ + #md5sum /iso/${product_id}/${product_id}.$i.iso > /iso/${product_id}/${product_id}.$i.iso.md5sum + + echo "" + echo " ALL DONE! $build_root/iso/${product_id}/${product_id}.$i.iso" + echo "" +eos diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 9c3addeb7..f763c0e12 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -52,6 +52,12 @@ ru: back_to_the_list: ⇐ К списку репозиториев confirm_delete: Вы уверены, что хотите удалить этот репозиторий? current_repository_header: Текущий репозиторий + products: + list: Список + new: Новый продукт + list_header: Продукты + new_header: Новый продукт + confirm_delete: Вы уверены, что хотите удалить этот продукт? projects: list: Список list_header: Проекты @@ -140,6 +146,7 @@ ru: project: Проект rpm: RPM user: Пользователь + product: Продукт attributes: repository: @@ -147,8 +154,20 @@ ru: platform_id: Платформа platform: Платформа unixname: Unixname - created_at: Создана - updated_at: Обновлена + created_at: Создан + updated_at: Обновлен + + product: + name: Название + platform_id: Платформа + build_status: Статус последней сборки + build_path: Путь к iso + created_at: Создан + updated_at: Обновлен + ks: Содержимое .ks.template + counter: Содержимое .counter + build: Содержимое build + menu: Содержимое .menu.xml arch: name: Название diff --git a/db/migrate/20110411125015_add_fields_to_products.rb b/db/migrate/20110411125015_add_fields_to_products.rb new file mode 100644 index 000000000..b845eb38c --- /dev/null +++ b/db/migrate/20110411125015_add_fields_to_products.rb @@ -0,0 +1,15 @@ +class AddFieldsToProducts < ActiveRecord::Migration + def self.up + add_column :products, :build, :text + add_column :products, :counter, :text + add_column :products, :ks, :text + add_column :products, :menu, :text + end + + def self.down + remove_column :products, :menu + remove_column :products, :ks + remove_column :products, :counter + remove_column :products, :build + end +end diff --git a/db/schema.rb b/db/schema.rb index 96e8a1e44..3fbf6ee87 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20110411082826) do +ActiveRecord::Schema.define(:version => 20110411125015) do create_table "arches", :force => true do |t| t.string "name", :null => false @@ -61,6 +61,10 @@ ActiveRecord::Schema.define(:version => 20110411082826) do t.string "build_path" t.datetime "created_at" t.datetime "updated_at" + t.text "build" + t.text "counter" + t.text "ks" + t.text "menu" end create_table "projects", :force => true do |t|