From 3412b02660c5f1f112597dbd228290e184bd570d Mon Sep 17 00:00:00 2001 From: Vikrant Chaudhary Date: Tue, 8 Sep 2009 14:51:57 +0530 Subject: [PATCH] Edited plugin.rb --- railties/lib/commands/plugin.rb | 46 ++++++++++++++++++++++++++++---------- 1 files changed, 34 insertions(+), 12 deletions(-) diff --git a/railties/lib/commands/plugin.rb b/railties/lib/commands/plugin.rb index 159db70..50511b6 100644 --- a/railties/lib/commands/plugin.rb +++ b/railties/lib/commands/plugin.rb @@ -17,7 +17,7 @@ # This is Free Software, copyright 2005 by Ryan Tomayko (rtomayko@gmail.com) # and is licensed MIT: (http://www.opensource.org/licenses/mit-license.php) -$verbose = false +$verbose = true require 'open-uri' @@ -145,6 +145,8 @@ class Plugin def install(method=nil, options = {}) method ||= rails_env.best_install_method? + @name = options[:name] || @name + puts "Chosen name of plugin is #{@name}" if $verbose if :http == method method = :export if svn_url? method = :git if git_url? @@ -262,7 +264,7 @@ class Plugin end def guess_name(url) - @name = File.basename(url) + @name = File.basename(url.gsub(/(\?|#)(.*)$/, '')) if @name == 'trunk' || @name.empty? @name = File.basename(File.dirname(url)) end @@ -370,6 +372,8 @@ module Commands o.define_head "Install one or more plugins." o.separator "" o.separator "Options:" + o.on( "-n NAME", "--name NAME", + "Name of plugin. Default is name of the last directory of uri.") { |v| @options[:name] = v } o.on( "-x", "--externals", "Use svn:externals to grab the plugin.", "Enables plugin updates and plugin versioning.") { |v| @method = :externals } @@ -421,8 +425,7 @@ module Commands end rescue StandardError => e puts "Plugin not found: #{args.inspect}" - puts e.inspect if $verbose - exit 1 + raise if $verbose end end @@ -476,7 +479,12 @@ class RecursiveHTTPFetcher def initialize(urls_to_fetch, level = 1, cwd = ".") @level = level @cwd = cwd - @urls_to_fetch = RUBY_VERSION >= '1.9' ? urls_to_fetch.lines : urls_to_fetch.to_a + @urls_to_fetch = (RUBY_VERSION >= '1.9' ? + urls_to_fetch.lines : urls_to_fetch.to_a).map {|u| + u = strip_uri_for_fragment(u) + u[0] << '/' unless u[0][-1].chr == '/' + u.join + } @quiet = false end @@ -501,35 +509,49 @@ class RecursiveHTTPFetcher @cwd = File.dirname(@cwd) end + #Strip fragments(#) and GET parameters. + def strip_uri_for_fragment uri + regex = Regexp.new('(\?|#)(.*)$') + [uri.gsub(regex, ''), regex.match(uri).to_s] + end + + def extract_file_name uri + File.basename(strip_uri_for_fragment(uri)[0]) + end + def links(base_url, contents) links = [] contents.scan(/href\s*=\s*\"*[^\">]*/i) do |link| link = link.sub(/href="/i, "") next if link =~ /svnindex.xsl$/ next if link =~ /^(\w*:|)\/\// || link =~ /^\./ - links << File.join(base_url, link) + links << File.join(strip_uri_for_fragment(base_url)[0], link) end links end def download(link) - puts "+ #{File.join(@cwd, File.basename(link))}" unless @quiet + file_name = extract_file_name(link) + puts "Downloading file #{link}" if $verbose + puts "+ #{File.join(@cwd, file_name)}" unless @quiet open(link) do |stream| - File.open(File.join(@cwd, File.basename(link)), "wb") do |file| + File.open(File.join(@cwd, file_name), "wb") do |file| file.write(stream.read) end end end - + def fetch(links = @urls_to_fetch) links.each do |l| - (l =~ /\/$/ || links == @urls_to_fetch) ? fetch_dir(l) : download(l) + stripped = strip_uri_for_fragment(l)[0] + (stripped =~ /\/$/) ? fetch_dir(l) : download(l) end end - + def fetch_dir(url) @level += 1 - push_d(File.basename(url)) if @level > 0 + push_d(extract_file_name(url)) if @level > 0 + puts "fetching directory #{url}" if $verbose open(url) do |stream| contents = stream.read fetch(links(url, contents)) -- 1.6.0.4 From de58776f763460d66e11869aa2b24d86eeda0a76 Mon Sep 17 00:00:00 2001 From: Vikrant Chaudhary Date: Mon, 14 Sep 2009 13:12:35 +0530 Subject: [PATCH] Minor imprevement --- railties/lib/commands/plugin.rb | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/railties/lib/commands/plugin.rb b/railties/lib/commands/plugin.rb index 50511b6..378f9a4 100644 --- a/railties/lib/commands/plugin.rb +++ b/railties/lib/commands/plugin.rb @@ -264,9 +264,10 @@ class Plugin end def guess_name(url) - @name = File.basename(url.gsub(/(\?|#)(.*)$/, '')) + base_url = url.gsub(/(\?|#)(.*)$/, '') + @name = File.basename(base_url) if @name == 'trunk' || @name.empty? - @name = File.basename(File.dirname(url)) + @name = File.basename(File.dirname(base_url)) end @name.gsub!(/\.git$/, '') if @name =~ /\.git$/ end -- 1.6.0.4 From 32b0d57b82449fa8558dd2b3725e09f04ca83e3a Mon Sep 17 00:00:00 2001 From: Vikrant Chaudhary Date: Mon, 14 Sep 2009 13:13:10 +0530 Subject: [PATCH] to false --- railties/lib/commands/plugin.rb | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/railties/lib/commands/plugin.rb b/railties/lib/commands/plugin.rb index 378f9a4..bc02e9c 100644 --- a/railties/lib/commands/plugin.rb +++ b/railties/lib/commands/plugin.rb @@ -17,7 +17,7 @@ # This is Free Software, copyright 2005 by Ryan Tomayko (rtomayko@gmail.com) # and is licensed MIT: (http://www.opensource.org/licenses/mit-license.php) -$verbose = true +$verbose = false require 'open-uri' -- 1.6.0.4