Sha256: 367e917487943d8340c9f6c82aa1e3513070a45e1aa64c1664719ce5ed6137b7

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

module Dev
class Svn
  
  def self.last_changed_revision(url)
    call=Dev::SystemCall.new("svn info #{url}")
    if call.status == 0
      call.output.each_line { |line|
        words=line.split(':')
        return words[1].strip if(words.length==2 && words[0] == "Last Changed Rev")
      }
    end
    return "0"
  end
  
  def self.update_revision_variable(filename,variable_name,url)
    if File.exist?(filename)
      revision=Dev::Svn::last_changed_revision(url)
      replace="#{variable_name}='#{revision}'"
      text=File.read(filename)
      unless text.include?(replace)
        unless revision == "0"
          puts "  updating " + filename + " with " + replace
          search=Regexp.new("#{variable_name}='[\\d]+'")
          Dev::Environment.replace_text_in_file(filename,search,"#{variable_name}='#{revision}'")
        end
      end
    end
  end
  
  def self.update_revision_variables(filename)
    if File.exist?(filename)
      text=File.read(filename)
      # extract potential variable names of form 
      text.scan(/([A-Z_]+)='[\d]+'/).each{ | var_match |
        #puts "found var_match: " + var_match[0].to_s
        varname = var_match[0].to_s
        # extract potential urls that use the variable name
        # '([.\w:\/-]+)@#{INTERFACE_REV}'
        uri_search=Regexp.new("'([.\\w:\\/-]+)@" + '#{' + "#{varname}" + '}' + "'")
        #puts uri_search.to_s
        text.scan(uri_search).each { |uri_match|
          #puts "found uri_match: " + uri_match.to_s
          uri=uri_match[0].to_s
          update_revision_variable(filename,varname,uri)
        }
      }
    end
  end
  
end # class Svn
end # module Dev

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dev-1.0.17 lib/dev/Svn.rb