Skip to content
This repository has been archived by the owner on Nov 19, 2018. It is now read-only.

Commit

Permalink
PerlWatch
Browse files Browse the repository at this point in the history
  • Loading branch information
biow0lf committed Aug 18, 2011
1 parent 15f215e commit f640c5d
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 5 deletions.
3 changes: 3 additions & 0 deletions app/controllers/srpms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ def show
:version => @srpm.version,
:release => @srpm.release,
:epoch => @srpm.epoch).select('DISTINCT arch, weeks').all
if @srpm.name[0..4] == 'perl-' && @srpm.name != 'perl'
@perl_watch = PerlWatch.where(:name => @srpm.name[5..-1]).first
end
@allsrpms = Srpm.where(:name => params[:id]).joins(:branch).order('branches.order_id')
if $redis.exists("#{@branch.name}:#{@srpm.name}:acls")
@acls = Maintainer.where(:login => $redis.zrange("#{@branch.name}:#{@srpm.name}:acls", 0, -1))
Expand Down
19 changes: 19 additions & 0 deletions app/models/perl_watch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class PerlWatch < ActiveRecord::Base
validates :name, :presence => true

def self.import_data(url)
source = open(url)
gz = Zlib::GzipReader.new(source)
result = gz.read
ActiveRecord::Base.transaction do
PerlWatch.delete_all
result.each_with_index do |line, index|
return if index <= 8
name = line.split[0]
version = line.split[1]
path = line.split[2]
PerlWatch.create(:name => name, :version => version, :path => path)
end
end
end
end
20 changes: 20 additions & 0 deletions app/views/srpms/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,28 @@
</tr>
<% end %>

</table>
</div><br/>

<% if @perl_watch %>
<div class="headleft">
<div class="headright" title="<%= _('Other repositories') %>">
<%= _('Other repositories') %>
</div>
<%= image_tag('collapse.gif', :id => 'otherREPO', :class => 'close', :title => _('hide window'), :alt => _('hide window'), :size => '10x9') %>
</div>
<div id="otherREPODiv" style="border: dotted gray 1px;margin: 0px 4px 4px 4px;">
<table style="font-size:8pt;" width="100%">
<tr>
<td style="text-align: left;">
<a class="news" href="http://search.cpan.org/CPAN/authors/id/<%= @perl_watch.path %>" rel='nofollow'><%= _('CPAN:') %></a>
</td>
<td style="text-align: right;"><%= @perl_watch.version %></td>
</tr>
</table>
</div><br />
<% end %>

</div>

<div style="height:3em;">
Expand Down
4 changes: 4 additions & 0 deletions config/schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@
rake "sitemap:refresh"
end

every :sunday, :at => '6:30 am' do
rake "perlwatch:update"
end

# Learn more: http://github.com/javan/whenever
11 changes: 11 additions & 0 deletions db/migrate/20110818200148_create_perl_watches.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreatePerlWatches < ActiveRecord::Migration
def change
create_table :perl_watches do |t|
t.string :name
t.string :version
t.string :path

t.timestamps
end
end
end
19 changes: 14 additions & 5 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
Expand All @@ -10,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20110805170900) do
ActiveRecord::Schema.define(:version => 20110818200148) do

create_table "acls", :force => true do |t|
t.datetime "created_at"
Expand Down Expand Up @@ -207,6 +208,14 @@
add_index "patches", ["branch_id"], :name => "index_patches_on_branch_id"
add_index "patches", ["srpm_id"], :name => "index_patches_on_srpm_id"

create_table "perl_watches", :force => true do |t|
t.string "name"
t.string "version"
t.string "path"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "provides", :force => true do |t|
t.integer "package_id"
t.string "name"
Expand Down Expand Up @@ -313,12 +322,12 @@
add_index "teams", ["maintainer_id"], :name => "index_teams_on_maintainer_id"

create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.string "remember_token"
t.datetime "remember_created_at"
t.integer "sign_in_count", :default => 0
t.integer "sign_in_count", :default => 0
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
Expand Down
10 changes: 10 additions & 0 deletions lib/tasks/perl_watch.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace :perlwatch do
desc 'Import CPAN info to database'
task :update => :environment do
require 'open-uri'
require 'zlib'
puts "#{Time.now.to_s}: import CPAN info to database"
PerlWatch.import_data('http://www.cpan.org/modules/02packages.details.txt.gz')
puts "#{Time.now.to_s}: end"
end
end

0 comments on commit f640c5d

Please sign in to comment.