Add support for import / export / merge of ranges.
This commit is contained in:
parent
53a9d33647
commit
6eb6e5e310
1 changed files with 53 additions and 4 deletions
|
@ -4,6 +4,7 @@
|
|||
require 'pp'
|
||||
require 'date'
|
||||
require 'optparse'
|
||||
require 'yaml'
|
||||
|
||||
class GitExtractor
|
||||
|
||||
|
@ -130,19 +131,24 @@ class GitExtractor
|
|||
|
||||
def add range
|
||||
merged = false
|
||||
merged_range = nil
|
||||
|
||||
# merge
|
||||
@ranges.each do |old|
|
||||
#pp old
|
||||
if old.overlap? range then
|
||||
old.merge range
|
||||
merged_range = old
|
||||
merged = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# add if needed
|
||||
if not merged then
|
||||
if merged then
|
||||
@ranges.delete merged_range
|
||||
self.add merged_range
|
||||
else
|
||||
@ranges.push range
|
||||
end
|
||||
end
|
||||
|
@ -172,6 +178,9 @@ class GitExtractor
|
|||
:date_filter_enable => false,
|
||||
:date_filter => ".*?",
|
||||
|
||||
:input_dump => [],
|
||||
:output_dump => nil,
|
||||
|
||||
:verbose => false
|
||||
}
|
||||
@rangelist = nil
|
||||
|
@ -190,6 +199,14 @@ class GitExtractor
|
|||
exit 0
|
||||
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|
|
||||
puts "set date filter to #{date}"
|
||||
@config[:date_filter] = DateTime.parse(date);
|
||||
|
@ -214,11 +231,12 @@ class GitExtractor
|
|||
end
|
||||
|
||||
|
||||
def analyze
|
||||
def analyze_git
|
||||
# git log
|
||||
# foreach, create time range (before) + logs
|
||||
process = IO.popen ["git", "log", "--date=iso"]
|
||||
|
||||
|
||||
@rangelist = RangeList.new
|
||||
commit = nil
|
||||
loop do
|
||||
|
@ -277,12 +295,41 @@ class GitExtractor
|
|||
|
||||
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
|
||||
return if not @config[:output_dump].nil?
|
||||
|
||||
@rangelist.each do |r|
|
||||
puts r.to_s + "\n"
|
||||
end
|
||||
puts "TOTAL: %.2f hours" % @rangelist.sum
|
||||
exit 0
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -290,5 +337,7 @@ end
|
|||
app = GitExtractor.new
|
||||
app.parse_cmdline ARGV
|
||||
app.analyze
|
||||
app.export
|
||||
app.report
|
||||
exit 0
|
||||
|
||||
|
|
Loading…
Reference in a new issue