hi, who has an example of how to retrieve svn-version information from inside a rails application. i''d like to display this information to the user, so that he can report a bug relating to the version number. retrieving should be quick as it is displayed on every view. many thanks in advance, siegi --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You could parse the results of `svn info` then store it in a cached class variable in your ApplicationHelper. In production mode, `svn info` would only be called once. def svn_revision (@@svn_revision rescue false) or @@svn_revision = `svn info`.scan(/Revision: (\d+)/)[0][0] end Hacky, but... On Apr 23, 3:27 pm, siegi <siegfried.wiesenho...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hi, > > who has an example of how to retrieve svn-version information from > inside a rails application. > > i''d like to display this information to the user, so that he can > report a bug relating to the version number. > > retrieving should be quick as it is displayed on every view. > > many thanks in advance, > siegi--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rob Biedenharn
2007-Apr-23 13:14 UTC
Re: getting svn version info from inside rails application
On Apr 23, 2007, at 8:10 AM, eden li wrote:> You could parse the results of `svn info` then store it in a cached > class variable in your ApplicationHelper. In production mode, `svn > info` would only be called once. > > def svn_revision > (@@svn_revision rescue false) or > @@svn_revision = `svn info`.scan(/Revision: (\d+)/)[0][0] > end > > Hacky, but... > > On Apr 23, 3:27 pm, siegi <siegfried.wiesenho...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> hi, >> >> who has an example of how to retrieve svn-version information from >> inside a rails application. >> >> i''d like to display this information to the user, so that he can >> report a bug relating to the version number. >> >> retrieving should be quick as it is displayed on every view. >> >> many thanks in advance, >> siegiIf you''re deploying with capistrano and have a revisions.log, you can use something like this: Layout: <div id=''footer''> <div id=''revision''><%= application_revision %></div> <div id=''time''><%= Time.now %></div> </div> Helper: def application_revision " ver. #{RevisionNumber.from_log}" rescue '''' end From lib/revision_number.rb: Note that this uses the file-tail gem to simplify getting the last line of the log file: # revision_number.rb # # Copyright (c) 2007 Rob Biedenharn # Rob [at] AgileConsultingLLC.com # Rob_Biedenharn [at] alum.mit.edu # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to # deal in the Software without restriction, including without limitation the # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or # sell copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. require ''rubygems'' require ''file/tail'' require ''logger'' class RevisionNumber @@logger = Logger.new(STDERR) @@logger.level = ENV[''RAILS_ENV''] == ''development'' ? Logger::DEBUG : Logger::INFO @@logger.debug "Loading #{self}" @@revision = {} def self.from_log name=''revisions.log'', forced=false return @@revision[name] if @@revision.has_key?(name) && ! forced starting_dir = Dir.pwd begin @@logger.debug "Starting in #{Dir.pwd} to look for #{name}" this_dir = Dir.pwd until File.exists?(name) || this_dir == ''/'' Dir.chdir ''..'' @@logger.debug "Not found; moving up to #{Dir.pwd}" break if this_dir == Dir.pwd # I.e., Windows "c:/.." => "c:/" this_dir = Dir.pwd end begin @@logger.debug "In #{Dir.pwd}, ready to open #{name}..." rev = File.open(name) do |f| f.extend(File::Tail) f.backward(1).gets.match(/(\d+) \d{14}$/)[1] end rescue rev = ''indeterminant'' else rev = ''unknown'' if rev.nil? end ensure Dir.chdir(starting_dir) end @@revision[name] = rev end end --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Faisal N Jawdat
2007-Apr-25 01:57 UTC
Re: getting svn version info from inside rails application
You might use a metadata file, accessible to the app, which includes the svn revision, and then have that revision managed by svn''s ''Revision'' keyword substitution: http://svnbook.red-bean.com/nightly/en/ svn.advanced.props.special.keywords.html -faisal On Apr 23, 2007, at 3:27 AM, siegi wrote:> > hi, > > who has an example of how to retrieve svn-version information from > inside a rails application. > > i''d like to display this information to the user, so that he can > report a bug relating to the version number. > > retrieving should be quick as it is displayed on every view. > > many thanks in advance, > siegi > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Brad Ediger
2007-Apr-27 21:51 UTC
Re: getting svn version info from inside rails application
On Apr 23, 2007, at 2:27 AM, siegi wrote:> > hi, > > who has an example of how to retrieve svn-version information from > inside a rails application. > > i''d like to display this information to the user, so that he can > report a bug relating to the version number. > > retrieving should be quick as it is displayed on every view.Hope you still need this, I''m a few days behind on reading the forums. Here''s what I use, assuming you have svnversion in your path: class ApplicationController < ActionController::Base def svn_revision @svn_revision ||= `svnversion .`.gsub(/^.*\:/, '''').gsub(/[MS]/, '''').to_i end helper_method :svn_revision end That caches the revision number for the life of the Ruby process, so it should be fast. Brad
Alain Ravet
2007-Apr-28 12:42 UTC
Re: getting svn version info from inside rails application
A variation: In environment.rb -------------------- APP_REVISION = IO.popen("svn info").readlines[4] rescue "not found" In your views/layout : -------------------- <!-- project svn revision : <%= APP_REVISION %>--> I place that line at the very bottom of layouts => I can quickly check what version has been deployed withouth showing to the users who don''t care. Alain> You could parse the results of `svn info` then store it in a cached > class variable in your ApplicationHelper. In production mode, `svn > info` would only be called once. > > def svn_revision > (@@svn_revision rescue false) or > @@svn_revision = `svn info`.scan(/Revision: (\d+)/)[0][0] > end--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Alain Ravet
2007-Apr-28 12:45 UTC
Re: getting svn version info from inside rails application
> If you''re deploying with capistrano and have a revisions.log, you canrevisions.log is phased out in Capistrano 2.x see: http://www.capify.org/upgrade Alain --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---