2009-11-09 01:50:44 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# framework-util-svn
|
|
|
|
# --------------
|
|
|
|
#
|
|
|
|
# The class provides methods for parsing the SVN information in the framework directory
|
|
|
|
#
|
|
|
|
###
|
|
|
|
|
|
|
|
require 'date'
|
|
|
|
|
|
|
|
module Msf
|
|
|
|
module Util
|
|
|
|
class SVN
|
|
|
|
|
|
|
|
def self.load_root
|
|
|
|
info = {}
|
|
|
|
path = ::File.join(::File.dirname(__FILE__), "..", "..", "..", ".svn", "entries")
|
|
|
|
if !::File.exists?(path)
|
|
|
|
return info
|
|
|
|
end
|
|
|
|
ents = []
|
|
|
|
File.open(path, "rb") do |fd|
|
|
|
|
ents = fd.read(::File.size(path)).split("\x0c")
|
|
|
|
end
|
|
|
|
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
|
|
|
|
info
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.revision
|
2009-11-13 22:50:12 +00:00
|
|
|
@@info ||= load_root
|
|
|
|
@@info[:revision]
|
2009-11-09 01:50:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.updated
|
2009-11-13 22:50:12 +00:00
|
|
|
@@info ||= load_root
|
|
|
|
@@info[:updated]
|
2009-11-09 01:50:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.root
|
2009-11-13 22:50:12 +00:00
|
|
|
@@info ||= load_root
|
|
|
|
@@info[:root]
|
2009-11-09 01:50:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.days_since_update
|
2009-11-13 22:50:12 +00:00
|
|
|
@@info ||= load_root
|
|
|
|
svnt = @@info[:updated]
|
2009-11-09 01:50:44 +00:00
|
|
|
if(not svnt)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
diff = (Date.parse(Time.now.to_s) - Date.parse(svnt)).to_f
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.last_updated_friendly
|
|
|
|
diff = self.days_since_update
|
|
|
|
case diff
|
|
|
|
when nil
|
2009-11-13 22:50:12 +00:00
|
|
|
"at an unknown date"
|
2009-11-09 01:50:44 +00:00
|
|
|
when -2.0 .. 1.0
|
|
|
|
"today"
|
|
|
|
when 1.0 .. 2.0
|
|
|
|
"yesterday"
|
|
|
|
else
|
2009-11-10 03:27:48 +00:00
|
|
|
if (diff.to_i > 7)
|
|
|
|
"%red#{diff.to_i} days ago%c"
|
|
|
|
else
|
|
|
|
"#{diff.to_i} days ago"
|
|
|
|
end
|
2009-11-09 01:50:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-11-13 22:50:12 +00:00
|
|
|
def self.last_updated_date
|
|
|
|
@@info ||= load_root
|
|
|
|
Date.parse(@@info[:updated])
|
|
|
|
end
|
2009-11-09 01:50:44 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|