[24683] users/jberry/mpwa

source_changes at macosforge.org source_changes at macosforge.org
Sun Apr 29 20:54:48 PDT 2007


Revision: 24683
          http://trac.macosforge.org/projects/macports/changeset/24683
Author:   jberry at macports.org
Date:     2007-04-29 20:54:48 -0700 (Sun, 29 Apr 2007)

Log Message:
-----------
mpwa: some cleanup

Modified Paths:
--------------
    users/jberry/mpwa/app/controllers/port_pkg_controller.rb
    users/jberry/mpwa/app/controllers/ports_controller.rb
    users/jberry/mpwa/app/models/port_pkg.rb
    users/jberry/mpwa/app/models/port_pkg_file.rb
    users/jberry/mpwa/doc/TODO.txt

Modified: users/jberry/mpwa/app/controllers/port_pkg_controller.rb
===================================================================
--- users/jberry/mpwa/app/controllers/port_pkg_controller.rb	2007-04-30 03:28:46 UTC (rev 24682)
+++ users/jberry/mpwa/app/controllers/port_pkg_controller.rb	2007-04-30 03:54:48 UTC (rev 24683)
@@ -54,11 +54,18 @@
   def submit
     portpkg = params[:portpkg]
 
-    # Validate parameters (we're probably making this too hard)
-    raise "bad package" if portpkg.nil?
+    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)  
+        # Create a package from the file
+        @port_pkg = PortPkg.create_from_file(portpkg)
+        
+        url = portpkg_url(:id => @port_pkg)
+        render :text => "STATUS: 0\nMESSAGE: PortPkg submitted successfully\nURL: #{url}"
+    rescue PortPkgException => ex
+        render :text => "STATUS: 1\nMESSAGE: Error during submit: #{ex}", :status => 400
+    end
   end
   
   def emit_portpkg

Modified: users/jberry/mpwa/app/controllers/ports_controller.rb
===================================================================
--- users/jberry/mpwa/app/controllers/ports_controller.rb	2007-04-30 03:28:46 UTC (rev 24682)
+++ users/jberry/mpwa/app/controllers/ports_controller.rb	2007-04-30 03:54:48 UTC (rev 24683)
@@ -1,5 +1,10 @@
 require "fileutils"
 
+# NOTE: THIS CODE IS OBSOLETE AND NOT BEING USED AT PRESENT
+#
+# But it is an example to use in case we decide to auto-commit
+# some things into svn
+
 class PortsController < ApplicationController
   
     def makeTempDir()

Modified: users/jberry/mpwa/app/models/port_pkg.rb
===================================================================
--- users/jberry/mpwa/app/models/port_pkg.rb	2007-04-30 03:28:46 UTC (rev 24682)
+++ users/jberry/mpwa/app/models/port_pkg.rb	2007-04-30 03:54:48 UTC (rev 24683)
@@ -13,6 +13,9 @@
     :name, :epoch, :version, :revision,
     :short_desc, :long_desc, :home_page,
     :maintainers, :variants, :categories)
+    
+class PortPkgException < RuntimeError
+end
 
 class PortPkg < ActiveRecord::Base
     belongs_to :port
@@ -63,7 +66,7 @@
     end
     
     def import_from_file(file)
-        raise "badpkg: nil file_path" if file.nil?
+        raise PortPkgException, "nil file_path" if file.nil?
         
         # Make a temporary directory
         tempDirPath = TempDirectories.makeTempDir
@@ -78,10 +81,12 @@
         
         # 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.
-        system("cd #{tempDirPath}; #{MPWA::XARTOOL} -xf #{pkgPath} -s #{metaPath} -n #{metaName}") or raise "badpkg"
-        
+        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       
-        raise "badpkg: no meta information" if !metaPath.file?
         meta = nil
         File.open(metaPath, "r") { |f| meta = PortPkg.extract_pkg_meta_from_file(f) }
         
@@ -104,7 +109,7 @@
         meta.categories.each { |c| self.add_tag(c) }
         
         # Save unpacked data into a file
-        self.files << PortPkgFile.from_path(pkgPath, tempDirPath)
+        self.files << PortPkgFile.from_path(pkgPath, tempDirPath, :mimetype => 'application/x-macports-portpkg')
         
         # Save files from the expanded package
         expandedPkgPath.find do |p|
@@ -127,7 +132,7 @@
     end
     
     def portpkg_file()
-        file_by_path("portpkg.xar")
+        file_by_path("portpkg.portpkg")
     end
     
     def has_tag(name)

Modified: users/jberry/mpwa/app/models/port_pkg_file.rb
===================================================================
--- users/jberry/mpwa/app/models/port_pkg_file.rb	2007-04-30 03:28:46 UTC (rev 24682)
+++ users/jberry/mpwa/app/models/port_pkg_file.rb	2007-04-30 03:54:48 UTC (rev 24683)
@@ -5,32 +5,33 @@
     belongs_to :port_pkg
     has_one :file_blob
     
-    def PortPkgFile.from_path(path, path_root = nil)
+    def PortPkgFile.from_path(path, path_root = nil, options = {})
         port_pkg_file = PortPkgFile.new
-        return port_pkg_file.read_from_path(path, path_root)
+        return port_pkg_file.read_from_path(path, path_root, options)
     end
     
     def PortPkgFile.mimetype_from_path(path)
         mimetype = /^([^;]+)(;\w*(.*))?/.match(`#{MPWA::FILETOOL} --mime --brief #{path}`)[1]
     end
 
-    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
+    def read_from_path(path, path_root = nil, options = {})
+        mimetype = options[:mimetype] || PortPkgFile.mimetype_from_path(path)
+        reported_path = options[:filename] || path_root.nil? ?
+            path.to_s : Pathname.new(path).relative_path_from(path_root).to_s
         File.open(path, "r") { |f| read_from_file(f, :path => reported_path, :mimetype => mimetype) }
         return self
     end
     
-    def read_from_file(file, args = {})
+    def read_from_file(file, options = {})
         # Create a new blob
         blob = FileBlob.new
         blob.read(file)
         self.file_blob = blob
         
         # Save other file information
-        self.file_path = args[:path]
+        self.file_path = options[:path]
         self.length = blob.data.length
-        self.mime_type = args[:mimetype] || 'application/octet-stream'
+        self.mime_type = options[:mimetype] || 'application/octet-stream'
         
         self.md5 = Digest::MD5.hexdigest(blob.data)
         self.sha256 = Digest::SHA256.hexdigest(blob.data)

Modified: users/jberry/mpwa/doc/TODO.txt
===================================================================
--- users/jberry/mpwa/doc/TODO.txt	2007-04-30 03:28:46 UTC (rev 24682)
+++ users/jberry/mpwa/doc/TODO.txt	2007-04-30 03:54:48 UTC (rev 24683)
@@ -1,20 +1,13 @@
 Short Term:
 
-	- Figure out the proper way to through exceptions out of model, for instance
-	  if we detect a bad package.
-	- Check for, and report, a bad status from xar unpack
-	- Report status from submit back to client, including portpkg url
-	- Maintain naming of portpkg file from client submit
 	- Set proper naming for downloaded file (this may work already)
+	- Security cleanup (edit)
 
 Medium Term:
 	
 	- Improve (drastically) the UI for port browsing
-	- Implement port searching
+	- Implement port searching	
 	
-	
-	
-	
 UI Design Thoughts:
 
 	- Global Page header:

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


More information about the macports-changes mailing list