[70311] branches/gsoc10-mpwa

jrozner at macports.org jrozner at macports.org
Thu Aug 5 15:57:42 PDT 2010


Revision: 70311
          http://trac.macports.org/changeset/70311
Author:   jrozner at macports.org
Date:     2010-08-05 15:57:41 -0700 (Thu, 05 Aug 2010)
Log Message:
-----------
Updated syncing script to properly sync and remove the need for category seed data. Also added messages when no categories or ports are in the db

Modified Paths:
--------------
    branches/gsoc10-mpwa/bin/add_ports
    branches/gsoc10-mpwa/mpwa/app/controllers/application_controller.rb
    branches/gsoc10-mpwa/mpwa/app/controllers/categories_controller.rb
    branches/gsoc10-mpwa/mpwa/app/controllers/ports_controller.rb
    branches/gsoc10-mpwa/mpwa/app/views/categories/index.html.erb
    branches/gsoc10-mpwa/mpwa/app/views/partials/_port_search.html.erb
    branches/gsoc10-mpwa/mpwa/app/views/ports/index.html.erb
    branches/gsoc10-mpwa/mpwa/db/seeds.rb
    branches/gsoc10-mpwa/mpwa/test/fixtures/categories.yml
    branches/gsoc10-mpwa/mpwa/test/fixtures/comments.yml
    branches/gsoc10-mpwa/mpwa/test/fixtures/port_dependencies.yml
    branches/gsoc10-mpwa/mpwa/test/fixtures/ports.yml
    branches/gsoc10-mpwa/mpwa/test/fixtures/tickets.yml

Modified: branches/gsoc10-mpwa/bin/add_ports
===================================================================
--- branches/gsoc10-mpwa/bin/add_ports	2010-08-05 22:47:40 UTC (rev 70310)
+++ branches/gsoc10-mpwa/bin/add_ports	2010-08-05 22:57:41 UTC (rev 70311)
@@ -3,9 +3,10 @@
 require 'trac4r'
 
 TIME_FILE = "/var/tmp/mpwa-sync"
-NEW_PORTS = "/Users/joe/Dev/gsoc10-mpwa/bin/new-ports"
+ROOT = File.expand_path(File.dirname(__FILE__) + "/../") 
+NEW_PORTS = "#{ROOT}/bin/new_ports"
 PORT_INDEX = "/opt/local/var/macports/sources/rsync.macports.org/release/ports"
-RAILS_ROOT = "/Users/joe/Dev/gsoc10-mpwa/mpwa"
+RAILS_ROOT = "#{ROOT}/mpwa"
 OPEN_STATUSES = ['new', 'reopened', 'assigned']
 TRAC_URL = "http://192.168.1.135/svn-helloworld/xmlrpc"
 TRAC_USER = "admin"
@@ -22,6 +23,8 @@
   $mtime = 0
 end
 
+FileUtils.touch(TIME_FILE)
+
 $ports = Array.new
 $hashed_data = Hash.new
 
@@ -31,8 +34,11 @@
 
 fp = IO.popen("#{NEW_PORTS} -m #{$mtime} #{PORT_INDEX}")
 new_ports = fp.read.split("\n")
-new_ports << ""
 
+if new_ports.count > 0
+  new_ports << "" #add last blank line
+end
+
 new_ports.each do |line|
   unless (line == "")
     data = line.match(/(\S+):\s+\{?(.+)\}?$/)
@@ -40,18 +46,29 @@
       $hashed_data[data[1].to_sym] = data[2]
     end
   else
-    port = Port.new({
-      :name => $hashed_data[:name],
-      :path => $hashed_data[:portdir],
-      :version => $hashed_data[:version],
-      :description => $hashed_data[:description],
-      :licenses => $hashed_data[:license],
-      :category_id => Category.find_by_name($hashed_data[:categories].split(" ")[0]).id,
-      :variants => $hashed_data[:variants],
-      :maintainers => $hashed_data[:maintainers],
-      :platforms => $hashed_data[:platforms],
-      :categories => $hashed_data[:categories]
-    })
+    category_name = $hashed_data[:categories].try(:split, " ").try(:[], 0)
+    $category = Category.find_by_name(category_name)
+    if $category.nil?
+      $category = Category.new({:name => category_name})
+      $category.save
+    end
+
+    port = Port.find_by_name($hashed_data[:name])
+    if port.nil?
+      port = Port.new
+    end
+
+    port[:name] = $hashed_data[:name]
+    port[:path] = $hashed_data[:portdir]
+    port[:version] = $hashed_data[:version]
+    port[:description] = $hashed_data[:description]
+    port[:licenses] = $hashed_data[:license]
+    port[:category_id] = $category.id
+    port[:variants] = $hashed_data[:variants]
+    port[:maintainers] = $hashed_data[:maintainers]
+    port[:platforms] = $hashed_data[:platforms]
+    port[:categories] = $hashed_data[:categories]
+
     $ports << [$hashed_data, port]
     port.save
     $hashed_data = {}

Modified: branches/gsoc10-mpwa/mpwa/app/controllers/application_controller.rb
===================================================================
--- branches/gsoc10-mpwa/mpwa/app/controllers/application_controller.rb	2010-08-05 22:47:40 UTC (rev 70310)
+++ branches/gsoc10-mpwa/mpwa/app/controllers/application_controller.rb	2010-08-05 22:57:41 UTC (rev 70311)
@@ -20,4 +20,6 @@
   $bz2_tarball = "#{$downloads_url}MacPorts-#{$latest_version}.tar.bz2"
   $gz_tarball = "#{$downloads_url}MacPorts-#{$latest_version}.tar.gz"
   $checksums = "#{$downloads_url}MacPorts-#{$latest_version}.chk.txt"
+
+  $updated = Port.all(:order => 'updated_at DESC', :limit => 1).try(:first).try(:updated_at) || Time.at(0)
 end

Modified: branches/gsoc10-mpwa/mpwa/app/controllers/categories_controller.rb
===================================================================
--- branches/gsoc10-mpwa/mpwa/app/controllers/categories_controller.rb	2010-08-05 22:47:40 UTC (rev 70310)
+++ branches/gsoc10-mpwa/mpwa/app/controllers/categories_controller.rb	2010-08-05 22:57:41 UTC (rev 70311)
@@ -1,6 +1,5 @@
 class CategoriesController < ApplicationController
   def index
     @categories = Category.all(:order => 'name ASC')
-    @updated = Port.all(:order => 'updated_at DESC', :limit => 1).first.updated_at
   end
 end

Modified: branches/gsoc10-mpwa/mpwa/app/controllers/ports_controller.rb
===================================================================
--- branches/gsoc10-mpwa/mpwa/app/controllers/ports_controller.rb	2010-08-05 22:47:40 UTC (rev 70310)
+++ branches/gsoc10-mpwa/mpwa/app/controllers/ports_controller.rb	2010-08-05 22:57:41 UTC (rev 70311)
@@ -5,7 +5,6 @@
     else
       @ports = Port.paginate :page => params[:page], :order => 'name ASC', :per_page => 50
     end
-    @updated = Port.all(:order => 'updated_at DESC', :limit => 1).first.updated_at
     @page = params[:page] || 1
 
     respond_to do |format|
@@ -24,7 +23,6 @@
 
   def search
     @ports = Port.search(params[:criteria], params[:val], params[:page])
-    @updated = Port.all(:order => 'updated_at DESC', :limit => 1).first.updated_at
     @page = params[:page] || 1
 
     respond_to do |format|

Modified: branches/gsoc10-mpwa/mpwa/app/views/categories/index.html.erb
===================================================================
--- branches/gsoc10-mpwa/mpwa/app/views/categories/index.html.erb	2010-08-05 22:47:40 UTC (rev 70310)
+++ branches/gsoc10-mpwa/mpwa/app/views/categories/index.html.erb	2010-08-05 22:57:41 UTC (rev 70311)
@@ -3,11 +3,17 @@
   <%= render :partial => '/partials/port_search' %>
 
   <h3>Port Categories</h3>
+
   <div id="categories">
+
+  <% unless @categories.empty? %>
     <ul>
       <% @categories.each do |category| %>
         <li><%= link_to category.name, category_ports_path(category.id) %></li>
       <% end %>
     </ul>
+  <% else %>
+    <p>No Categories found.</p>
+  <% end %>
   </div>
 </div>
\ No newline at end of file

Modified: branches/gsoc10-mpwa/mpwa/app/views/partials/_port_search.html.erb
===================================================================
--- branches/gsoc10-mpwa/mpwa/app/views/partials/_port_search.html.erb	2010-08-05 22:47:40 UTC (rev 70310)
+++ branches/gsoc10-mpwa/mpwa/app/views/partials/_port_search.html.erb	2010-08-05 22:57:41 UTC (rev 70311)
@@ -1,6 +1,6 @@
 <h2 class="hdr">MacPorts Portfiles</h2> 
 
-<p>The MacPorts Project currently distributes <b><%= Port.count %></b> ports, organized across 92 different categories and available below for viewing. This form allows you to search the MacPorts software index, last updated on <b><%= @updated.strftime("%Y-%m-%d") %></b> at <b><%= @updated.strftime("%H:%M:%S %Z") %></b>.</p> 
+<p>The MacPorts Project currently distributes <b><%= Port.count %></b> ports, organized across 92 different categories and available below for viewing. This form allows you to search the MacPorts software index, last updated on <b><%= $updated.strftime("%Y-%m-%d") %></b> at <b><%= $updated.strftime("%H:%M:%S %Z") %></b>.</p> 
 
 <br />
 

Modified: branches/gsoc10-mpwa/mpwa/app/views/ports/index.html.erb
===================================================================
--- branches/gsoc10-mpwa/mpwa/app/views/ports/index.html.erb	2010-08-05 22:47:40 UTC (rev 70310)
+++ branches/gsoc10-mpwa/mpwa/app/views/ports/index.html.erb	2010-08-05 22:57:41 UTC (rev 70311)
@@ -3,6 +3,7 @@
 
   <h3>Query Results</h3>
 
+<% unless @ports.empty? %>
   <p>
     <%= ((@page.to_i - 1) * 50) + 1 %> - <%= @page.to_i * 50 %> of <%= Port.count %> Portfiles Selected
   </p>
@@ -44,6 +45,9 @@
       </dd>
     </dl>
   <% end %>
+<% else %>
+  <p>No ports found.</p>
+<% end %>
 
   <p>
     <%= will_paginate @ports %>

Modified: branches/gsoc10-mpwa/mpwa/db/seeds.rb
===================================================================
--- branches/gsoc10-mpwa/mpwa/db/seeds.rb	2010-08-05 22:47:40 UTC (rev 70310)
+++ branches/gsoc10-mpwa/mpwa/db/seeds.rb	2010-08-05 22:57:41 UTC (rev 70311)
@@ -5,6 +5,3 @@
 #   
 #   cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
 #   Major.create(:name => 'Daley', :city => cities.first)
-require 'active_record/fixtures'
-
-Fixtures.create_fixtures("#{Rails.root}/test/fixtures", "categories")
\ No newline at end of file

Modified: branches/gsoc10-mpwa/mpwa/test/fixtures/categories.yml
===================================================================
--- branches/gsoc10-mpwa/mpwa/test/fixtures/categories.yml	2010-08-05 22:47:40 UTC (rev 70310)
+++ branches/gsoc10-mpwa/mpwa/test/fixtures/categories.yml	2010-08-05 22:57:41 UTC (rev 70311)
@@ -1,184 +0,0 @@
-0:
-  id: 0
-  name: aqua
-
-1:
-  id: 1
-  name: archivers
-
-2:
-  id: 2
-  name: audio
-
-3:
-  id: 3
-  name: benchmarks
-
-4:
-  id: 4
-  name: cad
-
-5:
-  id: 5
-  name: comms
-
-6:
-  id: 6
-  name: cross
-
-7:
-  id: 7
-  name: databases
-
-8:
-  id: 8
-  name: devel
-
-9:
-  id: 9
-  name: editors
-
-10:
-  id: 10
-  name: emulators
-
-11:
-  id: 11
-  name: erlang
-
-12:
-  id: 12
-  name: finance
-
-13:
-  id: 13
-  name: fuse
-
-14:
-  id: 14
-  name: games
-
-15:
-  id: 15
-  name: genealogy
-
-16:
-  id: 16
-  name: gis
-
-17:
-  id: 17
-  name: gnome
-
-18:
-  id: 18
-  name: gnustep
-
-19:
-  id: 19
-  name: graphics
-
-20:
-  id: 20
-  name: irc
-
-21:
-  id: 21
-  name: java
-
-22:
-  id: 22
-  name: kde
-
-23:
-  id: 23
-  name: lang
-
-24:
-  id: 24
-  name: mail
-
-25:
-  id: 25
-  name: math
-
-26:
-  id: 26
-  name: multimedia
-
-27:
-  id: 27
-  name: net
-
-28:
-  id: 28
-  name: news
-
-29:
-  id: 29
-  name: office
-
-30:
-  id: 30
-  name: palm
-
-31:
-  id: 31
-  name: perl
-
-32:
-  id: 32
-  name: php
-
-33:
-  id: 33
-  name: print
-
-34:
-  id: 34
-  name: python
-
-35:
-  id: 35
-  name: ruby
-
-36:
-  id: 36
-  name: science
-
-37:
-  id: 37
-  name: security
-
-38:
-  id: 38
-  name: shells
-
-39:
-  id: 39
-  name: sysutils
-
-40:
-  id: 40
-  name: tex
-
-41:
-  id: 41
-  name: textproc
-
-42:
-  id: 42
-  name: www
-
-43:
-  id: 43
-  name: x11
-
-44:
-  id: 44
-  name: xfce
-
-45:
-  id: 45
-  name: zope
-

Modified: branches/gsoc10-mpwa/mpwa/test/fixtures/comments.yml
===================================================================
--- branches/gsoc10-mpwa/mpwa/test/fixtures/comments.yml	2010-08-05 22:47:40 UTC (rev 70310)
+++ branches/gsoc10-mpwa/mpwa/test/fixtures/comments.yml	2010-08-05 22:57:41 UTC (rev 70311)
@@ -1,9 +0,0 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-
-one:
-  port_id: 1
-  body: MyText
-
-two:
-  port_id: 1
-  body: MyText

Modified: branches/gsoc10-mpwa/mpwa/test/fixtures/port_dependencies.yml
===================================================================
--- branches/gsoc10-mpwa/mpwa/test/fixtures/port_dependencies.yml	2010-08-05 22:47:40 UTC (rev 70310)
+++ branches/gsoc10-mpwa/mpwa/test/fixtures/port_dependencies.yml	2010-08-05 22:57:41 UTC (rev 70311)
@@ -1,9 +0,0 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-
-one:
-  port_id: 1
-  dependency_id: 1
-
-two:
-  port_id: 1
-  dependency_id: 1

Modified: branches/gsoc10-mpwa/mpwa/test/fixtures/ports.yml
===================================================================
--- branches/gsoc10-mpwa/mpwa/test/fixtures/ports.yml	2010-08-05 22:47:40 UTC (rev 70310)
+++ branches/gsoc10-mpwa/mpwa/test/fixtures/ports.yml	2010-08-05 22:57:41 UTC (rev 70311)
@@ -1,19 +0,0 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-
-one:
-  name: MyString
-  path: MyString
-  version: MyString
-  description: MyText
-  licenses: MyString
-  categories: MyString
-  variants: MyString
-
-two:
-  name: MyString
-  path: MyString
-  version: MyString
-  description: MyText
-  licenses: MyString
-  categories: MyString
-  variants: MyString

Modified: branches/gsoc10-mpwa/mpwa/test/fixtures/tickets.yml
===================================================================
--- branches/gsoc10-mpwa/mpwa/test/fixtures/tickets.yml	2010-08-05 22:47:40 UTC (rev 70310)
+++ branches/gsoc10-mpwa/mpwa/test/fixtures/tickets.yml	2010-08-05 22:57:41 UTC (rev 70311)
@@ -1,9 +0,0 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-
-one:
-  port_id: 1
-  ticket: 1
-
-two:
-  port_id: 1
-  ticket: 1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20100805/f1008862/attachment.html>


More information about the macports-changes mailing list