[38291] branches/gsoc08-mpwa/app

digx at macports.org digx at macports.org
Mon Jul 14 21:43:15 PDT 2008


Revision: 38291
          http://trac.macosforge.org/projects/macports/changeset/38291
Author:   digx at macports.org
Date:     2008-07-14 21:43:14 -0700 (Mon, 14 Jul 2008)
Log Message:
-----------
Rename PortPkg to Package

Modified Paths:
--------------
    branches/gsoc08-mpwa/app/views/packages/show.rhtml

Added Paths:
-----------
    branches/gsoc08-mpwa/app/controllers/packages_controller.rb
    branches/gsoc08-mpwa/app/models/package.rb
    branches/gsoc08-mpwa/app/views/packages/

Removed Paths:
-------------
    branches/gsoc08-mpwa/app/controllers/port_pkg_controller.rb
    branches/gsoc08-mpwa/app/models/port_pkg.rb
    branches/gsoc08-mpwa/app/views/port_pkg/

Copied: branches/gsoc08-mpwa/app/controllers/packages_controller.rb (from rev 38264, branches/gsoc08-mpwa/app/controllers/port_pkg_controller.rb)
===================================================================
--- branches/gsoc08-mpwa/app/controllers/packages_controller.rb	                        (rev 0)
+++ branches/gsoc08-mpwa/app/controllers/packages_controller.rb	2008-07-15 04:43:14 UTC (rev 38291)
@@ -0,0 +1,104 @@
+class PackagesController < ApplicationController
+  def index
+    Package.paginate :page => params[:page], :per_page => 10
+  end
+
+  def show
+    @port_pkg = Package.find(params[:id])
+  end
+
+  def new
+    @port_pkg = Package.new
+  end
+
+  def create
+    @port_pkg = Package.new(params[:port_pkg])
+    if @port_pkg.save
+      flash[:notice] = 'Package was successfully created.'
+      redirect_to :action => 'list'
+    else
+      render :action => 'new'
+    end
+  end
+
+  def edit
+    @port_pkg = Package.find(params[:id])
+  end
+
+  def update
+    @port_pkg = Package.find(params[:id])
+    if @port_pkg.update_attributes(params[:port_pkg])
+      flash[:notice] = 'Package was successfully updated.'
+      redirect_to :action => 'show', :id => @port_pkg
+    else
+      render :action => 'edit'
+    end
+  end
+
+  def destroy
+    Package.find(params[:id]).destroy
+    redirect_to :action => 'list'
+  end
+  
+  def submit
+    portpkg = params[:portpkg]
+
+    begin
+        # Validate parameters (we're probably making this too hard)
+        raise "bad package" if portpkg.nil?
+
+        # Create a package from the file
+        @port_pkg = Package.create_from_file(portpkg)
+        
+        download_url = portpkg_url(:id => @port_pkg)
+        human_url = url_for(:controller => "port_pkg", :action => "show", :id => @port_pkg)
+        render :text => "STATUS: 0\n" +
+            "MESSAGE: Package submitted successfully\n" +
+            "DOWNLOAD_URL: #{download_url}\n" +
+            "HUMAN_URL: #{human_url}\n"
+    rescue FileInfoException => ex
+        render :text => "STATUS: 1\n" +
+            "MESSAGE: Error during submit: #{ex}\n", :status => 400
+    end
+  end
+  
+  def download
+    port_pkg = Package.find(params[:id])
+    redirect_to :controller => 'file_ref', :action => 'emit',
+        :id => port_pkg.portpkg_file_ref()
+  end
+  
+  def download_path
+    port_pkg = Package.find(params[:id])
+    redirect_to :controller => 'file_ref', :action => 'emit',
+        :id => port_pkg.file_ref_by_path(params[:path].join, '/')
+  end
+  
+  def tag
+    port_pkg = Package.find(params[:id])
+    params[:tags].split(/,?[ ]+/).each do |t|
+      if t =~ /\-(.*)/
+        port_pkg.remove_tag($1) if $1
+      elsif t =~ /\+?(.+)/
+        port_pkg.add_tag($1)
+      end
+    end
+    redirect_to :action => 'show', :id => port_pkg
+  end
+  
+  def add_comment
+    port_pkg = Package.find(params[:id])
+    text = params[:text]
+    
+    if text
+      # TODO: Figure out the real maintainer
+      port_pkg.comments << Comment.create(:commenter => port_pkg.submitter, :comment => text)
+    end
+    
+    redirect_to :action => 'show', :id => port_pkg
+  end
+  
+  private :add_comment
+  private :create, :edit, :update, :destroy
+  
+end

Deleted: branches/gsoc08-mpwa/app/controllers/port_pkg_controller.rb
===================================================================
--- branches/gsoc08-mpwa/app/controllers/port_pkg_controller.rb	2008-07-15 04:15:13 UTC (rev 38290)
+++ branches/gsoc08-mpwa/app/controllers/port_pkg_controller.rb	2008-07-15 04:43:14 UTC (rev 38291)
@@ -1,115 +0,0 @@
-require 'port_pkg'
-
-class PortPkgController < ApplicationController
-  def index
-    list
-    render :action => 'list'
-  end
-
-  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
-  verify :method => :post, :only => [ :destroy, :create, :update ],
-         :redirect_to => { :action => :list }
-
-  def list
-    @port_pkg_pages, @port_pkgs = paginate :port_pkgs, :per_page => 10
-  end
-
-  def show
-    @port_pkg = PortPkg.find(params[:id])
-  end
-
-  def new
-    @port_pkg = PortPkg.new
-  end
-
-  def create
-    @port_pkg = PortPkg.new(params[:port_pkg])
-    if @port_pkg.save
-      flash[:notice] = 'PortPkg was successfully created.'
-      redirect_to :action => 'list'
-    else
-      render :action => 'new'
-    end
-  end
-
-  def edit
-    @port_pkg = PortPkg.find(params[:id])
-  end
-
-  def update
-    @port_pkg = PortPkg.find(params[:id])
-    if @port_pkg.update_attributes(params[:port_pkg])
-      flash[:notice] = 'PortPkg was successfully updated.'
-      redirect_to :action => 'show', :id => @port_pkg
-    else
-      render :action => 'edit'
-    end
-  end
-
-  def destroy
-    PortPkg.find(params[:id]).destroy
-    redirect_to :action => 'list'
-  end
-  
-  def submit
-    portpkg = params[:portpkg]
-
-    begin
-        # Validate parameters (we're probably making this too hard)
-        raise "bad package" if portpkg.nil?
-
-        # Create a package from the file
-        @port_pkg = PortPkg.create_from_file(portpkg)
-        
-        download_url = portpkg_url(:id => @port_pkg)
-        human_url = url_for(:controller => "port_pkg", :action => "show", :id => @port_pkg)
-        render :text => "STATUS: 0\n" +
-            "MESSAGE: PortPkg submitted successfully\n" +
-            "DOWNLOAD_URL: #{download_url}\n" +
-            "HUMAN_URL: #{human_url}\n"
-    rescue FileInfoException => ex
-        render :text => "STATUS: 1\n" +
-            "MESSAGE: Error during submit: #{ex}\n", :status => 400
-    end
-  end
-  
-  def emit_portpkg
-    port_pkg = PortPkg.find(params[:id])
-    redirect_to :controller => 'file_ref', :action => 'emit',
-        :id => port_pkg.portpkg_file_ref()
-  end
-  
-  def emit_portpkg_path
-    port_pkg = PortPkg.find(params[:id])
-    redirect_to :controller => 'file_ref', :action => 'emit',
-        :id => port_pkg.file_ref_by_path(params[:path].join, '/')
-  end
-  
-  def tag
-    port_pkg = PortPkg.find(params[:id])
-    params[:tags].split(/,?[ ]+/).each do |t|
-      if t =~ /\-(.*)/
-        port_pkg.remove_tag($1) if $1
-      elsif t =~ /\+?(.+)/
-        port_pkg.add_tag($1)
-      end
-    end
-    redirect_to :action => 'show', :id => port_pkg
-  end
-  
-  def add_comment
-    port_pkg = PortPkg.find(params[:id])
-    text = params[:text]
-    
-    if text
-      # TODO: Figure out the real maintainer
-      port_pkg.comments << Comment.create(:commenter => port_pkg.submitter, :comment => text)
-    end
-    
-    redirect_to :action => 'show', :id => port_pkg
-  end
-  
-  private :add_comment
-  private :create, :edit, :update, :destroy
-  
-end

Copied: branches/gsoc08-mpwa/app/models/package.rb (from rev 38290, branches/gsoc08-mpwa/app/models/port_pkg.rb)
===================================================================
--- branches/gsoc08-mpwa/app/models/package.rb	                        (rev 0)
+++ branches/gsoc08-mpwa/app/models/package.rb	2008-07-15 04:43:14 UTC (rev 38291)
@@ -0,0 +1,183 @@
+require 'time'
+require 'temp_directories'
+require 'rexml/document'
+
+require 'mpwa-conf'
+require 'file_ref'
+require 'file_info'
+require 'person'
+require 'port'
+require 'variant'
+require 'tag'
+
+PortPkgMeta = Struct.new("PortPkgMeta",
+    :submitter_email, :submitter_name, :submitter_notes,
+    :name, :epoch, :version, :revision,
+    :short_desc, :long_desc, :home_page,
+    :maintainers, :variants, :categories)
+    
+VariantMeta = Struct.new("VariantMeta",
+    :name, :description)
+
+class PortPkgException < RuntimeError
+end
+
+class Package < ActiveRecord::Base
+    belongs_to :port
+    belongs_to :submitter, :class_name => 'Person', :foreign_key => 'submitter_id'
+    has_many :file_refs, :dependent => :destroy
+    has_many :file_infos, :through => :file_refs
+    has_many :variants, :dependent => :destroy
+    has_and_belongs_to_many :tags
+    has_and_belongs_to_many :comments
+    
+    def self.create_from_file(file)
+        portpkg = Package.new
+        portpkg.import_from_file(file)
+    end
+    
+    def self.extract_pkg_meta_from_file(f)
+        # This function parses the xml metadata file from a portpkg,
+        # and creates a canonical internal form for our exclusive use
+        
+        meta = PortPkgMeta.new()
+        doc = REXML::Document.new(f)
+        
+        root_el = doc.root
+        submitter_el = root_el.elements["submitter"]
+        package_el = root_el.elements["package"]
+        
+        meta[:submitter_email] = submitter_el.elements["email"].text
+        meta[:submitter_name] = submitter_el.elements["name"].text
+        meta[:submitter_notes] = submitter_el.elements["notes"].text
+        
+        meta[:name] = package_el.elements["name"].text
+        meta[:epoch] = package_el.elements["epoch"].text
+        meta[:version] = package_el.elements["version"].text
+        meta[:revision] = package_el.elements["revision"].text
+        
+        meta[:short_desc] = package_el.elements["description"].text;
+        meta[:long_desc] = package_el.elements["long_description"].text;
+        meta[:home_page] = package_el.elements["homepage"].text;
+            
+        meta[:maintainers] = []
+        package_el.elements.each("maintainers/maintainer") { |m| meta.maintainers << m.text }
+        
+        meta[:variants] = []
+        package_el.elements.each("variants/variant")  do |v|
+          variant = VariantMeta.new()
+          variant[:name] = v.elements["name"].text
+          variant[:description] = v.elements["description"].text if v.elements["description"]
+          meta.variants << variant
+        end
+        
+        meta[:categories] = []
+        package_el.elements.each("categories/category")  { |c| meta.categories << c.text }
+
+        return meta
+    end
+    
+    def import_from_file(file)
+        raise PortPkgException, "nil file_path" if file.nil?
+        
+        # Make a temporary directory
+        tempDirPath = TempDirectories.makeTempDir
+        
+        # Write the portpkg file to the temporary directory
+        pkgPath = tempDirPath + "portpkg.portpkg"
+        metaName = "portpkg_meta.xml"
+        metaPath = tempDirPath + metaName
+ 
+        expandedPkgPath = tempDirPath + "portpkg"
+        File.open(pkgPath, "w") { |f| f.write(file.read) }
+        
+        # Note: a bug in xar presently prevents us from limiting the extraction to the portpkg directory,
+        # => which we'd like to do for the sake of cleanliness. Hopefully this will become fixed soon.
+        raise PortPkgException, "xar tool not executable" if !File.executable?(MPWA::XARTOOL)
+        system("cd #{tempDirPath}; #{MPWA::XARTOOL} -xf #{pkgPath} -s #{metaPath} -n #{metaName}")
+        raise PortPkgException, "error extracting portpkg from xar archive" if $? != 0
+        raise PortPkgException, "no meta information file" if !metaPath.file?
+         
+        # Parse the meta information       
+        meta = nil
+        File.open(metaPath, "r") { |f| meta = Package.extract_pkg_meta_from_file(f) }
+        
+        # Fill-in portpkg information from metadata
+        raise PortPkgException, "no submitter email" if meta.submitter_email.nil? || meta.submitter_email.empty?
+        self.submitted_at = Time.now
+        self.submitter = Person.ensure_person_with_email(meta.submitter_email, meta.submitter_name)
+        self.submitter_notes = meta.submitter_notes
+        
+        self.name = meta.name
+        self.short_desc = meta.short_desc
+        self.long_desc = meta.long_desc
+        self.home_page = meta.home_page
+        
+        self.epoch = meta.epoch
+        self.version = meta.version
+        self.revision = meta.revision
+        
+        # Map to, and/or create, a port
+        self.port = Port.ensure_port(meta.name, meta)
+        
+        # Save before we add variants and tags
+        self.save        
+        
+        # Add the variants
+        meta.variants.each do |v|
+          self.variants << Variant.new(:name => v.name, :description => v.description)
+        end
+        
+        # Tag with categories
+        meta.categories.each { |c| self.add_tag(c) }
+        
+        # Save unpacked data into a file
+        portpkg_ref = FileRef.create_from_path(pkgPath, tempDirPath,
+                            :mimetype => 'application/vnd.macports.portpkg')
+        portpkg_ref.is_port_pkg = true
+        self.file_refs << portpkg_ref
+        
+        # Save files from the expanded package
+        expandedPkgPath.find do |p|
+            self.file_refs << FileRef.create_from_path(p, tempDirPath) if p.file?
+        end
+        
+        # Final save
+        self.save
+        
+        # Cleanup the temp directory
+        tempDirPath.rmtree
+        
+        # Return the port_pkg
+        return self
+     end
+    
+    def file_ref_by_path(file_path)
+        candidates = self.file_refs.select { |r| r.file_info.file_path == file_path }
+        return candidates ? candidates.first : nil
+    end
+    
+    def portpkg_file_ref()
+        candidates = self.file_refs.select { |r| r.is_port_pkg }
+        return candidates ? candidates.first : nil
+    end
+    
+    def data_file_refs()
+        refs = self.file_refs.select { |r| !r.is_port_pkg }
+        return refs
+    end
+    
+    def add_tag(name)
+        tag = Tag.find_or_create_by_name(name)
+        self.tags << tag unless self.tags.include?(tag)
+    end
+    
+    def remove_tag(name)
+        self.tags.select { |t| t.name == name }.each { |t| self.tags.delete(t) }
+    end
+    
+    def <=>(other)
+        self.id <=> other.id
+    end
+
+end
\ No newline at end of file

Deleted: branches/gsoc08-mpwa/app/models/port_pkg.rb
===================================================================
--- branches/gsoc08-mpwa/app/models/port_pkg.rb	2008-07-15 04:15:13 UTC (rev 38290)
+++ branches/gsoc08-mpwa/app/models/port_pkg.rb	2008-07-15 04:43:14 UTC (rev 38291)
@@ -1,183 +0,0 @@
-require 'time'
-require 'temp_directories'
-require 'rexml/document'
-
-require 'mpwa-conf'
-require 'file_ref'
-require 'file_info'
-require 'person'
-require 'port'
-require 'variant'
-require 'tag'
-
-PortPkgMeta = Struct.new("PortPkgMeta",
-    :submitter_email, :submitter_name, :submitter_notes,
-    :name, :epoch, :version, :revision,
-    :short_desc, :long_desc, :home_page,
-    :maintainers, :variants, :categories)
-    
-VariantMeta = Struct.new("VariantMeta",
-    :name, :description)
-
-class PortPkgException < RuntimeError
-end
-
-class PortPkg < ActiveRecord::Base
-    belongs_to :port
-    belongs_to :submitter, :class_name => 'Person', :foreign_key => 'submitter_id'
-    has_many :file_refs, :dependent => :destroy
-    has_many :file_infos, :through => :file_refs
-    has_many :variants, :dependent => :destroy
-    has_and_belongs_to_many :tags
-    has_and_belongs_to_many :comments
-    
-    def PortPkg.create_from_file(file)
-        portpkg = PortPkg.new
-        portpkg.import_from_file(file)
-    end
-    
-    def PortPkg.extract_pkg_meta_from_file(f)
-        # This function parses the xml metadata file from a portpkg,
-        # and creates a canonical internal form for our exclusive use
-        
-        meta = PortPkgMeta.new()
-        doc = REXML::Document.new(f)
-        
-        root_el = doc.root
-        submitter_el = root_el.elements["submitter"]
-        package_el = root_el.elements["package"]
-        
-        meta[:submitter_email] = submitter_el.elements["email"].text
-        meta[:submitter_name] = submitter_el.elements["name"].text
-        meta[:submitter_notes] = submitter_el.elements["notes"].text
-        
-        meta[:name] = package_el.elements["name"].text
-        meta[:epoch] = package_el.elements["epoch"].text
-        meta[:version] = package_el.elements["version"].text
-        meta[:revision] = package_el.elements["revision"].text
-        
-        meta[:short_desc] = package_el.elements["description"].text;
-        meta[:long_desc] = package_el.elements["long_description"].text;
-        meta[:home_page] = package_el.elements["homepage"].text;
-            
-        meta[:maintainers] = []
-        package_el.elements.each("maintainers/maintainer") { |m| meta.maintainers << m.text }
-        
-        meta[:variants] = []
-        package_el.elements.each("variants/variant")  do |v|
-          variant = VariantMeta.new()
-          variant[:name] = v.elements["name"].text
-          variant[:description] = v.elements["description"].text if v.elements["description"]
-          meta.variants << variant
-        end
-        
-        meta[:categories] = []
-        package_el.elements.each("categories/category")  { |c| meta.categories << c.text }
-
-        return meta
-    end
-    
-    def import_from_file(file)
-        raise PortPkgException, "nil file_path" if file.nil?
-        
-        # Make a temporary directory
-        tempDirPath = TempDirectories.makeTempDir
-        
-        # Write the portpkg file to the temporary directory
-        pkgPath = tempDirPath + "portpkg.portpkg"
-        metaName = "portpkg_meta.xml"
-        metaPath = tempDirPath + metaName
- 
-        expandedPkgPath = tempDirPath + "portpkg"
-        File.open(pkgPath, "w") { |f| f.write(file.read) }
-        
-        # Note: a bug in xar presently prevents us from limiting the extraction to the portpkg directory,
-        # => which we'd like to do for the sake of cleanliness. Hopefully this will become fixed soon.
-        raise PortPkgException, "xar tool not executable" if !File.executable?(MPWA::XARTOOL)
-        system("cd #{tempDirPath}; #{MPWA::XARTOOL} -xf #{pkgPath} -s #{metaPath} -n #{metaName}")
-        raise PortPkgException, "error extracting portpkg from xar archive" if $? != 0
-        raise PortPkgException, "no meta information file" if !metaPath.file?
-         
-        # Parse the meta information       
-        meta = nil
-        File.open(metaPath, "r") { |f| meta = PortPkg.extract_pkg_meta_from_file(f) }
-        
-        # Fill-in portpkg information from metadata
-        raise PortPkgException, "no submitter email" if meta.submitter_email.nil? || meta.submitter_email.empty?
-        self.submitted_at = Time.now
-        self.submitter = Person.ensure_person_with_email(meta.submitter_email, meta.submitter_name)
-        self.submitter_notes = meta.submitter_notes
-        
-        self.name = meta.name
-        self.short_desc = meta.short_desc
-        self.long_desc = meta.long_desc
-        self.home_page = meta.home_page
-        
-        self.epoch = meta.epoch
-        self.version = meta.version
-        self.revision = meta.revision
-        
-        # Map to, and/or create, a port
-        self.port = Port.ensure_port(meta.name, meta)
-        
-        # Save before we add variants and tags
-        self.save        
-        
-        # Add the variants
-        meta.variants.each do |v|
-          self.variants << Variant.new(:name => v.name, :description => v.description)
-        end
-        
-        # Tag with categories
-        meta.categories.each { |c| self.add_tag(c) }
-        
-        # Save unpacked data into a file
-        portpkg_ref = FileRef.create_from_path(pkgPath, tempDirPath,
-                            :mimetype => 'application/vnd.macports.portpkg')
-        portpkg_ref.is_port_pkg = true
-        self.file_refs << portpkg_ref
-        
-        # Save files from the expanded package
-        expandedPkgPath.find do |p|
-            self.file_refs << FileRef.create_from_path(p, tempDirPath) if p.file?
-        end
-        
-        # Final save
-        self.save
-        
-        # Cleanup the temp directory
-        tempDirPath.rmtree
-        
-        # Return the port_pkg
-        return self
-     end
-    
-    def file_ref_by_path(file_path)
-        candidates = self.file_refs.select { |r| r.file_info.file_path == file_path }
-        return candidates ? candidates.first : nil
-    end
-    
-    def portpkg_file_ref()
-        candidates = self.file_refs.select { |r| r.is_port_pkg }
-        return candidates ? candidates.first : nil
-    end
-    
-    def data_file_refs()
-        refs = self.file_refs.select { |r| !r.is_port_pkg }
-        return refs
-    end
-    
-    def add_tag(name)
-        tag = Tag.find_or_create_by_name(name)
-        self.tags << tag unless self.tags.include?(tag)
-    end
-    
-    def remove_tag(name)
-        self.tags.select { |t| t.name == name }.each { |t| self.tags.delete(t) }
-    end
-    
-    def <=>(other)
-        self.id <=> other.id
-    end
-
-end

Copied: branches/gsoc08-mpwa/app/views/packages (from rev 38264, branches/gsoc08-mpwa/app/views/port_pkg)

Modified: branches/gsoc08-mpwa/app/views/packages/show.rhtml
===================================================================
--- branches/gsoc08-mpwa/app/views/port_pkg/show.rhtml	2008-07-14 06:25:57 UTC (rev 38264)
+++ branches/gsoc08-mpwa/app/views/packages/show.rhtml	2008-07-15 04:43:14 UTC (rev 38291)
@@ -40,9 +40,7 @@
 
 <p>
 	<strong>Submitter:</strong>
-  	 <%= link_to email_obfuscate(@port_pkg.submitter.user_name),
-                     :controller => 'person', :action => 'show',
-                     :id => @port_pkg.submitter %>
+  	 <%= link_to @port_pkg.submitter.user_name, @port_pkg.submitter %>
 </p>
 
 <p>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20080714/434cd93f/attachment-0001.html 


More information about the macports-changes mailing list