[Mongrel] versioning of win32 versus ruby gems

Charles Brian Quinn me at seebq.com
Tue Jan 9 18:00:32 EST 2007


Ezra, I found this cap plugin you posted to be extremely useful, ccing
Capistrano list, where I know you've posted about it too.  I have a
patch, adding the options as a params hash for readability.  My
cursory googling..err..searching could not reveal where this
capistrano "Gem" plugin resides.

main difference is this method:

def install(packages, source=nil, version=nil)

is now:

def install(packages, options={})

so you can do:

gem.select 'mysql', :version => '2.7', :platform => 'ruby',
:extra_params => '-- --with-mysql-config'

or:

gem.select 'mongrel', :version => '0.3.13.4'

Here's the diff, (email formatting is horrible), or point me to an svn
for latest to build a patch

$ diff cap_gem_plugin.rb cap_gem_plugin_cbq.rb
39,41c36,40
<   def install(packages, source=nil, version=nil)
<     sudo "#{GEM_INSTALL} #{version ? '-v '+version.to_s : nil} #
< {source ? '--source='+source : nil } #{packages.to_a.join(' ')}"
---
>   # def install(packages, source=nil, version=nil)
>   def install(packages, options={})
>     sudo "#{GEM_INSTALL} #{options[:version] ? '-v '+options[:version].to_s : nil} " +
>          "#{options[:source] ? '--source='+options[:source] : nil } " +
>          "#{packages.to_a.join(' ')}"
63c59,60
<   def select(package, source=nil, version=nil, platform='ruby')
---
>   # def select(package, source=nil, version=nil, platform='ruby')
>   def select(package, options={})
65,66c62,65
<     cmd="#{GEM_INSTALL} #{version ? '-v '+version.to_s : nil} #
< {package} #{source ? '--source='+source : nil }"
---
>     cmd="#{GEM_INSTALL} #{options[:version] ? '-v '+options[:version].to_s : nil} " +
>         "#{package} " +
>         "#{options[:source] ? '--source='+options[:source] : nil } " +
>         "#{options[:extra_params] ? options[:extra_params] : nil}"
70c69
<     when /\s(\d+).*\(#{platform}\)/
---
>     when /\s(\d+).*\(#{options[:platform]}\)/


Thanks!
-- 
Charles Brian Quinn
self-promotion: www.seebq.com
highgroove studios: www.highgroove.com
slingshot hosting: www.slingshothosting.com
678.389.9462

Ruby on Rails Bootcamp at the Big Nerd Ranch
Intensive Ruby on Rails Training:
http://www.bignerdranch.com/classes/ruby.shtml

On 12/21/06, Ezra Zygmuntowicz <ezmobius at gmail.com> wrote:
> On Dec 21, 2006, at 11:13 AM, Charles Brian Quinn wrote:
> > Thanks Steven,
> >
> > This is using Jamis' net/ssh library and using:
> >
> > sudo cmd do |channel, stream, data|
> >        data.each_line do | line |
> >
> > to regex match lines and type in input.  this could work, but i was
> > hoping for bash or something simpler....
> >
> > Guess that means it's time to move my all of my shell scripts over to
> > ruby (except for the one that installs ruby) ;-)
> >
> > Thanks!
>
>
> Charles-
>
>         You and me both. I didn't want to spend the time writing bash
> scripts for this when I need to do it on tons of machines anyway. So
> the script he linked to is actually a capistrano plugin. Take the
> file and put it somewhere in your load path and then require it from
> a capistrano recipe file and then you can use it like this:
>
>
> require 'cap_gem'
>
> task :install_gems, :roles => :app do
>    gem.select 'mongrel' , 'http://mongrel.rubyforge.org/releases'
>    gem.install 'mongrel',  'http://mongrel.rubyforge.org/releases' ,
> '1.0'
> end
>
> select will select the most recent versions for the current platform
> and install it. install will install a specific version but won't
> auto select from a menu. So is there are two or more versions of a
> gem then you want to use select.
>
> Here is the more current version of the plugin for cap. This one
> supports the --source option.
>
> require 'rubygems'
> require 'capistrano'
> # Installs within Capistrano as the plugin _gem_.
> # Prefix all calls to the library with <tt>gem.</tt>
> # Manages installing gems and versioned gems.
> module Gem
>
>    # Default install command
>    #
>    # * doesn't install documentation
>    # * installs all required dependencies automatically.
>    #
>    GEM_INSTALL="gem install -y --no-rdoc"
>
>    # Upgrade the *gem* system to the latest version. Runs via *sudo*
>    def update_system
>      sudo "gem update --system"
>    end
>
>    # Updates all the installed gems to the latest version. Runs via
> *sudo*.
>    # Don't use this command if any of the gems require a version
> selection.
>    def upgrade
>      sudo "gem update --no-rdoc"
>    end
>
>    # Removes old versions of gems from installation area.
>    def cleanup
>      sudo "gem cleanup"
>    end
>
>    # Installs the gems detailed in +packages+, selecting version
> +version+ if
>    # specified.
>    #
>    # +packages+ can be a single string or an array of strings.
>    #
>    def install(packages, source=nil, version=nil)
>      sudo "#{GEM_INSTALL} #{version ? '-v '+version.to_s : nil} #
> {source ? '--source='+source : nil } #{packages.to_a.join(' ')}"
>    end
>
>    def uninstall(package)
>      sudo "gem uninstall #{package}" do |channel, stream, data|
>        data.each_line do |line|
>          if line =~ /\[Yn\]/
>            channel.send_data "Y\n"
>          end
>        end
>      end
>    end
>
>    # Auto selects a gem from a list and installs it.
>    #
>    # *gem* has no mechanism on the command line of disambiguating
> builds for
>    # different platforms, and instead asks the user. This method has
> the necessary
>    # conversation to select the +version+ relevant to +platform+ (or
> the one nearest
>    # the top of the list if you don't specify +version+).
>    def select(package, source=nil, version=nil, platform='ruby')
>      selections={}
>      cmd="#{GEM_INSTALL} #{version ? '-v '+version.to_s : nil} #
> {package} #{source ? '--source='+source : nil }"
>      sudo cmd do |channel, stream, data|
>        data.each_line do | line |
>      case line
>      when /\s(\d+).*\(#{platform}\)/
>        if selections[channel[:host]].nil?
>          selections[channel[:host]]=$1.dup+"\n"
>          logger.info "Selecting #$&", "#{stream} :: #{channel[:host]}"
>        end
>      when /\s\d+\./
>        # Discard other selections from data stream
>      when /^>/
>        channel.send_data selections[channel[:host]]
>        logger.debug line, "#{stream} :: #{channel[:host]}"
>      else
>        logger.info line, "#{stream} :: #{channel[:host]}"
>      end
>        end
>      end
>    end
>
> end
>
> Capistrano.plugin :gem, Gem
>
>
> Cheers-
> -- Ezra Zygmuntowicz-- Lead Rails Evangelist
> -- ez at engineyard.com
> -- Engine Yard, Serious Rails Hosting
> -- (866) 518-YARD (9273)
>
>
> _______________________________________________
> Mongrel-users mailing list
> Mongrel-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/mongrel-users
>


More information about the Mongrel-users mailing list