[23997] users/jberry/mpwa

source_changes at macosforge.org source_changes at macosforge.org
Sat Apr 14 07:06:17 PDT 2007


Revision: 23997
          http://trac.macosforge.org/projects/macports/changeset/23997
Author:   jberry at macports.org
Date:     2007-04-14 07:06:15 -0700 (Sat, 14 Apr 2007)

Log Message:
-----------
More work on routes and emission of portpkg files

Modified Paths:
--------------
    users/jberry/mpwa/app/controllers/port_pkg_controller.rb
    users/jberry/mpwa/app/models/port_pkg.rb
    users/jberry/mpwa/app/models/port_pkg_file.rb
    users/jberry/mpwa/config/routes.rb
    users/jberry/mpwa/doc/design.txt

Modified: users/jberry/mpwa/app/controllers/port_pkg_controller.rb
===================================================================
--- users/jberry/mpwa/app/controllers/port_pkg_controller.rb	2007-04-14 13:43:34 UTC (rev 23996)
+++ users/jberry/mpwa/app/controllers/port_pkg_controller.rb	2007-04-14 14:06:15 UTC (rev 23997)
@@ -50,14 +50,28 @@
   end
   
   def submit
-      portpkg = params[:portpkg]
-      
-      # Validate parameters (we're probably making this too hard)
-      raise "bad package" if portpkg.nil?
-      
-      # Import the package from the file
-      @port_pkg = PortPkg.import_from_file(portpkg)  
+    portpkg = params[:portpkg]
+
+    # Validate parameters (we're probably making this too hard)
+    raise "bad package" if portpkg.nil?
+
+    # Import the package from the file
+    @port_pkg = PortPkg.import_from_file(portpkg)  
   end
   
+  def emit_portpkg
+    port_pkg = PortPkg.find(params[:id])
+    send_file(port_pkg.portpkg_file())
+  end
   
+  def emit_portpkg_path
+    port_pkg = PortPkg.find(params[:id])
+    send_file(port_pkg.file_by_path(params[:path].join '/'))
+  end
+  
+  def send_file(file)
+    send_data file.file_blob.data, :filename => file.file_path, :type => file.mime_type, :disposition => 'inline'
+  end
+  
+  
 end

Modified: users/jberry/mpwa/app/models/port_pkg.rb
===================================================================
--- users/jberry/mpwa/app/models/port_pkg.rb	2007-04-14 13:43:34 UTC (rev 23996)
+++ users/jberry/mpwa/app/models/port_pkg.rb	2007-04-14 14:06:15 UTC (rev 23997)
@@ -91,4 +91,13 @@
         return port_pkg
     end
     
+    def file_by_path(file_path)
+        candidates = self.files.select { |f| f.file_path == file_path }
+        return candidates.first
+    end
+    
+    def portpkg_file()
+        file_by_path("portpkg.xar")
+    end
+    
 end

Modified: users/jberry/mpwa/app/models/port_pkg_file.rb
===================================================================
--- users/jberry/mpwa/app/models/port_pkg_file.rb	2007-04-14 13:43:34 UTC (rev 23996)
+++ users/jberry/mpwa/app/models/port_pkg_file.rb	2007-04-14 14:06:15 UTC (rev 23997)
@@ -16,8 +16,6 @@
     def read_from_path(path, path_root = nil)
         mimetype = PortPkgFile.mimetype_from_path(path)
         reported_path = path_root.nil? ? path : Pathname.new(path).relative_path_from(path_root).to_s
-        
-    puts "path: #{path}; reportedpath: #{reported_path}"
         File.open(path, "r") { |f| read_from_file(f, :path => reported_path, :mimetype => mimetype) }
         return self
     end

Modified: users/jberry/mpwa/config/routes.rb
===================================================================
--- users/jberry/mpwa/config/routes.rb	2007-04-14 13:43:34 UTC (rev 23996)
+++ users/jberry/mpwa/config/routes.rb	2007-04-14 14:06:15 UTC (rev 23997)
@@ -13,12 +13,18 @@
   # -- just remember to delete public/index.html.
   # map.connect '', :controller => "welcome"
 
-  # Pretty url for portpkg by pkgid
-  map.portpkg 'portpkg/:id', :controller => 'port_pkg_file', :action => 'emit', :id => /\d+/
+  # Pretty urls
+  # ===========
+  # portpkg by pkgid
+  map.portpkg 'portpkg/:id', :controller => 'port_pkg', :action => 'emit_portpkg', :id => /\d+/
   
-  # Pretty url for portpkg by named selector (unimplemented)
+  # portpkg file by pkgid
+  map.portpkg 'portpkg/:id/*path', :controller => 'port_pkg', :action => 'emit_portpkg_path', :id => /\d+/
+
+  # portpkg by named selector (unimplemented)
   map.connect 'portpkg/:selector/:portname', :controller => 'port_pkg', :action => 'byselector'
 
+  # Pretty 
 
   # Allow downloading Web Service WSDL as a file with an extension
   # instead of a file named 'wsdl'

Modified: users/jberry/mpwa/doc/design.txt
===================================================================
--- users/jberry/mpwa/doc/design.txt	2007-04-14 13:43:34 UTC (rev 23996)
+++ users/jberry/mpwa/doc/design.txt	2007-04-14 14:06:15 UTC (rev 23997)
@@ -143,6 +143,9 @@
 			// This url returns the portpkg, not a human readable page
 		http://db.macports.org/portpkg/<pkgid>
 		
+			// Access to portpkg files
+		http://db.macports.org/portpkg/<pkgid>/path_to_file
+		
 			// A portpkg defined by a query instead of a pkgid
 			// (will 301 redirect to http://db.macports.org/portpkg/<pkgid>)
 		http://db.macports.org/portpkg/latest/<portname>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20070414/ab61a14c/attachment.html


More information about the macports-changes mailing list