Class: Msf::Util::SVN

Inherits:
Object
  • Object
show all
Defined in:
lib/msf/util/svn.rb

Class Method Summary collapse

Class Method Details

.days_since_updateObject


72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/msf/util/svn.rb', line 72

def self.days_since_update
  @@info ||= load_root
  svnt = @@info[:updated]
  if(not svnt)
    return
  end

  # Date.parse and Date.strptime are both broken beyond repair in
  # ruby 1.8.6 and older.  Just bail if the parsing doesn't work.
  begin
    diff = (Date.parse(Time.now.to_s) - Date.parse(svnt)).to_f
  rescue ArgumentError
  end
end

.last_updated_dateObject


105
106
107
108
109
110
111
112
113
114
115
# File 'lib/msf/util/svn.rb', line 105

def self.last_updated_date
  @@info ||= load_root
              svnt = @@info[:updated]
              if(not svnt)
                      return
              end
  begin
    Date.parse(@@info[:updated])
  rescue ArgumentError
  end
end

.last_updated_friendlyObject


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/msf/util/svn.rb', line 87

def self.last_updated_friendly
  diff = self.days_since_update
  case diff
  when nil
    "at an unknown date"
  when -2.0 .. 1.0
    "today"
  when 1.0 .. 2.0
    "yesterday"
  else
    if (diff.to_i > 7)
      "%red#{diff.to_i} days ago%clr"
    else
      "#{diff.to_i} days ago"
    end
  end
end

.load_rootObject


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/msf/util/svn.rb', line 17

def self.load_root
  info = {}
  path = ::File.join(::File.dirname(__FILE__), "..", "..", "..", ".svn", "entries")
  if !::File.exists?(path)
    return info
  end
  contents = ''
  File.open(path, "rb") do |fd|
    contents = fd.read(::File.size(path))
  end
  if contents.include? "<?xml"
    require 'rexml/document'
    rd = REXML::Document.new(contents).root
    rd.elements.each { |e|
      if e.attributes['name'] == ""
        info[:root] = e.attributes['url']
        info[:revision] = e.attributes['revision']
        info[:updated] = e.attributes['committed-date']
        break
      end
    }
  else
    ents = contents.split("\x0c")
    ents[0].split("\n").each do |line|
      line.strip!
      next if line.empty?
      case line
      when /framework3/
        info[:root] = line
      when /^\d+$/
        info[:revision] = line.to_i
      when /^\d{4}-\d.*T/
        info[:updated] = line
      end
      break if (info[:root] and info[:revision] and info[:updated])
    end
  end
  info
end

.revisionObject


57
58
59
60
# File 'lib/msf/util/svn.rb', line 57

def self.revision
  @@info ||= load_root
  @@info[:revision]
end

.rootObject


67
68
69
70
# File 'lib/msf/util/svn.rb', line 67

def self.root
  @@info ||= load_root
  @@info[:root]
end

.updatedObject


62
63
64
65
# File 'lib/msf/util/svn.rb', line 62

def self.updated
  @@info ||= load_root
  @@info[:updated]
end