Commit e46364e6 authored by Fabio Pelosin's avatar Fabio Pelosin

[pod-list] Introduced pod list new

parent 8fb0665b
require 'time'
module Pod module Pod
class Command class Command
class List < Command class List < Command
def self.banner def self.banner
%{List all pods: %{List all pods:
$ pod list $ pod list
Lists all available pods. Lists all available pods.
$ pod list [DAYS] $ pod list new
Lists the pods introduced in the master repo since the given number of days.} Lists the pods introduced in the master repository since the last check.}
end end
def self.options def self.options
...@@ -24,75 +25,59 @@ module Pod ...@@ -24,75 +25,59 @@ module Pod
def initialize(argv) def initialize(argv)
parse_set_options(argv) parse_set_options(argv)
@days = argv.arguments.first @new = argv.option('new')
unless @days == nil || @days =~ /^[0-9]+$/ super unless argv.empty?
super
end
end end
def dir def dir
config.repos_dir + 'master' config.repos_dir + 'master'
end end
def dir_list_from_commit(commit) def last_check_file
Dir.chdir(dir) { git("ls-tree --name-only -r #{commit}") } config.repos_dir + 'list_new.txt'
end end
def commit_from_days_ago (days) def update_last_check_time(time)
Dir.chdir(dir) { git("rev-list -n1 --before=\"#{days} day ago\" --first-parent master") } File.open(last_check_file, 'w') {|f| f.write(time)}
end end
def spec_names_from_commit (commit) def last_check_time
dir_list = dir_list_from_commit(commit) string = File.open(last_check_file, "rb").read
Time.parse(string)
# Keep only subdirectories rescue
dir_list.gsub!(/^[^\/]*$/,'') Time.now - 60 * 60 * 24 * 15
# Keep only subdirectories name
dir_list.gsub!(/(.*)\/[0-9].*/,'\1')
result = dir_list.split("\n").uniq
result.delete('')
result
end end
def new_specs_set(commit) def new_specs_since(time)
#TODO: find the changes for all repos all = Source.all_sets
new_specs = spec_names_from_commit('HEAD') - spec_names_from_commit(commit) all.reject! {|set| (set.creation_date - time).to_i <= 0 }
sets = all_specs_set.select { |set| new_specs.include?(set.name) } all.sort_by {|set| set.creation_date}
end
def all_specs_set
result = []
Source.all.each do |source|
source.pod_sets.each do |set|
result << set
end
end
result
end end
def list_new def list_new
sets = new_specs_set(commit_from_days_ago(@days)) time = last_check_time
present_sets(sets) time_string = time.strftime("%A %m %B %Y (%H:%M)")
if !list sets = new_specs_since(time)
if sets.count != 0 if sets.empty?
puts "#{sets.count} new pods were added in the last #{@days} days" puts "\nNo new pods were added since #{time.localtime}" unless list
puts
else else
puts "No new pods were added in the last #{@days} days" present_sets(sets)
puts update_last_check_time(sets.last.creation_date)
end puts "#{sets.count} new pods were added since #{time_string}" unless list
end end
puts
end end
def list_all def list_all
present_sets(all_specs_set) present_sets(all = Source.all_sets)
puts "#{all_specs_set.count} pods were found" puts "#{all.count} pods were found"
puts puts
end end
def run def run
if @days if @new
puts "\nUpdating Spec Repositories\n".yellow if config.verbose?
#Repo.new(ARGV.new(["update"])).run
list_new list_new
else else
list_all list_all
......
...@@ -29,15 +29,12 @@ module Pod ...@@ -29,15 +29,12 @@ module Pod
else else
puts "--> #{set.name} (#{set.versions.reverse.join(", ")})".green puts "--> #{set.name} (#{set.versions.reverse.join(", ")})".green
puts_wrapped_text(set.specification.summary) puts_wrapped_text(set.specification.summary)
spec = set.specification.part_of_other_pod? ? set.specification.part_of_specification : set.specification spec = set.specification.part_of_other_pod? ? set.specification.part_of_specification : set.specification
source = spec.source.reject {|k,_| k == :commit || k == :tag }.values.first
puts_detail('Homepage', spec.homepage) puts_detail('Homepage', spec.homepage)
puts_detail('Source', source) puts_detail('Source', spec.source_url)
if @stats if @stats
stats = stats(source) stats = stats(spec.source_url)
puts_detail('Watchers', stats[:watchers]) puts_detail('Watchers', stats[:watchers])
puts_detail('Forks', stats[:forks]) puts_detail('Forks', stats[:forks])
end end
......
...@@ -12,6 +12,10 @@ module Pod ...@@ -12,6 +12,10 @@ module Pod
end end
end end
def all_sets
all.map! {|source| source.pod_sets}.flatten
end
def search(dependency) def search(dependency)
all.map { |s| s.search(dependency) }.compact.first || all.map { |s| s.search(dependency) }.compact.first ||
raise(Informative, "[!] Unable to find a pod named `#{dependency.name}'".red) raise(Informative, "[!] Unable to find a pod named `#{dependency.name}'".red)
...@@ -32,6 +36,10 @@ module Pod ...@@ -32,6 +36,10 @@ module Pod
Aggregate.new.all Aggregate.new.all
end end
def self.all_sets
Aggregate.new.all_sets
end
def self.search(dependency) def self.search(dependency)
Aggregate.new.search(dependency) Aggregate.new.search(dependency)
end end
......
...@@ -126,10 +126,15 @@ module Pod ...@@ -126,10 +126,15 @@ module Pod
def header_dir=(dir) def header_dir=(dir)
@header_dir = Pathname.new(dir) @header_dir = Pathname.new(dir)
end end
def header_dir def header_dir
@header_dir || pod_destroot_name @header_dir || pod_destroot_name
end end
def source_url
source.reject {|k,_| k == :commit || k == :tag }.values.first
end
attr_writer :compiler_flags attr_writer :compiler_flags
def compiler_flags def compiler_flags
flags = "#{@compiler_flags}" flags = "#{@compiler_flags}"
......
...@@ -67,6 +67,12 @@ module Pod ...@@ -67,6 +67,12 @@ module Pod
end.compact.sort.reverse end.compact.sort.reverse
end end
def creation_date
Dir.chdir(@pod_dir.dirname) do
@creation_date ||= Time.at(`git log --format=%ct ./#{name} | tail -1`.to_i)
end
end
class External < Set class External < Set
def initialize(specification) def initialize(specification)
@specification = specification @specification = specification
......
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