[23799] users/jberry/mpwa
source_changes at macosforge.org
source_changes at macosforge.org
Mon Apr 9 21:08:22 PDT 2007
Revision: 23799
http://trac.macosforge.org/projects/macports/changeset/23799
Author: jberry at macports.org
Date: 2007-04-09 21:08:22 -0700 (Mon, 09 Apr 2007)
Log Message:
-----------
mpwa: Add mimetype detection of pkg files by shelling out to file command
Modified Paths:
--------------
users/jberry/mpwa/app/models/port_pkg.rb
users/jberry/mpwa/app/models/port_pkg_file.rb
Added Paths:
-----------
users/jberry/mpwa/lib/mpwa-conf.rb
Modified: users/jberry/mpwa/app/models/port_pkg.rb
===================================================================
--- users/jberry/mpwa/app/models/port_pkg.rb 2007-04-10 04:07:01 UTC (rev 23798)
+++ users/jberry/mpwa/app/models/port_pkg.rb 2007-04-10 04:08:22 UTC (rev 23799)
@@ -1,11 +1,9 @@
require 'time'
require 'temp_directories'
require 'port'
+require 'mpwa-conf'
class PortPkg < ActiveRecord::Base
- @@xar = "/opt/local/bin/xar"
- @@porttool = "/opt/local/bin/port"
-
belongs_to :port
belongs_to :submitter, :class_name => 'Person', :foreign_key => 'submitter_id'
has_many :files, :class_name => 'PortPkgFile'
@@ -24,12 +22,11 @@
# 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.
- puts("cd #{tempDirPath}; #{@@xar} -xf #{pkgPath}")
- system("cd #{tempDirPath}; #{@@xar} -xf #{pkgPath}") or raise "badpkg"
+ system("cd #{tempDirPath}; #{MPWA::XARTOOL} -xf #{pkgPath}") or raise "badpkg"
# Validate the portpkg, bailing on error
(expandedPkgPath + "Portfile").file? or raise "badpkg"
- infoOut = `#{@@porttool} info --name --category --epoch --version --revision --variants --maintainers --short_desc --long_description --description --homepage #{expandedPkgPath}`
+ infoOut = `#{MPWA::PORTTOOL} info --name --category --epoch --version --revision --variants --maintainers --short_desc --long_description --description --homepage #{expandedPkgPath}`
$?.exitstatus or raise "badpkg"
# Extract:
@@ -76,17 +73,12 @@
port_pkg.revision = info['revision']
# Save unpacked data into a file
- file.rewind
- portPkgFile = PortPkgFile.from_file(file, 'portpkg.xar')
- port_pkg.files << portPkgFile
+ port_pkg.files << PortPkgFile.from_path(pkgPath, tempDirPath)
# Save files from the expanded package
expandedPkgPath.find do |p|
if p.file?
- File.open(p, "r") do |f|
- relPath = p.relative_path_from(tempDirPath).to_s
- port_pkg.files << PortPkgFile.from_file(f, relPath)
- end
+ port_pkg.files << PortPkgFile.from_path(p, tempDirPath)
end
end
Modified: users/jberry/mpwa/app/models/port_pkg_file.rb
===================================================================
--- users/jberry/mpwa/app/models/port_pkg_file.rb 2007-04-10 04:07:01 UTC (rev 23798)
+++ users/jberry/mpwa/app/models/port_pkg_file.rb 2007-04-10 04:08:22 UTC (rev 23799)
@@ -1,3 +1,5 @@
+require 'mpwa-conf'
+
class PortPkgFile < ActiveRecord::Base
belongs_to :port_pkg
has_one :file_blob
@@ -2,18 +4,21 @@
- def PortPkgFile.from_path(path)
+ def PortPkgFile.from_path(path, path_root = nil)
port_pkg_file = PortPkgFile.new
- return port_pkg_file.read_from_path(path)
+ return port_pkg_file.read_from_path(path, path_root)
end
- def PortPkgFile.from_file(file, path)
- port_pkg_file = PortPkgFile.new
- return port_pkg_file.read_from_file(file, path)
+ def PortPkgFile.mimetype_from_path(path)
+ mimetype = /^([^;]+)(;\w*(.*))?/.match(`#{MPWA::FILETOOL} --mime --brief #{path}`)[1]
end
- def read_from_path(path)
- File.open(path, "r") { |f| read_from_file(f, path) }
+ 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
- def read_from_file(file, path)
+ def read_from_file(file, args = {})
# Create a new blob
@@ -24,9 +29,9 @@
self.file_blob = blob
# Save other file information
- self.file_path = path
+ self.file_path = args[:path]
self.length = blob.data.length
- self.mime_type = 'text/plain' # for now: could map file extensions and/or magic numbers, plus test for whether it looks like text
+ self.mime_type = args[:mimetype] || 'application/octet-stream'
self.sha256 = Digest::SHA256.hexdigest(blob.data)
return self
Added: users/jberry/mpwa/lib/mpwa-conf.rb
===================================================================
--- users/jberry/mpwa/lib/mpwa-conf.rb (rev 0)
+++ users/jberry/mpwa/lib/mpwa-conf.rb 2007-04-10 04:08:22 UTC (rev 23799)
@@ -0,0 +1,5 @@
+class MPWA
+ FILETOOL = "/usr/bin/file"
+ XARTOOL = "/opt/local/bin/xar"
+ PORTTOOL = "/opt/local/bin/port"
+end
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20070409/9afa6047/attachment.html
More information about the macports-changes
mailing list