reaver 0.4.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d4a124d2032645971e2084e688be989024bfc7deccaebb51c04742f85ebbd69
4
- data.tar.gz: 5d6f483932ebc078c182d054b329a45251c315856ec60084ae511c075773a2ba
3
+ metadata.gz: 32fb1834d726c5f6883514c899661f2a3ad42ed4dd53c5ab64fc0a97bcafe96e
4
+ data.tar.gz: fd73c58c53c159e86cc523960b795b30e3ca91a4333ef5340207bc438d71f6e9
5
5
  SHA512:
6
- metadata.gz: 4460f09f21e6e7816f50c24a1a2866a2e01de28f32cd8cb54b3600d8b13393bb6baf9bf05175c022b508119f82458c01115d6b8939ee02932c83f005eb8cfe92
7
- data.tar.gz: 1562641f8cd861fd7524e8445d9734eaef48d71a44bd66c012877562f0148094d8f049196f3d47e0c8092401290d63b4b798a3f5b57e471aa4e3674ea24a2f3d
6
+ metadata.gz: 54ce812f876370d2579221723c9d005abfd6abb1568ff8617f2272016287a4cc98990e2a55202a8ab4a791d4d1148c7c5b0715e3d8fd3b4e74064687dde84c15
7
+ data.tar.gz: 1e247b45ec3a47c90fa161c8e2677ae90dc8bea56b81e615db2a2c3f9c2ca68af82dc706825d412941b5aaabb398d5d06393bfd51c87c7780cadc638ecb2720f
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## 0.7.0, release 12/24/22
2
+
3
+ * Each collections download things in separate directory.
4
+ * Add a `changed` boolean if a file change.
5
+ * Stop modifying collection content, add them in a file called `metadata.yml`.
6
+ * Improve runtime.
7
+
8
+ ## 0.4.0, release 12/22/22
9
+
10
+ * Renaming project.
11
+ * Add a banner.
12
+ * Separate main.
13
+ * Add collection yml.
14
+ * Download stack.
1
15
 
2
16
  ## 0.0.1, release 12/21/22
3
17
  * Initial push, code freeying !
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # reaver
2
2
 
3
- A tools to downloads things on the net. Reaver is used to get all files
4
- required by your project, track the last version, etc.
3
+ A tool that allows to download and track the latest version of stuff on the net.
4
+ Define your collections in .yml and launch Reaver to retrieve everything.
5
5
 
6
6
  ## Collections
7
7
 
@@ -38,3 +38,5 @@ The `name` must contain the path extension for now.
38
38
  And start reaver simply with:
39
39
 
40
40
  $ reaver
41
+
42
+ Reaver download all files in `~/.cache/reaver` by default.
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'yaml'
4
4
  require 'time'
5
+ require 'digest'
5
6
 
6
7
  module Reaver
7
8
  class Collection
@@ -9,41 +10,44 @@ module Reaver
9
10
 
10
11
  def initialize(file)
11
12
  @file = file
13
+ @changed = false
12
14
  end
13
15
 
14
16
  def load_yaml
15
- puts "loading #{@file}..."
16
- @tasks = YAML.load_file(@file, permitted_classes: [Time, Symbol])
17
- # puts @tasks.inspect
17
+ puts ">> Loading #{@file}..."
18
+ if RUBY_VERSION >= '3.0'
19
+ @tasks = YAML.load_file(@file, permitted_classes: [Time, Symbol])
20
+ else
21
+ @tasks = YAML.load_file(@file)
22
+ end
18
23
  rescue => error
19
24
  raise error, "loading YAML fail for #{@file}: #{error.message}"
20
25
  end
21
26
 
22
- def launch
27
+ def launch(metadata)
23
28
  return unless @tasks
24
29
 
25
30
  if @tasks['things'].length >= 1
26
- @tasks['things'].each { |t| Reaver.download(t['url'], t['name']) }
31
+ @tasks['things'].each do |t|
32
+ if File.exist? t['name']
33
+ old_hash = Digest::MD5.file t['name']
34
+ else
35
+ @changed = true
36
+ end
37
+
38
+ Reaver.download(t['url'], t['name'])
39
+ compare_hash(t['name'], old_hash) if old_hash
40
+
41
+ metadata.info['changed'] = @changed
42
+ end
27
43
  end
28
-
29
- update_time
30
- end
31
-
32
- def save_yaml
33
- return if @tasks == nil
34
-
35
- File.open(@file, 'w') { |f| YAML.dump(@tasks, f) }
36
44
  end
37
45
 
38
46
  private
39
47
 
40
- def update_time
41
- return unless @tasks['things'].length >= 1
42
-
43
- now = Time.new
44
- n = @tasks['time'] if @tasks['time'].is_a?(Integer)
45
- @tasks['next'] = now + n ||= 0
46
- @tasks['last_download'] = now
48
+ def compare_hash(filename, old_hash)
49
+ hash = Digest::MD5.file filename
50
+ @changed = true if old_hash.hexdigest != hash.hexdigest
47
51
  end
48
52
  end
49
53
  end
@@ -2,13 +2,14 @@
2
2
 
3
3
  require 'open-uri'
4
4
  require 'net/http'
5
- require 'whirly'
6
5
  require 'tempfile'
7
6
  require 'fileutils'
8
7
 
9
8
  module Reaver
10
- def self.download(url, name)
11
- dest = "#{CACHE_DIR}/#{name}"
9
+ extend self
10
+
11
+ def download(url, name)
12
+ dest = name
12
13
  url = URI(url)
13
14
  raise Error, "url was invalid" if !url.respond_to?(:open)
14
15
 
@@ -19,21 +20,21 @@ module Reaver
19
20
  Whirly.start do
20
21
  Whirly.status = "downloading #{dest}"
21
22
  downloaded_file = URI.open(url, options)
22
- end
23
23
 
24
- # open-uri will return a StringIO instead of a Tempfile if the filesize
25
- # is less than 10 KB, so we patch this behaviour by converting it into
26
- # a Tempfile.
27
- if downloaded_file.is_a?(StringIO)
28
- tempfile = Tempfile.new("open-uri", binmode: true)
29
- IO.copy_stream(downloaded_file, tempfile.path)
30
- downloaded_file = tempfile
31
- FileUtils.mv downloaded_file.path, dest
32
- else
33
- IO.copy_stream(downloaded_file, dest)
34
- end
24
+ # open-uri will return a StringIO instead of a Tempfile if the filesize
25
+ # is less than 10 KB, so we patch this behaviour by converting it into
26
+ # a Tempfile.
27
+ if downloaded_file.is_a?(StringIO)
28
+ tempfile = Tempfile.new('open-uri', binmode: true)
29
+ IO.copy_stream(downloaded_file, tempfile.path)
30
+ downloaded_file = tempfile
31
+ FileUtils.mv downloaded_file.path, dest
32
+ else
33
+ IO.copy_stream(downloaded_file, dest)
34
+ end
35
35
 
36
- downloaded_file
36
+ downloaded_file
37
+ end
37
38
  end
38
39
  end
39
40
 
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Reaver
4
+ class MetaData
5
+ attr_accessor :info
6
+
7
+ def initialize(dirname, collection)
8
+ @dirname = dirname
9
+ @collection = collection
10
+ @file = "#{@dirname}/metadata.yml"
11
+ @info = { 'changed' => false, 'next' => Time.new }
12
+ end
13
+
14
+ def load_yaml
15
+ if File.exist? @file
16
+ #puts "loading metadata #{@file}..."
17
+ if RUBY_VERSION >= '3.0'
18
+ @info = YAML.load_file(@file, permitted_classes: [Time, Symbol])
19
+ else
20
+ @info = YAML.load_file(@file)
21
+ end
22
+ # puts @info.inspect
23
+ else
24
+ File.open(@file, 'w') { |f| YAML.dump(@info, f) }
25
+ end
26
+ end
27
+
28
+ def save_yaml
29
+ update_time
30
+
31
+ File.open(@file, 'w') { |f| YAML.dump(@info, f) }
32
+ end
33
+
34
+ private
35
+
36
+ def update_time
37
+ return unless @collection.tasks['things'].length >= 1
38
+
39
+ now = Time.new
40
+ n = @collection.tasks['time'] if @collection.tasks['time'].is_a?(Integer)
41
+ @info['next'] = now + n ||= now
42
+ @info['last_download'] = now
43
+ end
44
+ end
45
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Reaver
4
- VERSION = '0.4.0'
4
+ VERSION = '0.7.1'
5
5
  end
data/lib/reaver.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require_relative 'reaver/version'
4
4
  require_relative 'reaver/banner'
5
5
  require_relative 'reaver/download'
6
+ require_relative 'reaver/metadata'
6
7
  require_relative 'reaver/collection'
7
8
 
8
9
  require 'whirly'
@@ -25,29 +26,35 @@ module Reaver
25
26
  ambiguous_characters_width: 1
26
27
 
27
28
  def self.main
28
- FileUtils.mkdir_p(CACHE_DIR)
29
29
  FileUtils.mkdir_p(WORKDIR)
30
30
 
31
- puts ">> Search collections in #{WORKDIR}"
31
+ #puts ">> Search collections in #{WORKDIR}"
32
32
 
33
33
  Dir.glob("#{WORKDIR}/*.yml").each do |f|
34
- if File.exist? f
35
- collection = Collection.new(f)
36
- collection.load_yaml
37
-
38
- if collection.tasks
39
- next_download = collection.tasks['next'] ||= Time.new
40
- name = f.split('/').last
41
-
42
- if next_download < Time.new
43
- puts ' >> Download time for ' + name
44
- collection.launch
45
- else
46
- puts "Next download for #{name} >> #{next_download}"
47
- end
34
+ name = f.split('/').last
35
+ name = name.split('.').first
36
+ workdir = "#{CACHE_DIR}/#{name}"
37
+
38
+ FileUtils.mkdir_p(workdir)
39
+
40
+ collection = Collection.new(f)
41
+ collection.load_yaml
42
+
43
+ if collection.tasks
44
+ metadata = MetaData.new(workdir, collection)
45
+ metadata.load_yaml
46
+ next_download = metadata.info['next']
47
+
48
+ if next_download < Time.new
49
+ #puts ' >> Download time for ' + name
50
+ FileUtils.chdir(workdir)
51
+ #puts " > chdir #{workdir}"
52
+ collection.launch(metadata)
53
+ else
54
+ puts " > Next download > #{next_download}"
48
55
  end
49
56
 
50
- collection.save_yaml
57
+ metadata.save_yaml
51
58
  end
52
59
  end
53
60
  end
data/reaver.gemspec CHANGED
@@ -5,12 +5,13 @@ require_relative 'lib/reaver/version'
5
5
  # https://guides.rubygems.org/specification-reference/
6
6
  Gem::Specification.new do |s|
7
7
  s.name = 'reaver'
8
- s.summary = 'A tool to downloads and search for updates of things on the Net.'
8
+ s.summary = 'A tool to downloads and track updates of things on the Net.'
9
9
  s.version = Reaver::VERSION
10
10
  s.platform = Gem::Platform::RUBY
11
11
 
12
12
  s.description = <<-DESCRIPTION
13
- A tool to download and search for updates of things on the Net. Define collections in yaml with a delay in seconds and launch Reaver.
13
+ A tool that allows to download and track the latest version of stuff on the net.
14
+ Define your collections in .yml and launch Reaver to retrieve everything.
14
15
  DESCRIPTION
15
16
 
16
17
  s.email = 'szorfein@protonmail.com'
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reaver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - szorfein
@@ -36,7 +36,7 @@ cert_chain:
36
36
  aEJeKq4/BlIwMlXPe+W5C8zp2i8hgG1/OYbwbGE1p2iRi1NIK7G/HyRqQjOqJxzE
37
37
  LLknX69FN7/G
38
38
  -----END CERTIFICATE-----
39
- date: 2022-12-22 00:00:00.000000000 Z
39
+ date: 2022-12-28 00:00:00.000000000 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: whirly
@@ -66,8 +66,9 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.3'
69
- description: " A tool to download and search for updates of things on the Net.
70
- Define collections in yaml with a delay in seconds and launch Reaver.\n"
69
+ description: |2
70
+ A tool that allows to download and track the latest version of stuff on the net.
71
+ Define your collections in .yml and launch Reaver to retrieve everything.
71
72
  email: szorfein@protonmail.com
72
73
  executables:
73
74
  - reaver
@@ -83,6 +84,7 @@ files:
83
84
  - lib/reaver/banner.rb
84
85
  - lib/reaver/collection.rb
85
86
  - lib/reaver/download.rb
87
+ - lib/reaver/metadata.rb
86
88
  - lib/reaver/version.rb
87
89
  - reaver.gemspec
88
90
  homepage: https://github.com/szorfein/reaver
@@ -112,5 +114,5 @@ requirements: []
112
114
  rubygems_version: 3.3.23
113
115
  signing_key:
114
116
  specification_version: 4
115
- summary: A tool to downloads and search for updates of things on the Net.
117
+ summary: A tool to downloads and track updates of things on the Net.
116
118
  test_files: []
metadata.gz.sig CHANGED
Binary file