[23526] users/jberry/mpwa/app

source_changes at macosforge.org source_changes at macosforge.org
Tue Apr 3 16:33:27 PDT 2007


Revision: 23526
          http://trac.macosforge.org/projects/macports/changeset/23526
Author:   jberry at macports.org
Date:     2007-04-03 16:33:27 -0700 (Tue, 03 Apr 2007)

Log Message:
-----------
mpwa (MacPorts WebApp) now supports basic port submission

Modified Paths:
--------------
    users/jberry/mpwa/app/controllers/application.rb
    users/jberry/mpwa/app/controllers/ports_controller.rb
    users/jberry/mpwa/app/views/ports/submit.rhtml

Modified: users/jberry/mpwa/app/controllers/application.rb
===================================================================
--- users/jberry/mpwa/app/controllers/application.rb	2007-04-03 21:49:12 UTC (rev 23525)
+++ users/jberry/mpwa/app/controllers/application.rb	2007-04-03 23:33:27 UTC (rev 23526)
@@ -2,13 +2,18 @@
 # Likewise, all the methods added will be available for all controllers.
 class ApplicationController < ActionController::Base
 
-	attr_reader :svn, :repo_root, :repo_submissions, :repo_versions
+    attr_reader :svn, :tar, :mtree
+	attr_reader :repo_url, :repo_root, :repo_submissions, :repo_submissions_url
 
 	def initialize
 		@svn = "/opt/local/bin/svn"
+		@tar = "/usr/bin/tar"
+		@mtree = "/usr/sbin/mtree"
+		
+		@repo_url = "file:///Users/jberry/Projects/macports/users/jberry/mpwa/testrepo/repo"
 		@repo_root = "/Users/jberry/Projects/macports/users/jberry/mpwa/testrepo/root"
 		@repo_submissions = "#{@repo_root}/port/submissions"
-		@repo_versions = "#{@repo_root}/port/versions"
+		@repo_submissions_url = "#{@repo_url}/port/submissions"
 	end
 	
 end
\ No newline at end of file

Modified: users/jberry/mpwa/app/controllers/ports_controller.rb
===================================================================
--- users/jberry/mpwa/app/controllers/ports_controller.rb	2007-04-03 21:49:12 UTC (rev 23525)
+++ users/jberry/mpwa/app/controllers/ports_controller.rb	2007-04-03 23:33:27 UTC (rev 23526)
@@ -1,62 +1,164 @@
 require "fileutils"
 
 class PortsController < ApplicationController
+  
+    def makeTempDir()
+        tmpdir = Dir::tmpdir
+        basename = "macports"
+        n = 1
+        begin
+    	    tmpname = File.join(tmpdir, sprintf('%s.%d.%d', basename, $$, n))
+    	    n += 1
+      	    next if File.exist?(tmpname)
+     	    begin
+     	        Dir.mkdir(tmpname)
+     	    rescue SystemCallError
+     	        next
+     	    end
+        end while !File.exist?(tmpname)
+        return tmpname
+    end
 
 	def subversionCommand(args)
-		system("#{svn} #{args}")
+		`#{svn} #{args}`
 	end
 
-	def ensureCategory(category)
-		categoryDir = "#{repo_submissions}/#{category}"
+	def ensurePort(category, portName)
+        # Make sure the base directory exists
+        assert { File.directory?(repo_submissions) }
+
+		# Build the category directory as needed
+ 		categoryDir = "#{repo_submissions}/#{category}"
 		if !File.directory?(categoryDir)
 			FileUtils.mkdir(categoryDir)
 			subversionCommand("add #{categoryDir}")
-			subversionCommand("commit -m '' #{categoryDir}")
+			subversionCommand("commit -m 'Make category #{category}' #{categoryDir}")
 		end
-	end
-	
-	def ensurePort(category, portname)
-	  # Make sure the base directory exists
-	  puts repo_submissions
-	  
-	  assert { File.directory?(repo_submissions) }
-	  
-	  # Make sure the category exists
-		ensureCategory(category)
 		
 		# Build the port directory as needed
-		portDir = "#{repo_submissions}/#{category}/#{portname}"
+		portDir = "#{repo_submissions}/#{category}/#{portName}"
 		if !File.directory?(portDir)
 			FileUtils.mkdir(portDir)
 			subversionCommand("add #{portDir}")
-			subversionCommand("commit -m '' #{portDir}")
+			subversionCommand("commit -m 'Make new port #{portName}' #{portDir}")
 		end
+		
+		# Build the port common directory as needed
+		commonDir = "#{repo_submissions}/#{category}/#{portName}/common"
+		if !File.directory?(commonDir)
+			FileUtils.mkdir(commonDir)
+			subversionCommand("add #{commonDir}")
+			subversionCommand("commit -m 'Make common directory for #{portName}' #{commonDir}")
+		end
 	end
 	
 	def submit
+	    # TODO:
+	    # => Move some of this into the model
+	    # => And/or break up into more methods
+	    
 		# Get and validate parameters
 		@category = params[:category]
 		@portName = params[:portname]
-		@dirpackage = params[:dirpackage]
+		@submission = params[:submission]
 		
+		# Validate parameters (we're probably making this too hard)
+		raise "bad category" if @category.nil?
+		raise "bad portName" if @portName.nil?
+		raise "bad package" if @submission.nil?
+		
 		# Look for, and create if not found, a category/port
 		ensurePort(@category, @portName)
 		
-		# Unpack the port into temporary space
-		#
-		# We'll store:
-		# => /port/submissions/catname/portname/(unpacked)
-		# - and - 
-		# => /port/versions/catname/portname/version-uid/packed.tgz
-		# => /port/versions/catname/portname/version-uid/unpacked/
-		# => /port/versions/catname/portname/version-uid/meta/
-		# => /port/versions/catname/portname/version-uid/binaries/
+		# Unpack into temporary directory a directory called "submission"
+		tempDir = makeTempDir
+		package = "#{tempDir}/package"
+		submission = "#{tempDir}/submission"
+		common = "#{tempDir}/common"
+		target = "#{tempDir}/target"
+		submission_url = "#{repo_submissions_url}/#{@category}/#{@portName}"
 		
-		# For each file that already exists, copy it over,
-		# if it doesn't exist in dest, svn add it
-		# and if it doesn't exist in src, svn rm it
-	end
+		File.open(package, "w") { |f| f.write(@submission.read) }		
+		system("#{tar} -C #{tempDir} -zf #{package} -x submission")
+		
+		# Check out a private temporary copy of the submissions directory
+		# so that we don't get into concurrency issues by multi-modifying the directory
+		subversionCommand("co #{submission_url}/common #{common}")
+		
+		# Sync the submission into the common directory by parsing the results of mtree
+		changeCnt = 0
+		treeOut = `#{mtree} -c -k type,cksum -p #{submission} | #{mtree} -p #{common}`
+		treeOut.each_line do |line|
+		    puts "Line #{line}"
+		    
+		    case line
+	        when /^\w+/
+	            puts "Whitespace line #$1"
+	            
+	        when /^(.*) changed$/
+	            srcFile = File.join(submission, $1)
+	            dstFile = File.join(common, $1)
+	            puts "Changed file #{srcFile} != #{dstFile}"
+	            FileUtils.cp(srcFile, dstFile)
+	            changeCnt += 1
+	            
+	        when /^(.*) extra$/
+	            dstFile = File.join(common, $1)
+	            if /^\./ =~ File.basename(dstFile)
+	                puts "Skipping invisible extra entry #{dstFile}"
+	            else
+ 	                puts "Extra entry #{dstFile}"
+ 	                subversionCommand("rm #{dstFile}")
+    	            changeCnt += 1
+               end
+	            
+	        when /^(.*) missing$/
+	            srcFile = File.join(submission, $1)
+	            dstFile = File.join(common, $1)
+
+ 	            if /^\./ =~ File.basename(dstFile)
+	                puts "Skipping invisible new entry #{dstFile}"
+ 	            else
+       	            puts "New entry #{srcFile} ==> #{dstFile}"
+ 
+                    if File.directory?(srcFile)
+                        subversionCommand("mkdir #{dstFile}")
+                    else
+        	            FileUtils.cp(srcFile, dstFile)
+                        subversionCommand("add #{dstFile}")
+                    end
+                    
+    	            changeCnt += 1
+                end
+
+		    end
+		end
+		
+		if changeCnt == 0
+		    puts "No changes detected, so don't create a new submission"
+		else
+    		# Commit changes to the common directory
+    		commitOutput = subversionCommand("commit -m 'New submission of #{@portName}' #{common}")
+    		commitRevision = /^Committed revision (\d+)./.match(commitOutput)[1]
+    		puts "Creating new submission #{commitRevision} at #{submission_url}/#{commitRevision}"
 	
+    		# Make the target directory structure
+    		subversionCommand("mkdir -m 'Create new submission #{commitRevision} of port #{@portName}' #{submission_url}/#{commitRevision}")
+	
+    		# Check out the submission directory
+    		subversionCommand("co #{submission_url}/#{commitRevision} #{target}")
+    
+            # Add original package and meta directory
+            FileUtils.cp(package, "#{target}/port.tgz")
+            FileUtils.mkdir("#{target}/meta")
+            subversionCommand("add #{target}/port.tgz #{target}/meta")
+	
+    		# Copy over the common directory into unpacked
+    		subversionCommand("cp #{common} #{target}/unpacked")
+	
+    		# Commit the submission directory
+    		subversionCommand("commit -m 'Complete submission #{commitRevision} of port #{@portName}' #{target}")
+	    end
+ 	end
   
-  
 end

Modified: users/jberry/mpwa/app/views/ports/submit.rhtml
===================================================================
--- users/jberry/mpwa/app/views/ports/submit.rhtml	2007-04-03 21:49:12 UTC (rev 23525)
+++ users/jberry/mpwa/app/views/ports/submit.rhtml	2007-04-03 23:33:27 UTC (rev 23526)
@@ -2,8 +2,7 @@
 <p>Find me in app/views/ports/submit.rhtml</p>
 
 <p>repo_root: <%= @controller.repo_root %></p>
-<p>repo_versions: <%= @controller.repo_versions %></p>
+<p>repo_submissions: <%= @controller.repo_submissions %></p>
 
-
 <p>category: <%= @category %></p>
 <p>portname: <%= @portname %></p>
\ No newline at end of file

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


More information about the macports-changes mailing list