[refs #1861] Add downloads statistics
This commit is contained in:
parent
f3d32273d8
commit
8103b14e15
|
@ -11,3 +11,4 @@ public/stylesheets/compiled/*
|
||||||
public/assets/*
|
public/assets/*
|
||||||
config/initializers/local.rb
|
config/initializers/local.rb
|
||||||
public/system/*
|
public/system/*
|
||||||
|
*.swp
|
||||||
|
|
1
Gemfile
1
Gemfile
|
@ -52,5 +52,6 @@ gem "grit"
|
||||||
gem 'unicorn'
|
gem 'unicorn'
|
||||||
gem 'delayed_job'
|
gem 'delayed_job'
|
||||||
gem 'paperclip', "~> 2.3"
|
gem 'paperclip', "~> 2.3"
|
||||||
|
gem 'whenever', :require => false
|
||||||
|
|
||||||
gem 'jammit'
|
gem 'jammit'
|
||||||
|
|
|
@ -42,6 +42,7 @@ GEM
|
||||||
net-ssh-gateway (>= 1.0.0)
|
net-ssh-gateway (>= 1.0.0)
|
||||||
capistrano-ext (1.2.1)
|
capistrano-ext (1.2.1)
|
||||||
capistrano (>= 1.0.0)
|
capistrano (>= 1.0.0)
|
||||||
|
chronic (0.6.4)
|
||||||
closure-compiler (1.1.1)
|
closure-compiler (1.1.1)
|
||||||
compass (0.10.6)
|
compass (0.10.6)
|
||||||
haml (>= 3.0.4)
|
haml (>= 3.0.4)
|
||||||
|
@ -139,6 +140,9 @@ GEM
|
||||||
warden (1.0.3)
|
warden (1.0.3)
|
||||||
rack (>= 1.0.0)
|
rack (>= 1.0.0)
|
||||||
web-app-theme (0.6.3)
|
web-app-theme (0.6.3)
|
||||||
|
whenever (0.7.0)
|
||||||
|
activesupport (>= 2.3.4)
|
||||||
|
chronic (~> 0.6.3)
|
||||||
will_paginate (3.0.pre2)
|
will_paginate (3.0.pre2)
|
||||||
yui-compressor (0.9.5)
|
yui-compressor (0.9.5)
|
||||||
|
|
||||||
|
@ -166,4 +170,5 @@ DEPENDENCIES
|
||||||
russian
|
russian
|
||||||
unicorn
|
unicorn
|
||||||
web-app-theme (>= 0.6.2)
|
web-app-theme (>= 0.6.2)
|
||||||
|
whenever
|
||||||
will_paginate (~> 3.0.pre2)
|
will_paginate (~> 3.0.pre2)
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class DownloadsController < ApplicationController
|
||||||
|
def index
|
||||||
|
@downloads = Download.paginate :page => params[:page], :per_page => 30
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,2 @@
|
||||||
|
module DownloadHelper
|
||||||
|
end
|
|
@ -0,0 +1,38 @@
|
||||||
|
class Download < ActiveRecord::Base
|
||||||
|
PREV_LOG_FILE = "#{ APP_CONFIG['nginx_log'] }.0"
|
||||||
|
|
||||||
|
default_scope order(:name)
|
||||||
|
|
||||||
|
class << self
|
||||||
|
def rotate_nginx_log
|
||||||
|
system("mv #{ APP_CONFIG['nginx_log'] } #{ PREV_LOG_FILE }")
|
||||||
|
system("sudo kill -USR1 `cat #{ APP_CONFIG['nginx_pid'] }`")
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_nginx_log
|
||||||
|
File.open(PREV_LOG_FILE) do |log|
|
||||||
|
while (line = log.gets)
|
||||||
|
if package = line.match( /GET \/.+\/([\w\d]+)-([\d.]+)-((\d+mdv[\d.]+)|([\d\w]+-mdv[\d.]+))\.([\w\d]+)\.rpm/ )
|
||||||
|
increase(
|
||||||
|
:name => package[1],
|
||||||
|
:version => package[2],
|
||||||
|
:distro => package[3].sub(/-/, ''),
|
||||||
|
:platform => package[6]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_and_remove_nginx_log
|
||||||
|
parse_nginx_log
|
||||||
|
system("rm -f #{PREV_LOG_FILE}")
|
||||||
|
end
|
||||||
|
|
||||||
|
def increase(opts={})
|
||||||
|
download = find_or_initialize_by_name_and_version_and_platform_and_distro(opts)
|
||||||
|
download.counter += 1
|
||||||
|
download.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,28 @@
|
||||||
|
.block
|
||||||
|
.content
|
||||||
|
%h2.title
|
||||||
|
= t("layout.downloads.title")
|
||||||
|
.inner
|
||||||
|
%table.table
|
||||||
|
%tr
|
||||||
|
%th.first= t("activerecord.attributes.download.name")
|
||||||
|
%th= t("activerecord.attributes.download.version")
|
||||||
|
%th= t("activerecord.attributes.download.distro")
|
||||||
|
%th= t("activerecord.attributes.download.platform")
|
||||||
|
%th.last= t("activerecord.attributes.download.counter")
|
||||||
|
- @downloads.each do |download|
|
||||||
|
%tr{:class => cycle("odd", "even")}
|
||||||
|
%td
|
||||||
|
= download.name
|
||||||
|
%td
|
||||||
|
= download.version
|
||||||
|
%td
|
||||||
|
= download.distro
|
||||||
|
%td
|
||||||
|
= download.platform
|
||||||
|
%td.last
|
||||||
|
= download.counter
|
||||||
|
.actions-bar.wat-cf
|
||||||
|
.actions
|
||||||
|
= will_paginate @downloads
|
||||||
|
|
|
@ -20,13 +20,15 @@
|
||||||
%a{:href => users_path}= t("layout.menu.users")
|
%a{:href => users_path}= t("layout.menu.users")
|
||||||
%li{:class => controller.controller_path == 'platforms' ? 'active' : '' }
|
%li{:class => controller.controller_path == 'platforms' ? 'active' : '' }
|
||||||
%a{:href => platforms_path}= t("layout.menu.platforms")
|
%a{:href => platforms_path}= t("layout.menu.platforms")
|
||||||
|
%li{:class => controller.controller_path == 'downloads' ? 'active' : '' }
|
||||||
|
%a{:href => downloads_path}= t("layout.menu.downloads")
|
||||||
#wrapper.wat-cf
|
#wrapper.wat-cf
|
||||||
= render :partial => "layouts/flashes"
|
= render :partial => "layouts/flashes"
|
||||||
#main
|
#main
|
||||||
= yield
|
= yield
|
||||||
#footer
|
#footer
|
||||||
.block
|
.block
|
||||||
|
|
||||||
#sidebar
|
#sidebar
|
||||||
= yield :sidebar
|
= yield :sidebar
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,9 @@ ru:
|
||||||
false_: Нет
|
false_: Нет
|
||||||
publish: Опубликовать
|
publish: Опубликовать
|
||||||
|
|
||||||
|
downloads:
|
||||||
|
title: Статистика закачек пакетов
|
||||||
|
|
||||||
weekdays:
|
weekdays:
|
||||||
Monday: Понедельник
|
Monday: Понедельник
|
||||||
Tuesday: Вторник
|
Tuesday: Вторник
|
||||||
|
@ -33,6 +36,7 @@ ru:
|
||||||
menu:
|
menu:
|
||||||
users: Пользователи
|
users: Пользователи
|
||||||
platforms: Платформы
|
platforms: Платформы
|
||||||
|
downloads: Статистика
|
||||||
|
|
||||||
sessions:
|
sessions:
|
||||||
sign_in_header: Вход в систему
|
sign_in_header: Вход в систему
|
||||||
|
@ -145,7 +149,7 @@ ru:
|
||||||
no_items_data: Данных нет
|
no_items_data: Данных нет
|
||||||
show: Просмотр
|
show: Просмотр
|
||||||
confirm_publish: Вы уверены, что хотите опубликовать контейнер?
|
confirm_publish: Вы уверены, что хотите опубликовать контейнер?
|
||||||
|
|
||||||
items:
|
items:
|
||||||
statuses:
|
statuses:
|
||||||
build_error: ошибка сборки
|
build_error: ошибка сборки
|
||||||
|
@ -228,6 +232,7 @@ ru:
|
||||||
product: Продукт
|
product: Продукт
|
||||||
build_list: Сборочный лист
|
build_list: Сборочный лист
|
||||||
build_list_item: Элемент сборочного листа
|
build_list_item: Элемент сборочного листа
|
||||||
|
download: Статистика
|
||||||
|
|
||||||
attributes:
|
attributes:
|
||||||
repository:
|
repository:
|
||||||
|
@ -244,7 +249,7 @@ ru:
|
||||||
build_status: Статус последней сборки
|
build_status: Статус последней сборки
|
||||||
build_path: Путь к iso
|
build_path: Путь к iso
|
||||||
created_at: Создан
|
created_at: Создан
|
||||||
updated_at: Обновлен
|
updated_at: Обновлен
|
||||||
ks: Содержимое .ks.template
|
ks: Содержимое .ks.template
|
||||||
counter: Содержимое .counter
|
counter: Содержимое .counter
|
||||||
build: Содержимое build
|
build: Содержимое build
|
||||||
|
@ -322,3 +327,9 @@ ru:
|
||||||
level: Уровень
|
level: Уровень
|
||||||
status: Статус
|
status: Статус
|
||||||
build_list: Сборочный лист
|
build_list: Сборочный лист
|
||||||
|
download:
|
||||||
|
name: Название
|
||||||
|
version: Версия
|
||||||
|
distro: Дистрибутив
|
||||||
|
platform: Архитектура
|
||||||
|
counter: Закачки
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
Rosa::Application.routes.draw do
|
Rosa::Application.routes.draw do
|
||||||
devise_for :users
|
devise_for :users
|
||||||
|
|
||||||
|
resources :downloads, :only => :index
|
||||||
|
|
||||||
resources :platforms do
|
resources :platforms do
|
||||||
member do
|
member do
|
||||||
get 'freeze'
|
get 'freeze'
|
||||||
|
@ -25,7 +27,7 @@ Rosa::Application.routes.draw do
|
||||||
end
|
end
|
||||||
member do
|
member do
|
||||||
post :publish
|
post :publish
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
member do
|
member do
|
||||||
|
@ -38,7 +40,7 @@ Rosa::Application.routes.draw do
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :users
|
resources :users
|
||||||
|
|
||||||
match 'build_lists/status_build', :to => "build_lists#status_build"
|
match 'build_lists/status_build', :to => "build_lists#status_build"
|
||||||
match 'build_lists/post_build', :to => "build_lists#post_build"
|
match 'build_lists/post_build', :to => "build_lists#post_build"
|
||||||
match 'build_lists/pre_build', :to => "build_lists#pre_build"
|
match 'build_lists/pre_build', :to => "build_lists#pre_build"
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
every 1.day, :at => '0:05 am' do
|
||||||
|
runner "Download.rotate_nginx_log"
|
||||||
|
end
|
||||||
|
|
||||||
|
every 1.day, :at => '0:10 am' do
|
||||||
|
runner "Download.parse_and_remove_nginx_log"
|
||||||
|
end
|
|
@ -0,0 +1,17 @@
|
||||||
|
class CreateDownloads < ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
create_table :downloads do |t|
|
||||||
|
t.string :name, :null => false
|
||||||
|
t.string :version
|
||||||
|
t.string :distro
|
||||||
|
t.string :platform
|
||||||
|
t.integer :counter, :default => 0
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
drop_table :downloads
|
||||||
|
end
|
||||||
|
end
|
12
db/schema.rb
12
db/schema.rb
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20110428140753) do
|
ActiveRecord::Schema.define(:version => 20111012065448) do
|
||||||
|
|
||||||
create_table "arches", :force => true do |t|
|
create_table "arches", :force => true do |t|
|
||||||
t.string "name", :null => false
|
t.string "name", :null => false
|
||||||
|
@ -73,6 +73,16 @@ ActiveRecord::Schema.define(:version => 20110428140753) do
|
||||||
|
|
||||||
add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority"
|
add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority"
|
||||||
|
|
||||||
|
create_table "downloads", :force => true do |t|
|
||||||
|
t.string "name", :null => false
|
||||||
|
t.string "version"
|
||||||
|
t.string "distro"
|
||||||
|
t.string "platform"
|
||||||
|
t.integer "counter", :default => 0
|
||||||
|
t.datetime "created_at"
|
||||||
|
t.datetime "updated_at"
|
||||||
|
end
|
||||||
|
|
||||||
create_table "platforms", :force => true do |t|
|
create_table "platforms", :force => true do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.string "unixname"
|
t.string "unixname"
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe DownloadController do
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,15 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
# Specs in this file have access to a helper object that includes
|
||||||
|
# the DownloadHelper. For example:
|
||||||
|
#
|
||||||
|
# describe DownloadHelper do
|
||||||
|
# describe "string concat" do
|
||||||
|
# it "concats two strings with spaces" do
|
||||||
|
# helper.concat_strings("this","that").should == "this that"
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
describe DownloadHelper do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Download do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
Loading…
Reference in New Issue