duracloud-client 0.7.2 → 0.8.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
  SHA1:
3
- metadata.gz: 434249b9d6736f7d391be4fc5189270a542f59e0
4
- data.tar.gz: 4af488c84ba6a92a239c971577c6cd5384c5c5a7
3
+ metadata.gz: 935b71b6483353f2dee2f6919df2844e31f51ba7
4
+ data.tar.gz: 369ec0668fbc416e23978241668a983e2bd92caa
5
5
  SHA512:
6
- metadata.gz: 3fb21e2fd338b9273b5afafb5cfe1394f4052232bc12619d6a98f549e383c576a9371e046a3a43212fa6d9596f7c9c36e52a8a5c8355dd3b4c1183970dc4184f
7
- data.tar.gz: 79cd8060222f7a4e7fc2fd0b9485d05f690900d2e1afb28bf6159ec1fedca56a3089c99cd2d60c88832cb8361ea362d7027d6081ea4f682191cdc3807a79d02b
6
+ metadata.gz: 6f8717da6c2ef7515e7bf791456d923c6156a445c541a3a5c21bd7b8d73730881ba4bd681ffc7539ca5717c9b2b25a887cd6de50107ad5c4149c4806aed553d4
7
+ data.tar.gz: 351a64019bdea2b4426d9288df4ac5c7f7fa166dfe89ee25d3cecd14930a8c20ae71f01a29a34a1d9118431eb8df1d173e72d055b583b5359639e5d30ec6dbca
data/README.md CHANGED
@@ -103,6 +103,12 @@ D, [2016-04-29T12:15:12.593075 #28275] DEBUG -- : Duracloud::Client HEAD https:/
103
103
 
104
104
  A `Duracloud::NotFoundError` exception is raised if the space does not exist.
105
105
 
106
+ NOTE: When the object count in a space exceeds 1000, Duracloud returns "1000+" as the count. Ruby's integer coercion `to_i`
107
+ turns that string into the integer 1000. Getting an exact count above 1000 requires (on the client side) enumerating the content_ids
108
+ (below, fixed in v0.7.2 when count is >= 1000) which can take a long time for a space with a lot of content items,
109
+ since a maxiumum of 1000 ids can be retrived at one time. If an up-to-the-minute
110
+ count is not required, the storage report for the space (not yet implemented in this library) shows an exact count on a daily basis.
111
+
106
112
  #### Enumerate the content IDs of the space
107
113
 
108
114
  ```
@@ -322,7 +328,8 @@ D, [2016-05-19T15:39:33.538448 #29974] DEBUG -- : Duracloud::Client GET https://
322
328
 
323
329
  *New in version 0.6.0*
324
330
 
325
- The `bin/` directory of the gem now includes an executable `duracloud`. Use `-h/--help` to display usage. If the gem was installed with `bundler` you may need to run `bundle exec bin/duracloud`.
331
+ The `bin/` directory of the gem now includes an executable `duracloud`. Use `-h/--help` to display usage.
332
+ If the gem was installed with `bundler` you may need to run `bundle exec bin/duracloud`.
326
333
 
327
334
  ## Versioning
328
335
 
data/bin/duracloud CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'duracloud'
4
4
 
5
- Duracloud::Command.call(*ARGV)
5
+ Duracloud::CLI.call(*ARGV)
data/lib/duracloud.rb CHANGED
@@ -7,8 +7,7 @@ module Duracloud
7
7
  autoload :BitIntegrityReport, "duracloud/bit_integrity_report"
8
8
  autoload :ChunkedContent, "duracloud/chunked_content"
9
9
  autoload :Client, "duracloud/client"
10
- autoload :Command, "duracloud/command"
11
- autoload :Commands, "duracloud/commands"
10
+ autoload :CLI, "duracloud/cli"
12
11
  autoload :Configuration, "duracloud/configuration"
13
12
  autoload :Connection, "duracloud/connection"
14
13
  autoload :Content, "duracloud/content"
@@ -2,23 +2,34 @@ require 'optparse'
2
2
  require 'active_model'
3
3
 
4
4
  module Duracloud
5
- class Command
5
+ class CLI
6
6
  include ActiveModel::Model
7
- include Commands
8
7
 
9
- COMMANDS = Commands.public_instance_methods.map(&:to_s)
10
- USAGE = "Usage: duracloud [#{COMMANDS.join('|')}] [options]"
11
- HELP = "Type 'duracloud --help' for usage."
8
+ COMMANDS = %w( sync validate manifest properties )
9
+
10
+ USAGE = <<-EOS
11
+ Usage: duracloud [COMMAND] [options]
12
+
13
+ Commands:
14
+ #{COMMANDS.sort.join("\n ")}
15
+
16
+ Options:
17
+ EOS
18
+ HELP = "Type 'duracloud -h/--help' for usage."
12
19
 
13
20
  attr_accessor :command, :user, :password, :host, :port,
14
21
  :space_id, :store_id, :content_id,
15
22
  :content_type, :md5,
16
- :content_dir, :format,
23
+ :content_dir, :format, :infile,
17
24
  :logging
18
25
 
19
- def self.error!(reason)
20
- STDERR.puts reason
21
- STDERR.puts HELP
26
+ validates_presence_of :space_id, message: "-s/--space-id option is required."
27
+
28
+ def self.error!(exception)
29
+ $stderr.puts exception.message
30
+ if [ CommandError, OptionParser::ParseError ].include?(exception.class)
31
+ $stderr.puts HELP
32
+ end
22
33
  exit(false)
23
34
  end
24
35
 
@@ -88,27 +99,47 @@ module Duracloud
88
99
  "Local content directory") do |v|
89
100
  options[:content_dir] = v
90
101
  end
102
+
103
+ opts.on("-f", "--infile FILE",
104
+ "Input file") do |v|
105
+ options[:infile] = v
106
+ end
91
107
  end
92
108
 
93
109
  command = args.shift if COMMANDS.include?(args.first)
94
110
  parser.parse!(args)
95
111
 
96
- new(options).execute(command)
97
- rescue CommandError, OptionParser::ParseError => e
98
- error!(e.message)
112
+ cli = new(options)
113
+ if cli.invalid?
114
+ message = cli.errors.map { |k, v| "ERROR: #{v}" }.join("\n")
115
+ raise CommandError, message
116
+ end
117
+ cli.execute(command)
118
+ rescue => e
119
+ error!(e)
99
120
  end
100
121
 
101
122
  def execute(command)
102
- unless COMMANDS.include?(command)
103
- raise CommandError, "Invalid command: #{command}."
104
- end
105
- begin
106
- configure_client
107
- send(command)
108
- rescue Error => e
109
- STDERR.puts e.message
110
- exit(false)
111
- end
123
+ configure_client
124
+ send(command).call(self)
125
+ end
126
+
127
+ protected
128
+
129
+ def sync
130
+ Commands::Sync
131
+ end
132
+
133
+ def validate
134
+ Commands::Validate
135
+ end
136
+
137
+ def manifest
138
+ Commands::DownloadManifest
139
+ end
140
+
141
+ def properties
142
+ Commands::GetProperties
112
143
  end
113
144
 
114
145
  private
@@ -126,3 +157,5 @@ module Duracloud
126
157
 
127
158
  end
128
159
  end
160
+
161
+ Dir[File.expand_path("../commands/*.rb", __FILE__)].each { |m| require m }
@@ -0,0 +1,11 @@
1
+ require 'delegate'
2
+
3
+ module Duracloud::Commands
4
+ class Command < SimpleDelegator
5
+
6
+ def self.call(command)
7
+ new(command).call
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ require_relative "command"
2
+
3
+ module Duracloud::Commands
4
+ class DownloadManifest < Command
5
+
6
+ def call
7
+ Duracloud::Manifest.download(space_id, store_id, format: format) do |chunk|
8
+ print chunk
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,27 @@
1
+ require_relative "command"
2
+
3
+ module Duracloud::Commands
4
+ class GetProperties < Command
5
+
6
+ def call
7
+ proplist = content_id ? content_properties : space_properties
8
+ puts proplist
9
+ end
10
+
11
+ private
12
+
13
+ def content_properties
14
+ content = Duracloud::Content.find(space_id: space_id, store_id: store_id, content_id: content_id, md5: md5)
15
+ proplist = content.properties.map { |k, v| "#{k}: #{v}" }
16
+ proplist << "MD5: #{content.md5}"
17
+ proplist << "Size: #{content.size} (#{content.human_size})"
18
+ proplist << "Chunked?: #{content.chunked?}"
19
+ end
20
+
21
+ def space_properties
22
+ space = Duracloud::Space.find(space_id, store_id)
23
+ space.properties.map { |k, v| "#{k}: #{v}" }
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,18 @@
1
+ require_relative 'command'
2
+
3
+ module Duracloud::Commands
4
+ class Sync < Command
5
+
6
+ def call
7
+ if infile
8
+ File.open(infile, "rb") do |f|
9
+ self.content_id ||= infile # XXX relativize to cwd?
10
+ Duracloud::Content.create(space_id: space_id, store_id: store_id, content_id: content_id, md5: md5, body: f)
11
+ end
12
+ else
13
+ Duracloud::Content.create(space_id: space_id, store_id: store_id, content_id: content_id, md5: md5, body: $stdin)
14
+ end
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ require_relative "command"
2
+
3
+ module Duracloud::Commands
4
+ class Validate < Command
5
+
6
+ def call
7
+ Duracloud::SyncValidation.call(space_id: space_id, store_id: store_id, content_dir: content_dir)
8
+ end
9
+
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Duracloud
2
- VERSION = "0.7.2"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -0,0 +1,43 @@
1
+ module Duracloud
2
+ RSpec.describe CLI do
3
+
4
+ subject { described_class.new(**opts) }
5
+
6
+ describe "properties" do
7
+ let(:opts) { {space_id: "foo", content_id: "bar"} }
8
+ let(:command) { "properties" }
9
+ specify {
10
+ expect(Commands::GetProperties).to receive(:call).with(subject) { nil }
11
+ subject.execute(command)
12
+ }
13
+ end
14
+
15
+ describe "sync" do
16
+ let(:opts) { {space_id: "foo", content_id: "bar", infile: "foo/bar"} }
17
+ let(:command) { "sync" }
18
+ specify {
19
+ expect(Commands::Sync).to receive(:call).with(subject) { nil }
20
+ subject.execute(command)
21
+ }
22
+ end
23
+
24
+ describe "validate" do
25
+ let(:opts) { {space_id: "foo", content_dir: "/tmp"} }
26
+ let(:command) { "validate" }
27
+ specify {
28
+ expect(Commands::Validate).to receive(:call).with(subject) { nil }
29
+ subject.execute(command)
30
+ }
31
+ end
32
+
33
+ describe "manifest" do
34
+ let(:opts) { {space_id: "foo"} }
35
+ let(:command) { "manifest" }
36
+ specify {
37
+ expect(Commands::DownloadManifest).to receive(:call).with(subject) { nil }
38
+ subject.execute(command)
39
+ }
40
+ end
41
+
42
+ end
43
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duracloud-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Chandek-Stark
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-25 00:00:00.000000000 Z
11
+ date: 2017-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -167,9 +167,13 @@ files:
167
167
  - lib/duracloud/audit_log.rb
168
168
  - lib/duracloud/bit_integrity_report.rb
169
169
  - lib/duracloud/chunked_content.rb
170
+ - lib/duracloud/cli.rb
170
171
  - lib/duracloud/client.rb
171
- - lib/duracloud/command.rb
172
- - lib/duracloud/commands.rb
172
+ - lib/duracloud/commands/command.rb
173
+ - lib/duracloud/commands/download_manifest.rb
174
+ - lib/duracloud/commands/get_properties.rb
175
+ - lib/duracloud/commands/sync.rb
176
+ - lib/duracloud/commands/validate.rb
173
177
  - lib/duracloud/configuration.rb
174
178
  - lib/duracloud/connection.rb
175
179
  - lib/duracloud/content.rb
@@ -197,6 +201,7 @@ files:
197
201
  - spec/support/shared_examples_for_tsv.rb
198
202
  - spec/unit/audit_log_spec.rb
199
203
  - spec/unit/bit_integrity_report_spec.rb
204
+ - spec/unit/cli_spec.rb
200
205
  - spec/unit/client_spec.rb
201
206
  - spec/unit/content_manifest_spec.rb
202
207
  - spec/unit/content_spec.rb
@@ -239,6 +244,7 @@ test_files:
239
244
  - spec/support/shared_examples_for_tsv.rb
240
245
  - spec/unit/audit_log_spec.rb
241
246
  - spec/unit/bit_integrity_report_spec.rb
247
+ - spec/unit/cli_spec.rb
242
248
  - spec/unit/client_spec.rb
243
249
  - spec/unit/content_manifest_spec.rb
244
250
  - spec/unit/content_spec.rb
@@ -1,35 +0,0 @@
1
- module Duracloud
2
- module Commands
3
-
4
- def validate
5
- SyncValidation.call(space_id: space_id, store_id: store_id, content_dir: content_dir)
6
- end
7
-
8
- def manifest
9
- Manifest.download(space_id, store_id, format: format) do |chunk|
10
- print chunk
11
- end
12
- end
13
-
14
- def properties
15
- proplist = content_id ? content_properties : space_properties
16
- STDOUT.puts proplist
17
- end
18
-
19
- private
20
-
21
- def content_properties
22
- content = Content.find(space_id: space_id, store_id: store_id, content_id: content_id, md5: md5)
23
- proplist = content.properties.map { |k, v| "#{k}: #{v}" }
24
- proplist << "MD5: #{content.md5}"
25
- proplist << "Size: #{content.size} (#{content.human_size})"
26
- proplist << "Chunked?: #{content.chunked?}"
27
- end
28
-
29
- def space_properties
30
- space = Space.find(space_id, store_id)
31
- space.properties.map { |k, v| "#{k}: #{v}" }
32
- end
33
-
34
- end
35
- end