[69353] branches/gsoc10-mpwa

jrozner at macports.org jrozner at macports.org
Thu Jul 1 23:00:12 PDT 2010


Revision: 69353
          http://trac.macports.org/changeset/69353
Author:   jrozner at macports.org
Date:     2010-07-01 23:00:11 -0700 (Thu, 01 Jul 2010)
Log Message:
-----------
#!/usr/bin/env ruby
require 'active_record'

TIME_FILE = "/var/tmp/mpwa-sync"
NEW_PORTS = "/Users/joe/Dev/gsoc10-mpwa/bin/new-ports"
PORT_INDEX = "/opt/local/var/macports/sources/rsync.macports.org/release/ports"
RAILS_ROOT = "/Users/joe/Dev/gsoc10-mpwa/mpwa"

require File.expand_path(RAILS_ROOT + '/app/models/category.rb',  __FILE__)
require File.expand_path(RAILS_ROOT + '/app/models/port.rb',  __FILE__)
require File.expand_path(RAILS_ROOT + '/app/models/port_dependency.rb',  __FILE__)
require File.expand_path(RAILS_ROOT + '/app/models/supplemental_category.rb',  __FILE__)

if File.exists?(TIME_FILE)
  $mtime = File.stat(TIME_FILE).mtime.to_i
else
  $mtime = 0
end

$ports = Array.new
$hashed_data = Hash.new

db_info = YAML.load_file(File.expand_path(RAILS_ROOT + '/config/database.yml',  __FILE__))
ActiveRecord::Base.establish_connection(db_info['development'])

fp = IO.popen("#{NEW_PORTS} -m #{$mtime} #{PORT_INDEX}")
new_ports = fp.read.split("\n")

new_ports.each do |line|
  unless (line == "")
    data = line.match(/(\S+):\s+\{?(.+)\}?$/)
    unless data.nil? #field missing, should record this if it happens
      $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]
    })
    $ports << [$hashed_data, port]
    port.save
    $hashed_data = {}
  end
end

$ports.each do |port|
  categories = port[0][:categories].split(" ")
  unless (categories.count < 2)
    categories[1..-1].each do |category|
      port[1].supplemental_categories.build({:name => category}).save!
    end
  end

  dependencies = Array.new
  unless port[0][:depends_lib].nil?
    dependencies << port[0][:depends_lib].split(" ")
  end

  unless port[0][:depends_run].nil?
    dependencies << port[0][:depends_run].split(" ")
  end

  unless port[0][:depends_build].nil?
    dependencies << port[0][:depends_build].split(" ")
  end

  dependencies.flatten.uniq.each do |dependency|
    name = dependency.match(/.+:(.+)/)[1]
    dep = Port.find_by_name(name)
    unless dep.nil? #should provide the info that the port doesn't exist eventually
      port[1].port_dependencies.build({:dependency_id => dep.id}).save!
    end
  end
end

Modified Paths:
--------------
    branches/gsoc10-mpwa/bin/add_ports
    branches/gsoc10-mpwa/mpwa/app/controllers/ports_controller.rb
    branches/gsoc10-mpwa/mpwa/app/views/pages/index.html.erb
    branches/gsoc10-mpwa/mpwa/app/views/partials/_nav.html.erb
    branches/gsoc10-mpwa/mpwa/app/views/ports/index.html.erb
    branches/gsoc10-mpwa/mpwa/app/views/ports/show.html.erb
    branches/gsoc10-mpwa/mpwa/config/environment.rb
    branches/gsoc10-mpwa/mpwa/config/routes.rb

Modified: branches/gsoc10-mpwa/bin/add_ports
===================================================================
--- branches/gsoc10-mpwa/bin/add_ports	2010-07-02 05:57:37 UTC (rev 69352)
+++ branches/gsoc10-mpwa/bin/add_ports	2010-07-02 06:00:11 UTC (rev 69353)
@@ -2,23 +2,28 @@
 require 'active_record'
 
 TIME_FILE = "/var/tmp/mpwa-sync"
-NEW_PORTS = "/Users/joe/Dev/macports/new-ports"
+NEW_PORTS = "/Users/joe/Dev/gsoc10-mpwa/bin/new-ports"
 PORT_INDEX = "/opt/local/var/macports/sources/rsync.macports.org/release/ports"
-RAILS_ROOT = "/Users/joe/Dev/mpwa"
+RAILS_ROOT = "/Users/joe/Dev/gsoc10-mpwa/mpwa"
 
 require File.expand_path(RAILS_ROOT + '/app/models/category.rb',  __FILE__)
 require File.expand_path(RAILS_ROOT + '/app/models/port.rb',  __FILE__)
 require File.expand_path(RAILS_ROOT + '/app/models/port_dependency.rb',  __FILE__)
 require File.expand_path(RAILS_ROOT + '/app/models/supplemental_category.rb',  __FILE__)
 
-$mtime = File.stat(TIME_FILE).mtime.to_i
+if File.exists?(TIME_FILE)
+  $mtime = File.stat(TIME_FILE).mtime.to_i
+else
+  $mtime = 0
+end
+
 $ports = Array.new
 $hashed_data = Hash.new
 
 db_info = YAML.load_file(File.expand_path(RAILS_ROOT + '/config/database.yml',  __FILE__))
 ActiveRecord::Base.establish_connection(db_info['development'])
 
-fp = IO.popen("#{NEW_PORTS} #{PORT_INDEX}")
+fp = IO.popen("#{NEW_PORTS} -m #{$mtime} #{PORT_INDEX}")
 new_ports = fp.read.split("\n")
 
 new_ports.each do |line|
@@ -36,7 +41,8 @@
       :licenses => $hashed_data[:license],
       :category_id => Category.find_by_name($hashed_data[:categories].split(" ")[0]).id,
       :variants => $hashed_data[:variants],
-      :maintainers => $hashed_data[:maintainers]
+      :maintainers => $hashed_data[:maintainers],
+      :platforms => $hashed_data[:platforms]
     })
     $ports << [$hashed_data, port]
     port.save

Modified: branches/gsoc10-mpwa/mpwa/app/controllers/ports_controller.rb
===================================================================
--- branches/gsoc10-mpwa/mpwa/app/controllers/ports_controller.rb	2010-07-02 05:57:37 UTC (rev 69352)
+++ branches/gsoc10-mpwa/mpwa/app/controllers/ports_controller.rb	2010-07-02 06:00:11 UTC (rev 69353)
@@ -1,84 +1,19 @@
 class PortsController < ApplicationController
-  # GET /ports
-  # GET /ports.xml
   def index
-    @ports = Port.all
+    @ports = Port.paginate :page => params[:page], :order => 'name ASC', :per_page => 50
+    @updated = Port.all(:order => 'updated_at DESC', :limit => 1).first.updated_at
 
     respond_to do |format|
-      format.html # index.html.erb
-      format.xml  { render :xml => @ports }
+      format.html
     end
   end
 
-  # GET /ports/1
-  # GET /ports/1.xml
   def show
     @port = Port.find(params[:id])
     @comment = @port.comments.build
 
     respond_to do |format|
-      format.html # show.html.erb
-      format.xml  { render :xml => @port }
+      format.html
     end
   end
-
-  # GET /ports/new
-  # GET /ports/new.xml
-  def new
-    @port = Port.new
-
-    respond_to do |format|
-      format.html # new.html.erb
-      format.xml  { render :xml => @port }
-    end
-  end
-
-  # GET /ports/1/edit
-  def edit
-    @port = Port.find(params[:id])
-  end
-
-  # POST /ports
-  # POST /ports.xml
-  def create
-    @port = Port.new(params[:port])
-
-    respond_to do |format|
-      if @port.save
-        format.html { redirect_to(@port, :notice => 'Port was successfully created.') }
-        format.xml  { render :xml => @port, :status => :created, :location => @port }
-      else
-        format.html { render :action => "new" }
-        format.xml  { render :xml => @port.errors, :status => :unprocessable_entity }
-      end
-    end
-  end
-
-  # PUT /ports/1
-  # PUT /ports/1.xml
-  def update
-    @port = Port.find(params[:id])
-
-    respond_to do |format|
-      if @port.update_attributes(params[:port])
-        format.html { redirect_to(@port, :notice => 'Port was successfully updated.') }
-        format.xml  { head :ok }
-      else
-        format.html { render :action => "edit" }
-        format.xml  { render :xml => @port.errors, :status => :unprocessable_entity }
-      end
-    end
-  end
-
-  # DELETE /ports/1
-  # DELETE /ports/1.xml
-  def destroy
-    @port = Port.find(params[:id])
-    @port.destroy
-
-    respond_to do |format|
-      format.html { redirect_to(ports_url) }
-      format.xml  { head :ok }
-    end
-  end
 end

Modified: branches/gsoc10-mpwa/mpwa/app/views/pages/index.html.erb
===================================================================
--- branches/gsoc10-mpwa/mpwa/app/views/pages/index.html.erb	2010-07-02 05:57:37 UTC (rev 69352)
+++ branches/gsoc10-mpwa/mpwa/app/views/pages/index.html.erb	2010-07-02 06:00:11 UTC (rev 69353)
@@ -4,7 +4,7 @@
 
   <p>The MacPorts Project is an open-source community initiative to design an easy-to-use system for compiling, installing, and upgrading either command-line, X11 or Aqua based open-source software on the <%= link_to 'Mac OS X', 'http://www.apple.com/macosx/' %> operating system. To that end we provide the command-line driven MacPorts software package under a <%= link_to 'BSD License', 'http://opensource.org/licenses/bsd-license.php' %>, and through it easy access to thousands of ports that <%= link_to 'greatly simplify', "#{$guide_url}#introduction" %> the task of <%= link_to 'compiling and installing', "#{$guide_url}#using" %> open-source software on your Mac.</p>
 
-  <p>We provide a single software tree that attempts to track the latest release of every software title (port) we distribute, without splitting them into &#8220;stable&#8221; Vs. &#8220;unstable&#8221; branches, targetting mainly the current Mac OS X release (10.6, A.K.A Snow Leopard) and the immediately previous one (10.5, A.K.A. Leopard). There are currently <%# link_to "<b>#{Port.count} ports</b>" %> in our tree, distributed among <%# Category.count %> different categories, and more are being added on a regular basis.</p>
+  <p>We provide a single software tree that attempts to track the latest release of every software title (port) we distribute, without splitting them into &#8220;stable&#8221; Vs. &#8220;unstable&#8221; branches, targetting mainly the current Mac OS X release (10.6, A.K.A Snow Leopard) and the immediately previous one (10.5, A.K.A. Leopard). There are currently <%= link_to "<b>#{Port.count}</b> ports" %> in our tree, distributed among <%= Category.count %> different categories, and more are being added on a regular basis.</p>
 
   <h3 class="subhdr">Getting started</h3>
 
@@ -19,9 +19,9 @@
   <p>There are many ways you can get involved with MacPorts and peer users, system administrators &amp; developers alike. Browse over to the &#8220;<%= link_to 'Contact Us', contact_path %>&#8221; section of our site and:</p>
 
   <ul>
-    <li>Explore our <%= link_to 'mailing list', "#{contact_path}#Lists" %>, either if it is for some general user support or to keep on top of the latest MacPorts developments and commits to our software repository.</li>
+    <li>Explore our <%= link_to 'mailing lists', "#{contact_path}#Lists" %>, either if it is for some general user support or to keep on top of the latest MacPorts developments and commits to our software repository.</li>
     <li>Check out our <%= link_to 'Support &amp; Development', "#{contact_path}#Tracker" %> portal for some bug reporting and live tutorials through the integrated Wiki server.</li>
-    <li>Or simply come join us for a friendly <%= link_to 'IRC Chat', "#{contact_path}#IRC" %> if you wish for more direct contact with the <%= link_to 'people behind', "#{contact_path}#Individuals" %> it all.</li>
+    <li>Or simply come join us for a friendly <%= link_to 'IRC chat', "#{contact_path}#IRC" %> if you wish for more direct contact with the <%= link_to 'people behind', "#{contact_path}#Individuals" %> it all.</li>
   </ul>
 
   <p>If on the other hand you are interested in joining The MacPorts Project in any way, then don't hesitate to contact the project's management team, &#8220;<%= link_to 'PortMgr', "#{contact_path}#PortMgr" %>&#8221;, to explain your particular interest and present a formal application. We're always looking for more helping hands that can extend and improve our ports tree and documentation, or take MacPorts itself beyond its current limitations and into new areas of the vast software packaging field. We're eager to hear from you!</p>

Modified: branches/gsoc10-mpwa/mpwa/app/views/partials/_nav.html.erb
===================================================================
--- branches/gsoc10-mpwa/mpwa/app/views/partials/_nav.html.erb	2010-07-02 05:57:37 UTC (rev 69352)
+++ branches/gsoc10-mpwa/mpwa/app/views/partials/_nav.html.erb	2010-07-02 06:00:11 UTC (rev 69353)
@@ -5,7 +5,7 @@
       <ul>
         <li><%= link_to 'Home', root_path %></li>
         <li><%= link_to 'Installing MacPorts', install_path %></li>
-        <li><%= link_to 'Available Ports', ports_path %></li>
+        <li><%= link_to 'Available Ports', categories_path %></li>
         <li><%= link_to 'Documentation', $guide_url %></li>
         <li><%= link_to 'Support &amp; Development', $trac_url %></li>
         <li><%= link_to 'Contact Us', contact_path %></li>

Modified: branches/gsoc10-mpwa/mpwa/app/views/ports/index.html.erb
===================================================================
--- branches/gsoc10-mpwa/mpwa/app/views/ports/index.html.erb	2010-07-02 05:57:37 UTC (rev 69352)
+++ branches/gsoc10-mpwa/mpwa/app/views/ports/index.html.erb	2010-07-02 06:00:11 UTC (rev 69353)
@@ -1,32 +1,20 @@
-<h1>Listing ports</h1>
+<div id="content">
+  <%= render :partial => '/partials/port_search' %>
 
-<table>
-  <tr>
-    <th>Name</th>
-    <th>Path</th>
-    <th>Version</th>
-    <th>Description</th>
-    <th>Licenses</th>
-    <th>Categories</th>
-    <th>Variants</th>
-  </tr>
+  <h3>Query Results</h3>
 
-<% @ports.each do |port| %>
-  <tr>
-    <td><%=h port.name %></td>
-    <td><%=h port.path %></td>
-    <td><%=h port.version %></td>
-    <td><%=h port.description %></td>
-    <td><%=h port.licenses %></td>
-    <td><%=h port.categories %></td>
-    <td><%=h port.variants %></td>
-    <td><%= link_to 'Show', port %></td>
-    <td><%= link_to 'Edit', edit_port_path(port) %></td>
-    <td><%= link_to 'Destroy', port, :confirm => 'Are you sure?', :method => :delete %></td>
-  </tr>
-<% end %>
-</table>
+  <%= will_paginate @ports %>
 
-<br />
+  <% @ports.each do |port| %>
+    <dl>
+      <dt><b><%= link_to port.name, category_ports_path(port.category, port) %></b> <%= port.version %></dt>
+      <dd><%= port.description %><br />
+      <i>Maintained by:</i> <b><span class="email"><%= port.maintainers %></span></b><br>
+      <i>Categories:</i> <%= port.category.name %><br />
+      <i>Platforms:</i> <%= port.platforms %><br />
+      <i>Variants:</li> <%= port.variants %></dd>
+    </dl>
+  <% end %>
 
-<%= link_to 'New port', new_port_path %>
\ No newline at end of file
+  <%= will_paginate @ports %>
+</div>
\ No newline at end of file

Modified: branches/gsoc10-mpwa/mpwa/app/views/ports/show.html.erb
===================================================================
--- branches/gsoc10-mpwa/mpwa/app/views/ports/show.html.erb	2010-07-02 05:57:37 UTC (rev 69352)
+++ branches/gsoc10-mpwa/mpwa/app/views/ports/show.html.erb	2010-07-02 06:00:11 UTC (rev 69353)
@@ -12,6 +12,14 @@
   </p>
 
   <p>
+    <strong>Categories</strong>
+    <%=h @port.category.name %>
+    <% @port.supplemental_categories.each do |category| %>
+      <%=h category.name %>
+    <% end %>
+  </p>
+
+  <p>
     <strong>Variants:</strong> <%=h @port.variants %>
   </p>
 
@@ -30,7 +38,7 @@
     <strong>SVN Path:</strong> <%=h @port.path %>
   </p>
 
-  <% form_for([@port, @comment]) do |f| %>
+  <% form_for([@port.category, @port, @comment]) do |f| %>
     <%= f.error_messages %>
 
     <p>
@@ -49,6 +57,5 @@
     <div><%= h comment.body %></div>
   <% end %>
 
-  <%= link_to 'Edit', edit_port_path(@port) %> |
   <%= link_to 'Back', ports_path %>
 </div>
\ No newline at end of file

Modified: branches/gsoc10-mpwa/mpwa/config/environment.rb
===================================================================
--- branches/gsoc10-mpwa/mpwa/config/environment.rb	2010-07-02 05:57:37 UTC (rev 69352)
+++ branches/gsoc10-mpwa/mpwa/config/environment.rb	2010-07-02 06:00:11 UTC (rev 69353)
@@ -7,7 +7,8 @@
 require File.join(File.dirname(__FILE__), 'boot')
 
 Rails::Initializer.run do |config|
-  config.gem "recaptcha", :lib => "recaptcha/rails"
+  config.gem 'recaptcha', :lib => "recaptcha/rails"
+  config.gem 'will_paginate'
 
   config.time_zone = 'UTC'
 end
\ No newline at end of file

Modified: branches/gsoc10-mpwa/mpwa/config/routes.rb
===================================================================
--- branches/gsoc10-mpwa/mpwa/config/routes.rb	2010-07-02 05:57:37 UTC (rev 69352)
+++ branches/gsoc10-mpwa/mpwa/config/routes.rb	2010-07-02 06:00:11 UTC (rev 69353)
@@ -1,8 +1,12 @@
 ActionController::Routing::Routes.draw do |map|
-  map.resources :ports, :except => [:edit, :update] do |port|
-    port.resources :comments, :except => [:index, :show, :new]
+  map.resources :categories, :only => [:index] do |category|
+    category.resources :ports, :only => [:index, :show] do |port|
+      port.resources :comments, :except => [:index, :show, :new]
+    end
   end
 
+  map.resources :ports, :only => [:index]
+
   map.index 'index', :controller => :pages, :action => :show, :page => :index
   map.install 'install', :controller => :pages, :action => :show, :page => :install
   map.contact 'contact', :controller => :pages, :action => :show, :page => :contact
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20100701/c09fcc2d/attachment-0001.html>


More information about the macports-changes mailing list