dl-core 0.1.0 → 0.2.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 +4 -0
- data/README.md +1 -0
- 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 +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '0344548899c858f4c63e4d2ac6e9b08ad7ce0e0546469357bbde4bd9520cb8ae'
|
|
4
|
+
data.tar.gz: 9a11d71acc23886b25970deb87ffebd940c5204606e46764c8463c69aedafef7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3e001006d0aef5ef9991e21771e581bcb4e575c7d7bb995cf958e359bb8e8087f4dbca9fb614a377ecab9c8e0476ce08ec1a0a2ca39a19be3b33abed6810e87a
|
|
7
|
+
data.tar.gz: c4dc9749d8a1c2b666fd1521b6efa0e3c8cdf60ba344f71dd476dfcbcbad50c8987850de98125de7ec686081225fc53a380e37224192edd1fc3e72a6059bf6e9
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
## [0.2.0]
|
|
2
|
+
|
|
3
|
+
- `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).
|
|
4
|
+
|
|
1
5
|
## [0.1.0]
|
|
2
6
|
|
|
3
7
|
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 |
|
|
@@ -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.2.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
|