dl-core 0.1.0 → 0.3.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 +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +1 -0
- data/lib/dl/core/cli.rb +7 -1
- data/lib/dl/core/paper_folder.rb +78 -0
- data/lib/dl/core/version.rb +1 -1
- data/lib/dl/core.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 978dfcf1613c0608488a9799d314c3f3d54d454395d7ea04d27b65ad036138b9
|
|
4
|
+
data.tar.gz: 6be2a6ad35bb9a248ba3e9158a87706795c1439e432d7f4b0eb76b8ce8e7ec14
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: db271ab75843c8188d0f6bb8207f98b58a677605625d95ac680b0434edc69db1c87ee3a3e4c9361a313fc2cfcc368d5d1c4a734b1d7ca81d7ec8387f3db97da1
|
|
7
|
+
data.tar.gz: b60b5e4b659e8b1bcabda3f88ddf1ecd629a15c1516740a55349b35af32e2adcb5645621d9d969960c9e539c4f7864207ced004590f53f71ab989aa0c7c7ed14
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
## [0.3.0]
|
|
2
|
+
|
|
3
|
+
- Requires Ruby 4.0.10 or later.
|
|
4
|
+
- `DL::Core::CLI#default_rate_limit`: the seconds between requests when neither `--rate-limit` nor `<PREFIX>_RATE_LIMIT` is set. It defaults to 3. A gem whose source allows fewer requests overrides it (osf-dl uses 36).
|
|
5
|
+
|
|
6
|
+
## [0.2.0]
|
|
7
|
+
|
|
8
|
+
- `DL::Core::PaperFolder`, extracted from arxiv-dl and hal-dl: a paper's folder is flat while one version (v1) is archived and uses `v<N>/` folders once there are several; `unflatten!` moves a flat version into its `v<N>/` folder and calls `moved_into(destination)`, which a gem can override (arxiv-dl rewrites `html/` links there).
|
|
9
|
+
|
|
1
10
|
## [0.1.0]
|
|
2
11
|
|
|
3
12
|
First version, extracted from arxiv-dl 0.3.0 and jstor-dl 0.1.0.
|
data/README.md
CHANGED
|
@@ -10,6 +10,7 @@ Shared foundation for the `<site>-dl` gems that build offline archives: [arxiv-d
|
|
|
10
10
|
| `DL::Core::Error`, `DL::Core::HTTPError` | Base error for every gem; `HTTPError` for non-success responses (`status`, `url`) |
|
|
11
11
|
| `DL::Core::Author` | `name` and `affiliations` |
|
|
12
12
|
| `DL::Core::Slug` | Title → URL-safe slug, truncated at a word boundary |
|
|
13
|
+
| `DL::Core::PaperFolder` | A paper's folder: flat while one version is archived, `v<N>/` folders once there are several; override `moved_into` to fix up files moved one level deeper |
|
|
13
14
|
| `DL::Core::Sidecar::YAML`, `JSON` | `metadata.yaml` / `metadata.json` from any metadata `Data` object |
|
|
14
15
|
| `DL::Core::Sidecar::Markdown` | `metadata.md`: YAML frontmatter from the metadata, plus a body each gem writes |
|
|
15
16
|
| `DL::Core::CLI` | The shared command line: targets as args or `--input FILE\|-`, `-p`, `--rate-limit`, `-v`, `-q`, per-target errors, exit 1 on any failure |
|
data/lib/dl/core/cli.rb
CHANGED
|
@@ -12,6 +12,8 @@ module DL
|
|
|
12
12
|
# user_agent for requests, naming the gem
|
|
13
13
|
# identifier_for(target) parses one target; raises an Error subclass if invalid
|
|
14
14
|
# archive_for(identifier, root:, client:) an object whose #run archives it and returns its folder
|
|
15
|
+
#
|
|
16
|
+
# and can override default_rate_limit when its source allows fewer requests.
|
|
15
17
|
class CLI
|
|
16
18
|
def initialize argv, stderr: $stderr, stdin: $stdin, stdout: $stdout
|
|
17
19
|
@argv = argv
|
|
@@ -49,6 +51,10 @@ module DL
|
|
|
49
51
|
|
|
50
52
|
def client_for(rate_limit:, log:) = Client.new(user_agent:, rate_limit:, log:)
|
|
51
53
|
|
|
54
|
+
# seconds between requests when neither --rate-limit nor <PREFIX>_RATE_LIMIT is set.
|
|
55
|
+
# A gem whose source allows fewer requests overrides this.
|
|
56
|
+
def default_rate_limit = Client::DEFAULT_RATE_LIMIT
|
|
57
|
+
|
|
52
58
|
private
|
|
53
59
|
|
|
54
60
|
def usage
|
|
@@ -72,7 +78,7 @@ module DL
|
|
|
72
78
|
end
|
|
73
79
|
|
|
74
80
|
options[:path] ||= ENV["#{env_prefix}_DOWNLOAD_PATH"] || default_path
|
|
75
|
-
options[:rate_limit] ||= (ENV["#{env_prefix}_RATE_LIMIT"] ||
|
|
81
|
+
options[:rate_limit] ||= (ENV["#{env_prefix}_RATE_LIMIT"] || default_rate_limit).to_i
|
|
76
82
|
options
|
|
77
83
|
end
|
|
78
84
|
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
require 'date'
|
|
2
|
+
require 'fileutils'
|
|
3
|
+
require 'yaml'
|
|
4
|
+
|
|
5
|
+
module DL
|
|
6
|
+
module Core
|
|
7
|
+
# One paper's folder. A paper with a single archived version is kept flat
|
|
8
|
+
# (files directly in the folder); once a second version arrives, each
|
|
9
|
+
# version gets its own v<N>/ folder.
|
|
10
|
+
#
|
|
11
|
+
# A gem whose files need fixing after moving one level deeper (arxiv-dl's
|
|
12
|
+
# relative links in html/) subclasses this and overrides moved_into.
|
|
13
|
+
class PaperFolder
|
|
14
|
+
VERSION_FOLDER = /\Av\d+(\.partial)?\z/
|
|
15
|
+
|
|
16
|
+
attr_reader :path
|
|
17
|
+
|
|
18
|
+
def initialize path
|
|
19
|
+
@path = path
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def archived? version
|
|
23
|
+
Dir.exist? location_of(version)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def location_of version
|
|
27
|
+
return path if flat_version == version
|
|
28
|
+
|
|
29
|
+
version_path version
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# where a new download of `version` goes; call unflatten! first if the folder is flat
|
|
33
|
+
def destination_for version
|
|
34
|
+
return path if version == 1 && !versioned?
|
|
35
|
+
|
|
36
|
+
version_path version
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# moves the flat version into v<N>/ so another version can sit beside it
|
|
40
|
+
def unflatten!
|
|
41
|
+
return if flat_version.nil?
|
|
42
|
+
|
|
43
|
+
destination = version_path flat_version
|
|
44
|
+
FileUtils.mkdir_p destination
|
|
45
|
+
|
|
46
|
+
# metadata.yaml marks the folder as flat, so it moves last
|
|
47
|
+
children = Dir.children(path) - [File.basename(destination), metadata_filename]
|
|
48
|
+
children.each { FileUtils.mv File.join(path, it), destination }
|
|
49
|
+
moved_into destination
|
|
50
|
+
FileUtils.mv File.join(path, metadata_filename), destination
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# called after a flat version's files moved into `destination`, one level deeper
|
|
54
|
+
def moved_into(_destination) = nil
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
def flat_version
|
|
59
|
+
metadata_path = File.join path, metadata_filename
|
|
60
|
+
return unless File.exist? metadata_path
|
|
61
|
+
|
|
62
|
+
::YAML.safe_load_file(metadata_path, permitted_classes: [Date]).fetch 'version'
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def versioned?
|
|
66
|
+
Dir.exist?(path) && Dir.children(path).any? { VERSION_FOLDER.match? it }
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def version_path version
|
|
70
|
+
File.join path, "v#{version}"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def metadata_filename
|
|
74
|
+
Sidecar::YAML::FILENAME
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
data/lib/dl/core/version.rb
CHANGED
data/lib/dl/core.rb
CHANGED
|
@@ -3,6 +3,7 @@ require_relative 'core/cli'
|
|
|
3
3
|
require_relative 'core/client'
|
|
4
4
|
require_relative 'core/error' # before errors below that subclass Error
|
|
5
5
|
require_relative 'core/http_error' # after error
|
|
6
|
+
require_relative 'core/paper_folder'
|
|
6
7
|
require_relative 'core/sidecar/json'
|
|
7
8
|
require_relative 'core/sidecar/markdown'
|
|
8
9
|
require_relative 'core/sidecar/yaml'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dl-core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shane Becker
|
|
@@ -70,6 +70,7 @@ files:
|
|
|
70
70
|
- lib/dl/core/client.rb
|
|
71
71
|
- lib/dl/core/error.rb
|
|
72
72
|
- lib/dl/core/http_error.rb
|
|
73
|
+
- lib/dl/core/paper_folder.rb
|
|
73
74
|
- lib/dl/core/sidecar/json.rb
|
|
74
75
|
- lib/dl/core/sidecar/markdown.rb
|
|
75
76
|
- lib/dl/core/sidecar/yaml.rb
|
|
@@ -93,14 +94,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
93
94
|
requirements:
|
|
94
95
|
- - ">="
|
|
95
96
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: 4.0.
|
|
97
|
+
version: 4.0.10
|
|
97
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
99
|
requirements:
|
|
99
100
|
- - ">="
|
|
100
101
|
- !ruby/object:Gem::Version
|
|
101
102
|
version: '0'
|
|
102
103
|
requirements: []
|
|
103
|
-
rubygems_version: 4.0.
|
|
104
|
+
rubygems_version: 4.0.20
|
|
104
105
|
specification_version: 4
|
|
105
106
|
summary: Shared foundation for the <site>-dl offline-archive gems (arxiv-dl, jstor-dl,
|
|
106
107
|
and more).
|