Add support for import / export / merge of ranges.

This commit is contained in:
Glenn Y. Rolland 2013-09-23 14:02:39 +02:00
parent 53a9d33647
commit 6eb6e5e310

View file

@ -4,6 +4,7 @@
require 'pp' require 'pp'
require 'date' require 'date'
require 'optparse' require 'optparse'
require 'yaml'
class GitExtractor class GitExtractor
@ -130,19 +131,24 @@ class GitExtractor
def add range def add range
merged = false merged = false
merged_range = nil
# merge # merge
@ranges.each do |old| @ranges.each do |old|
#pp old #pp old
if old.overlap? range then if old.overlap? range then
old.merge range old.merge range
merged_range = old
merged = true merged = true
break
end end
end end
# add if needed # add if needed
if not merged then if merged then
@ranges.delete merged_range
self.add merged_range
else
@ranges.push range @ranges.push range
end end
end end
@ -172,6 +178,9 @@ class GitExtractor
:date_filter_enable => false, :date_filter_enable => false,
:date_filter => ".*?", :date_filter => ".*?",
:input_dump => [],
:output_dump => nil,
:verbose => false :verbose => false
} }
@rangelist = nil @rangelist = nil
@ -190,6 +199,14 @@ class GitExtractor
exit 0 exit 0
end end
opts.on("-i","--input FILE", "Set input dump file") do |file|
@config[:input_dump] << file
end
opts.on("-o","--output FILE", "Set output dump file") do |file|
@config[:output_dump] = file
end
opts.on("-d","--date DATE", "Keep only commits since DATE") do |date| opts.on("-d","--date DATE", "Keep only commits since DATE") do |date|
puts "set date filter to #{date}" puts "set date filter to #{date}"
@config[:date_filter] = DateTime.parse(date); @config[:date_filter] = DateTime.parse(date);
@ -214,11 +231,12 @@ class GitExtractor
end end
def analyze def analyze_git
# git log # git log
# foreach, create time range (before) + logs # foreach, create time range (before) + logs
process = IO.popen ["git", "log", "--date=iso"] process = IO.popen ["git", "log", "--date=iso"]
@rangelist = RangeList.new @rangelist = RangeList.new
commit = nil commit = nil
loop do loop do
@ -277,12 +295,41 @@ class GitExtractor
end end
def analyze_dumps
#read ranges
@rangelist = RangeList.new
@config[:input_dump].each do |filename|
rangelist = YAML::load(File.open(filename,"r"))
rangelist.each do |range|
@rangelist.add range
end
end
end
def analyze
if @config[:input_dump].empty? then
analyze_git
else
analyze_dumps
end
end
def export
return if @config[:output_dump].nil?
puts "Exporting to %s" % @config[:output_dump]
File.open(@config[:output_dump], "w") do |file|
file.puts YAML::dump(@rangelist)
end
end
def report def report
return if not @config[:output_dump].nil?
@rangelist.each do |r| @rangelist.each do |r|
puts r.to_s + "\n" puts r.to_s + "\n"
end end
puts "TOTAL: %.2f hours" % @rangelist.sum puts "TOTAL: %.2f hours" % @rangelist.sum
exit 0
end end
end end
@ -290,5 +337,7 @@ end
app = GitExtractor.new app = GitExtractor.new
app.parse_cmdline ARGV app.parse_cmdline ARGV
app.analyze app.analyze
app.export
app.report app.report
exit 0