#!/usr/bin/env ruby
require 'set'
require 'yaml'
require 'optparse'
options = {}
opts = OptionParser.new do |opts|
opts.banner = "Usage: list-packages.rb [options]"
opts.separator ""
opts.separator "Specific options:"
opts.on('-r', '--release-path FILE', 'Path to release') { |v| options[:release_path] = v }
end
opts.parse!
unless options[:release_path] && File.exist?(options[:release_path])
puts opts.help
exit(2)
end
jobs_folders = Dir.glob(File.join(options[:release_path], 'jobs', '*')).select { |f| File.directory? f }
packages = Set.new
def extract_packages_from_spec(deps_section, packages)
lambda do |folder|
spec_file = File.join(folder, 'spec')
raise "There is no spec file in #{folder}" unless File.exist?(spec_file)
spec = YAML.load_file(spec_file)
packages.merge(spec[deps_section]) if spec[deps_section]
end
end
jobs_folders.each &extract_packages_from_spec('packages', packages)
packages_folders = packages.to_a.map do |package|
File.join(options[:release_path], 'packages', package)
end
packages_folders.each &extract_packages_from_spec('dependencies', packages)
puts "List of packages:\n---\n"
puts packages.to_a.join("\n")