Merge branch 'downloads'

First turn of merging.

Conflicts:
	.gitignore
	Gemfile
	Gemfile.lock
	config/locales/ru.yml
	config/routes.rb
	db/schema.rb
This commit is contained in:
George Vinogradov 2011-10-20 19:22:11 +04:00
commit 2dd99d32f9
16 changed files with 160 additions and 5 deletions

1
.gitignore vendored
View File

@ -12,3 +12,4 @@ public/assets/*
config/initializers/local.rb
public/system/*
.rvmrc
*.swp

View File

@ -54,6 +54,9 @@ end
group :development, :test do
gem 'mysql2', '<= 0.2.9'
end
gem "capistrano"
gem "capistrano-ext"
gem 'whenever', :require => false
group :test do
gem 'rspec-rails', '~> 2.6.1'

View File

@ -47,6 +47,7 @@ GEM
capistrano-ext (1.2.1)
capistrano (>= 1.0.0)
capistrano_colors (0.5.5)
chronic (0.6.4)
chunky_png (1.2.5)
cocaine (0.2.0)
columnize (0.3.4)
@ -58,7 +59,7 @@ GEM
delayed_job (2.1.4)
activesupport (~> 3.0)
daemons
devise (1.4.8)
devise (1.4.9)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.0.3)
warden (~> 1.0.3)
@ -237,6 +238,9 @@ GEM
warden (1.0.6)
rack (>= 1.0)
web-app-theme (0.7.0)
whenever (0.7.0)
activesupport (>= 2.3.4)
chronic (~> 0.6.3)
will_paginate (3.0.2)
yui-compressor (0.9.5)
@ -271,5 +275,6 @@ DEPENDENCIES
silent-postgres (~> 0.1.1)
unicorn
web-app-theme
whenever
will_paginate (~> 3.0.2)
yui-compressor (= 0.9.5)

View File

@ -0,0 +1,5 @@
class DownloadsController < ApplicationController
def index
@downloads = Download.paginate :page => params[:page], :per_page => 30
end
end

View File

@ -0,0 +1,2 @@
module DownloadHelper
end

38
app/models/download.rb Normal file
View File

@ -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

View File

@ -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

View File

@ -22,6 +22,8 @@
%a{:href => groups_path}= t("layout.menu.groups")
%li{:class => controller.controller_path == 'platforms' ? 'active' : '' }
%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
= render :partial => "layouts/flashes"
#main

View File

@ -22,6 +22,9 @@ ru:
publish: Опубликовать
add: Добавить
downloads:
title: Статистика закачек пакетов
weekdays:
Monday: Понедельник
Tuesday: Вторник
@ -35,6 +38,7 @@ ru:
users: Пользователи
platforms: Платформы
groups: Группы
downloads: Статистика
sessions:
sign_in_header: Вход в систему
@ -258,6 +262,7 @@ ru:
product: Продукт
build_list: Сборочный лист
build_list_item: Элемент сборочного листа
download: Статистика
attributes:
repository:
@ -366,3 +371,9 @@ ru:
level: Уровень
status: Статус
build_list: Сборочный лист
download:
name: Название
version: Версия
distro: Дистрибутив
platform: Архитектура
counter: Закачки

View File

@ -4,6 +4,7 @@ Rosa::Application.routes.draw do
end
resources :users
resources :downloads, :only => :index
# resources :platforms do
# member do
# get 'freeze'

7
config/schedule.rb Normal file
View File

@ -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

View File

@ -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

View File

@ -84,6 +84,16 @@ ActiveRecord::Schema.define(:version => 20111018102655) do
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 "groups", :force => true do |t|
t.string "name"
t.integer "owner_id"
@ -207,9 +217,9 @@ ActiveRecord::Schema.define(:version => 20111018102655) do
t.datetime "remember_created_at"
t.datetime "created_at"
t.datetime "updated_at"
t.string "uname"
t.string "nickname"
t.text "ssh_key"
t.string "uname"
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe DownloadController do
end

View File

@ -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

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe Download do
pending "add some examples to (or delete) #{__FILE__}"
end