Commit 31b6da64 authored by Fabio Pelosin's avatar Fabio Pelosin

[pod-list] pod list new now doesn't need to store the state in a file and…

[pod-list] pod list new now doesn't need to store the state in a file and displays the results in groups
parent 51a90756
...@@ -29,47 +29,33 @@ module Pod ...@@ -29,47 +29,33 @@ module Pod
super unless argv.empty? super unless argv.empty?
end end
def last_check_file def list_all
config.repos_dir + 'list_new' present_sets(all = Source.all_sets)
end puts "#{all.count} pods were found"
puts
def update_last_check_time(time)
File.open(last_check_file, 'w') {|f| f.write(time)}
end
def last_check_time
if File.exists?(last_check_file)
string = File.open(last_check_file, "rb").read
Time.parse(string)
else
Time.now - 60 * 60 * 24 * 15
end
end
def new_sets_since(time)
all = Source.all_sets
all.reject! {|set| (set.creation_date - time).to_i <= 0 }
all.sort_by {|set| set.creation_date}
end end
def list_new def list_new
time = last_check_time days = [1,2,3,5,8]
time_string = time.strftime("%A %m %B %Y (%H:%M)") dates, groups = {}, {}
sets = new_sets_since(time) days.each {|d| dates[d] = Time.now - 60 * 60 * 24 * d}
if sets.empty? Source.all_sets.sort_by {|set| set.creation_date}.each do |set|
puts "\nNo new pods were added since #{time.localtime}" unless list set_date = set.creation_date
else days.each do |d|
present_sets(sets) if set_date > dates[d]
update_last_check_time(sets.last.creation_date) groups[d] = [] unless groups[d]
puts "#{sets.count} new pods were added since #{time_string}" unless list groups[d] << set
break
end
end
end end
puts puts
end days.reverse.each do |d|
sets = groups[d]
def list_all next unless sets
present_sets(all = Source.all_sets) puts "Pods added in the last #{d == 1 ? '1 day' : "#{d} days"}\n".yellow
puts "#{all.count} pods were found" present_sets(sets)
puts end
end end
def run def run
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment