sdr-client 0.14.0 → 0.16.1
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/.rubocop_todo.yml +3 -3
- data/README.md +2 -0
- data/exe/sdr +8 -0
- data/lib/sdr_client/deposit.rb +9 -2
- data/lib/sdr_client/deposit/file_metadata_builder.rb +51 -0
- data/lib/sdr_client/deposit/file_metadata_builder_operations/md5.rb +17 -0
- data/lib/sdr_client/deposit/file_metadata_builder_operations/mime_type.rb +17 -0
- data/lib/sdr_client/deposit/file_metadata_builder_operations/sha1.rb +17 -0
- data/lib/sdr_client/deposit/metadata_builder.rb +21 -3
- data/lib/sdr_client/deposit/request.rb +13 -2
- data/lib/sdr_client/deposit/upload_files.rb +1 -1
- data/lib/sdr_client/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6d44bbb8b087e0045328a2b8625654ad9f7eaadf7c968c5ee5402683dc04d26
|
4
|
+
data.tar.gz: 9808626f7cad4548ccce883253245c80fc18fac9cd14353dcb008cb8c1cf365a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e14bf4032db046e886a7ef02cc1183fab23806bf0b450527ad8e33f396d3cac1f2d254644e9f9e2179d38c04d200a4cdf09eb07515aabf0e8a7a2c7ad9367fd1
|
7
|
+
data.tar.gz: 39e311b8bb036dd2abff468086103be8e55516b1490d219c4c34e5b68b0c80322af47efd0dcc198ee11e3e24e484d7d206102f20e415ccfa171abd7d61d6fde5
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2020-
|
3
|
+
# on 2020-03-02 15:54:47 -0600 using RuboCop version 0.79.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -10,7 +10,7 @@
|
|
10
10
|
Metrics/AbcSize:
|
11
11
|
Max: 16
|
12
12
|
|
13
|
-
# Offense count:
|
13
|
+
# Offense count: 4
|
14
14
|
# Configuration parameters: CountComments, ExcludedMethods.
|
15
15
|
Metrics/MethodLength:
|
16
|
-
Max:
|
16
|
+
Max: 14
|
data/README.md
CHANGED
@@ -8,6 +8,8 @@
|
|
8
8
|
This is a CLI for interacting with the Stanford Digital Repository API.
|
9
9
|
The code for the SDR API server is at https://github.com/sul-dlss/sdr-api
|
10
10
|
|
11
|
+
This provides a way for consumers to easily and correctly deposit files to the SDR without requiring access to the `/dor` NFS mount or to use Hydrus. A primary design goal was for this to have as few dependencies as possible so that it can be easily distributed by `gem install sdr-client` and then it can be used as a CLI.
|
12
|
+
|
11
13
|
## Install
|
12
14
|
|
13
15
|
`gem install sdr-client`
|
data/exe/sdr
CHANGED
@@ -70,6 +70,14 @@ subcommands = {
|
|
70
70
|
options[:source_id] = source_id
|
71
71
|
end
|
72
72
|
|
73
|
+
opts.on('--copyright COPYRIGHT', 'The copyright statement') do |copyright|
|
74
|
+
options[:copyright] = copyright
|
75
|
+
end
|
76
|
+
|
77
|
+
opts.on('--use-statement STATEMENT', 'The use and reproduction statement') do |use_statement|
|
78
|
+
options[:use_statement] = use_statement
|
79
|
+
end
|
80
|
+
|
73
81
|
opts.on('--viewing-direction DIRECTION', 'The viewing direction (if a book). ' \
|
74
82
|
'Either "left-to-right" or "right-to-left"') do |viewing_direction|
|
75
83
|
options[:viewing_direction] = viewing_direction if %w[left-to-right right-to-left].include?(viewing_direction)
|
data/lib/sdr_client/deposit.rb
CHANGED
@@ -5,12 +5,15 @@ require 'logger'
|
|
5
5
|
module SdrClient
|
6
6
|
# The namespace for the "deposit" command
|
7
7
|
module Deposit
|
8
|
+
BOOK_TYPE = 'http://cocina.sul.stanford.edu/models/book.jsonld'
|
8
9
|
# rubocop:disable Metrics/ParameterLists
|
9
10
|
# rubocop:disable Metrics/MethodLength
|
10
11
|
def self.run(label: nil,
|
11
|
-
type:
|
12
|
+
type: BOOK_TYPE,
|
12
13
|
viewing_direction: nil,
|
13
14
|
access: 'dark',
|
15
|
+
use_statement: nil,
|
16
|
+
copyright: nil,
|
14
17
|
apo:,
|
15
18
|
collection: nil,
|
16
19
|
catkey: nil,
|
@@ -24,17 +27,20 @@ module SdrClient
|
|
24
27
|
logger: Logger.new(STDOUT))
|
25
28
|
token = Credentials.read
|
26
29
|
|
30
|
+
augmented_metadata = FileMetadataBuilder.build(files: files, files_metadata: files_metadata)
|
27
31
|
metadata = Request.new(label: label,
|
28
32
|
type: type,
|
29
33
|
access: access,
|
30
34
|
apo: apo,
|
35
|
+
use_statement: use_statement,
|
36
|
+
copyright: copyright,
|
31
37
|
collection: collection,
|
32
38
|
source_id: source_id,
|
33
39
|
catkey: catkey,
|
34
40
|
embargo_release_date: embargo_release_date,
|
35
41
|
embargo_access: embargo_access,
|
36
42
|
viewing_direction: viewing_direction,
|
37
|
-
files_metadata:
|
43
|
+
files_metadata: augmented_metadata)
|
38
44
|
Process.new(metadata: metadata, url: url, token: token, files: files,
|
39
45
|
grouping_strategy: grouping_strategy, logger: logger).run
|
40
46
|
end
|
@@ -48,6 +54,7 @@ require 'sdr_client/deposit/matching_file_grouping_strategy'
|
|
48
54
|
require 'sdr_client/deposit/files/direct_upload_request'
|
49
55
|
require 'sdr_client/deposit/files/direct_upload_response'
|
50
56
|
require 'sdr_client/deposit/file'
|
57
|
+
require 'sdr_client/deposit/file_metadata_builder'
|
51
58
|
require 'sdr_client/deposit/file_set'
|
52
59
|
require 'sdr_client/deposit/request'
|
53
60
|
require 'sdr_client/deposit/upload_files'
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sdr_client/deposit/file_metadata_builder_operations/mime_type'
|
4
|
+
require 'sdr_client/deposit/file_metadata_builder_operations/md5'
|
5
|
+
require 'sdr_client/deposit/file_metadata_builder_operations/sha1'
|
6
|
+
|
7
|
+
module SdrClient
|
8
|
+
module Deposit
|
9
|
+
# Build basic metadata for files, iterating over a series of operations
|
10
|
+
# The available options are here: https://github.com/sul-dlss/sdr-client/blob/v0.8.1/lib/sdr_client/deposit/file.rb#L8-L10
|
11
|
+
class FileMetadataBuilder
|
12
|
+
OPERATIONS = [
|
13
|
+
FileMetadataBuilderOperations::MimeType,
|
14
|
+
FileMetadataBuilderOperations::MD5,
|
15
|
+
FileMetadataBuilderOperations::SHA1
|
16
|
+
].freeze
|
17
|
+
private_constant :OPERATIONS
|
18
|
+
|
19
|
+
# @param (see #initialize)
|
20
|
+
# @return (see #build)
|
21
|
+
def self.build(files:, files_metadata:)
|
22
|
+
new(files: files, files_metadata: files_metadata.dup).build
|
23
|
+
end
|
24
|
+
|
25
|
+
# @param [Array<String>] files the list of files for which to generate metadata
|
26
|
+
def initialize(files:, files_metadata:)
|
27
|
+
@files = files
|
28
|
+
@files_metadata = files_metadata
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [Hash<String, Hash<String, String>>]
|
32
|
+
def build
|
33
|
+
files.each do |file_path|
|
34
|
+
file_key = ::File.basename(file_path)
|
35
|
+
OPERATIONS.each do |operation|
|
36
|
+
result = operation.for(file_path: file_path)
|
37
|
+
next if result.nil?
|
38
|
+
|
39
|
+
files_metadata[file_key] ||= {}
|
40
|
+
files_metadata[file_key][operation::NAME] = result
|
41
|
+
end
|
42
|
+
end
|
43
|
+
files_metadata
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
attr_reader :files, :files_metadata
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'digest'
|
4
|
+
|
5
|
+
module SdrClient
|
6
|
+
module Deposit
|
7
|
+
module FileMetadataBuilderOperations
|
8
|
+
# MD5 for this file.
|
9
|
+
class MD5
|
10
|
+
NAME = 'md5'
|
11
|
+
def self.for(file_path:, **)
|
12
|
+
Digest::MD5.file(file_path).hexdigest
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'digest'
|
4
|
+
|
5
|
+
module SdrClient
|
6
|
+
module Deposit
|
7
|
+
module FileMetadataBuilderOperations
|
8
|
+
# Mime-type for this file.
|
9
|
+
class MimeType
|
10
|
+
NAME = 'mime_type'
|
11
|
+
def self.for(file_path:, **)
|
12
|
+
`file --mime-type -b #{file_path}`.chomp
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'digest'
|
4
|
+
|
5
|
+
module SdrClient
|
6
|
+
module Deposit
|
7
|
+
module FileMetadataBuilderOperations
|
8
|
+
# SHA1 for this file.
|
9
|
+
class SHA1
|
10
|
+
NAME = 'sha1'
|
11
|
+
def self.for(file_path:, **)
|
12
|
+
Digest::SHA1.file(file_path).hexdigest
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -16,6 +16,8 @@ module SdrClient
|
|
16
16
|
@grouping_strategy = grouping_strategy
|
17
17
|
end
|
18
18
|
|
19
|
+
# @param [UploadFiles] upload_responses the uploaded file information
|
20
|
+
# @return [Request] the metadata with fileset information added in.
|
19
21
|
def with_uploads(upload_responses)
|
20
22
|
file_sets = build_filesets(uploads: upload_responses)
|
21
23
|
metadata.with_file_sets(file_sets)
|
@@ -30,9 +32,25 @@ module SdrClient
|
|
30
32
|
def build_filesets(uploads:)
|
31
33
|
grouped_uploads = grouping_strategy.run(uploads: uploads)
|
32
34
|
grouped_uploads.map.with_index(1) do |upload_group, i|
|
33
|
-
|
34
|
-
|
35
|
-
|
35
|
+
FileSet.new(uploads: upload_group,
|
36
|
+
uploads_metadata: metadata_group(upload_group),
|
37
|
+
label: label(i))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def label(index)
|
42
|
+
case metadata.type
|
43
|
+
when BOOK_TYPE
|
44
|
+
"Page #{index}"
|
45
|
+
else
|
46
|
+
"Object #{index}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Get the metadata for the files belonging to a fileset
|
51
|
+
def metadata_group(upload_group)
|
52
|
+
upload_group.each_with_object({}) do |upload, obj|
|
53
|
+
obj[upload.filename] = metadata.for(upload.filename)
|
36
54
|
end
|
37
55
|
end
|
38
56
|
end
|
@@ -14,6 +14,8 @@ module SdrClient
|
|
14
14
|
# rubocop:disable Metrics/ParameterLists
|
15
15
|
def initialize(label: nil,
|
16
16
|
access: 'dark',
|
17
|
+
use_statement: nil,
|
18
|
+
copyright: nil,
|
17
19
|
apo:,
|
18
20
|
collection: nil,
|
19
21
|
source_id:,
|
@@ -32,6 +34,8 @@ module SdrClient
|
|
32
34
|
@embargo_release_date = embargo_release_date
|
33
35
|
@embargo_access = embargo_access
|
34
36
|
@access = access
|
37
|
+
@use_statement = use_statement
|
38
|
+
@copyright = copyright
|
35
39
|
@apo = apo
|
36
40
|
@file_sets = file_sets
|
37
41
|
@files_metadata = files_metadata
|
@@ -57,11 +61,13 @@ module SdrClient
|
|
57
61
|
access: access,
|
58
62
|
apo: apo,
|
59
63
|
collection: collection,
|
64
|
+
copyright: copyright,
|
60
65
|
source_id: source_id,
|
61
66
|
catkey: catkey,
|
62
67
|
embargo_release_date: embargo_release_date,
|
63
68
|
embargo_access: embargo_access,
|
64
69
|
type: type,
|
70
|
+
use_statement: use_statement,
|
65
71
|
viewing_direction: viewing_direction,
|
66
72
|
file_sets: file_sets,
|
67
73
|
files_metadata: files_metadata)
|
@@ -73,11 +79,13 @@ module SdrClient
|
|
73
79
|
files_metadata.fetch(filename, {})
|
74
80
|
end
|
75
81
|
|
82
|
+
attr_reader :type
|
83
|
+
|
76
84
|
private
|
77
85
|
|
78
86
|
attr_reader :access, :label, :file_sets, :source_id, :catkey, :apo, :collection,
|
79
|
-
:
|
80
|
-
:viewing_direction
|
87
|
+
:files_metadata, :embargo_release_date, :embargo_access,
|
88
|
+
:viewing_direction, :use_statement, :copyright
|
81
89
|
|
82
90
|
def administrative
|
83
91
|
{
|
@@ -101,6 +109,9 @@ module SdrClient
|
|
101
109
|
|
102
110
|
def access_struct
|
103
111
|
{ access: access }.tap do |json|
|
112
|
+
json[:useAndReproductionStatement] = use_statement if use_statement
|
113
|
+
json[:copyright] = copyright if copyright
|
114
|
+
|
104
115
|
if embargo_release_date
|
105
116
|
json[:embargo] = {
|
106
117
|
releaseDate: embargo_release_date.strftime('%FT%T%:z'),
|
@@ -35,7 +35,7 @@ module SdrClient
|
|
35
35
|
file_name = ::File.basename(path)
|
36
36
|
obj[path] = Files::DirectUploadRequest.from_file(path,
|
37
37
|
file_name: file_name,
|
38
|
-
content_type: metadata.for(file_name)[
|
38
|
+
content_type: metadata.for(file_name)['mime_type'])
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
data/lib/sdr_client/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sdr-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.16.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Coyne
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-monads
|
@@ -164,6 +164,10 @@ files:
|
|
164
164
|
- lib/sdr_client/credentials.rb
|
165
165
|
- lib/sdr_client/deposit.rb
|
166
166
|
- lib/sdr_client/deposit/file.rb
|
167
|
+
- lib/sdr_client/deposit/file_metadata_builder.rb
|
168
|
+
- lib/sdr_client/deposit/file_metadata_builder_operations/md5.rb
|
169
|
+
- lib/sdr_client/deposit/file_metadata_builder_operations/mime_type.rb
|
170
|
+
- lib/sdr_client/deposit/file_metadata_builder_operations/sha1.rb
|
167
171
|
- lib/sdr_client/deposit/file_set.rb
|
168
172
|
- lib/sdr_client/deposit/files/direct_upload_request.rb
|
169
173
|
- lib/sdr_client/deposit/files/direct_upload_response.rb
|