lib/reaver.rb in reaver-0.4.0 vs lib/reaver.rb in reaver-0.7.0
- old
+ new
@@ -1,10 +1,11 @@
# frozen_string_literal: true
require_relative 'reaver/version'
require_relative 'reaver/banner'
require_relative 'reaver/download'
+require_relative 'reaver/metadata'
require_relative 'reaver/collection'
require 'whirly'
require 'fileutils'
@@ -23,32 +24,38 @@
Whirly.configure spinner: 'bouncingBar',
color: true,
ambiguous_characters_width: 1
def self.main
- FileUtils.mkdir_p(CACHE_DIR)
FileUtils.mkdir_p(WORKDIR)
- puts ">> Search collections in #{WORKDIR}"
+ #puts ">> Search collections in #{WORKDIR}"
Dir.glob("#{WORKDIR}/*.yml").each do |f|
- if File.exist? f
- collection = Collection.new(f)
- collection.load_yaml
+ name = f.split('/').last
+ name = name.split('.').first
+ workdir = "#{CACHE_DIR}/#{name}"
- if collection.tasks
- next_download = collection.tasks['next'] ||= Time.new
- name = f.split('/').last
+ FileUtils.mkdir_p(workdir)
- if next_download < Time.new
- puts ' >> Download time for ' + name
- collection.launch
- else
- puts "Next download for #{name} >> #{next_download}"
- end
+ collection = Collection.new(f)
+ collection.load_yaml
+
+ if collection.tasks
+ metadata = MetaData.new(workdir, collection)
+ metadata.load_yaml
+ next_download = metadata.info['next']
+
+ if next_download < Time.new
+ #puts ' >> Download time for ' + name
+ FileUtils.chdir(workdir)
+ #puts " > chdir #{workdir}"
+ collection.launch(metadata)
+ else
+ puts " > Next download > #{next_download}"
end
- collection.save_yaml
+ metadata.save_yaml
end
end
end
end