reaver 0.4.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d4a124d2032645971e2084e688be989024bfc7deccaebb51c04742f85ebbd69
4
- data.tar.gz: 5d6f483932ebc078c182d054b329a45251c315856ec60084ae511c075773a2ba
3
+ metadata.gz: 0df9b0a453544115410d64b72a65ac9589e5ad3639d58d733409c21d33c0513d
4
+ data.tar.gz: c08d7470fcbd1bfdb84d381e30360076f0ec9bdcb842aa4ebb4c0a39e16618a5
5
5
  SHA512:
6
- metadata.gz: 4460f09f21e6e7816f50c24a1a2866a2e01de28f32cd8cb54b3600d8b13393bb6baf9bf05175c022b508119f82458c01115d6b8939ee02932c83f005eb8cfe92
7
- data.tar.gz: 1562641f8cd861fd7524e8445d9734eaef48d71a44bd66c012877562f0148094d8f049196f3d47e0c8092401290d63b4b798a3f5b57e471aa4e3674ea24a2f3d
6
+ metadata.gz: ebf121f3da646562cd05108de7dfa32151ba3e31d3e7126d9b78000294c30855231fb1941f728496cfd8fb74a7b0875c87e89c62da8a42d2c0d3142b35754731
7
+ data.tar.gz: fa25fbb70ae82e631deaa4dd925900fb31d8b03c310ddfbc2b825ac6931c36d590ec3f520cc13220610e1a34b3420050cb82671cffad61b9b9fa7831ff842deb
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,41 @@ 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}..."
17
+ puts ">> Loading #{@file}..."
16
18
  @tasks = YAML.load_file(@file, permitted_classes: [Time, Symbol])
17
19
  # puts @tasks.inspect
18
20
  rescue => error
19
21
  raise error, "loading YAML fail for #{@file}: #{error.message}"
20
22
  end
21
23
 
22
- def launch
24
+ def launch(metadata)
23
25
  return unless @tasks
24
26
 
25
27
  if @tasks['things'].length >= 1
26
- @tasks['things'].each { |t| Reaver.download(t['url'], t['name']) }
28
+ @tasks['things'].each do |t|
29
+ if File.exist? t['name']
30
+ old_hash = Digest::MD5.file t['name']
31
+ else
32
+ @changed = true
33
+ end
34
+
35
+ Reaver.download(t['url'], t['name'])
36
+ compare_hash(t['name'], old_hash) if old_hash
37
+
38
+ metadata.info['changed'] = @changed
39
+ end
27
40
  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
41
  end
37
42
 
38
43
  private
39
44
 
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
45
+ def compare_hash(filename, old_hash)
46
+ hash = Digest::MD5.file filename
47
+ @changed = true if old_hash.hexdigest != hash.hexdigest
47
48
  end
48
49
  end
49
50
  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,41 @@
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
+ @info = YAML.load_file(@file, permitted_classes: [Time, Symbol])
18
+ # puts @info.inspect
19
+ else
20
+ File.open(@file, 'w') { |f| YAML.dump(@info, f) }
21
+ end
22
+ end
23
+
24
+ def save_yaml
25
+ update_time
26
+
27
+ File.open(@file, 'w') { |f| YAML.dump(@info, f) }
28
+ end
29
+
30
+ private
31
+
32
+ def update_time
33
+ return unless @collection.tasks['things'].length >= 1
34
+
35
+ now = Time.new
36
+ n = @collection.tasks['time'] if @collection.tasks['time'].is_a?(Integer)
37
+ @info['next'] = now + n ||= now
38
+ @info['last_download'] = now
39
+ end
40
+ end
41
+ 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.0'
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.0
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-24 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