Class: Dev::Svn

Inherits:
Object
  • Object
show all
Defined in:
lib/dev/Svn.rb

Class Method Summary collapse

Class Method Details

.last_changed_revision(url) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/dev/Svn.rb', line 4

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

.update_revision_variable(filename, variable_name, url) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dev/Svn.rb', line 15

def self.update_revision_variable(filename,variable_name,url)
  if File.exist?(filename)
    revision=Dev::Svn::last_changed_revision(url)
    replace="#{variable_name}='#{revision}'"
    puts "  " + replace + " in " + filename unless revision=="0"
    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

.update_revision_variables(filename) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/dev/Svn.rb', line 31

def self.update_revision_variables(filename)
  if File.exist?(filename)
    puts_debug "scanning " + filename + " for revision variables"
    text=File.read(filename)
    # extract potential variable names of form 

    text.scan(/([\dA-Z_]+)=['"][\d]+['"]/).each{ | var_match |
      puts_debug "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_debug "found uri_match: " + uri_match.to_s
        uri=uri_match[0].to_s
        update_revision_variable(filename,varname,uri)
      }
    }
  else
    puts "  " + filename + " does not exist"
  end
end