doi_extractor 1.0.5 → 1.0.16
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/bin/doi_extractor +1 -1
- data/config/deploy.rb +1 -1
- data/doi_extractor.gemspec +2 -1
- data/lib/doi_extractor.rb +2 -0
- data/lib/doi_extractor/command.rb +6 -1
- data/lib/doi_extractor/download_location.rb +1 -1
- data/lib/doi_extractor/ipums_client.rb +2 -0
- data/lib/doi_extractor/ipums_uri_builder.rb +6 -0
- data/lib/doi_extractor/logger.rb +16 -0
- data/lib/doi_extractor/options.rb +10 -3
- data/lib/doi_extractor/status_command.rb +1 -0
- data/lib/doi_extractor/version.rb +1 -1
- data/spec/unit/download_location_spec.rb +5 -0
- data/spec/unit/ipums_client_spec.rb +2 -2
- data/spec/unit/options_spec.rb +15 -2
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 116f301792c96628d4f5517bd4f7efc864634341
|
4
|
+
data.tar.gz: d44bd7726b32645b97c1f6e929ad2e067ae028f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fd0b1509417dd41a767c8b5ff8549f7232c06e7907af4531a8076401e0f75716f8706eb0372789412d9887d9932b9fc455f5f9589d0d03a636ddfcc8a14974f
|
7
|
+
data.tar.gz: f53dabd2f7125f14976657de55d977c4a6b5ab13f50dca19c1fa838bded20bc814d91a1dcbcdf9853ae53fd7304150ae0c76649576318b6e326e9e4053a72ac1
|
data/bin/doi_extractor
CHANGED
data/config/deploy.rb
CHANGED
@@ -10,7 +10,7 @@ set :deploy_to, '/pkg/ipums/programming/doi_extractor'
|
|
10
10
|
# Default value for :linked_files is []
|
11
11
|
# append :linked_files, "config/database.yml", "config/secrets.yml"
|
12
12
|
# Default value for linked_dirs is []
|
13
|
-
|
13
|
+
set :linked_dirs, %w{vendor/bundle log}
|
14
14
|
|
15
15
|
set :app_version, DoiExtractor::VERSION
|
16
16
|
set :jruby_path, -> { "/pkg/mpctools/jruby/current" }
|
data/doi_extractor.gemspec
CHANGED
@@ -17,9 +17,10 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.require_paths = ["lib"]
|
18
18
|
|
19
19
|
spec.add_runtime_dependency 'json'
|
20
|
+
spec.add_runtime_dependency 'jruby-openssl', '>= 0.9.18' if RUBY_PLATFORM =~ /java/
|
20
21
|
|
21
22
|
spec.add_development_dependency "bundler", "> 1.10"
|
22
|
-
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rake", "< 12.3"
|
23
24
|
spec.add_development_dependency "public_suffix", "1.4.6" # Locked to this version because of jruby in 1.9 mode
|
24
25
|
spec.add_development_dependency "rspec", "~> 3.5.0"
|
25
26
|
spec.add_development_dependency "ci_reporter_rspec", "~> 1.0.0"
|
data/lib/doi_extractor.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'erb'
|
2
2
|
require 'fileutils'
|
3
3
|
require 'json'
|
4
|
+
require 'logger'
|
4
5
|
require 'net/https'
|
5
6
|
require 'optparse'
|
6
7
|
require 'optparse/uri'
|
@@ -20,6 +21,7 @@ require 'doi_extractor/errors'
|
|
20
21
|
require 'doi_extractor/download_command'
|
21
22
|
require 'doi_extractor/ipums_client'
|
22
23
|
require 'doi_extractor/ipums_uri_builder'
|
24
|
+
require 'doi_extractor/logger'
|
23
25
|
require 'doi_extractor/options'
|
24
26
|
require 'doi_extractor/secrets'
|
25
27
|
require 'doi_extractor/status_command'
|
@@ -17,26 +17,31 @@ module DoiExtractor
|
|
17
17
|
end
|
18
18
|
|
19
19
|
attr_reader :options, :start_time
|
20
|
-
attr_accessor :std_out, :user_input_callback
|
20
|
+
attr_accessor :std_out, :user_input_callback, :log
|
21
21
|
|
22
22
|
def initialize(options, std_out = STDOUT, input_callback = nil)
|
23
23
|
@options = options
|
24
24
|
@std_out = std_out
|
25
25
|
@user_input_callback = input_callback || default_input_callback
|
26
|
+
@log = Logger::get_log
|
26
27
|
end
|
27
28
|
|
28
29
|
def execute
|
29
30
|
begin
|
30
31
|
@start_time = Time.now
|
31
32
|
cmd = self.class.name.split('::').last.sub('Command', '')
|
33
|
+
log.info "Starting #{cmd} Command:\n #{options.to_hash}"
|
32
34
|
say("starting #{cmd} Command", true)
|
33
35
|
say("api: #{options.api_uri}", true)
|
34
36
|
say("path: #{options.download_base_path}", true)
|
35
37
|
_execute
|
38
|
+
log.info "Finished #{cmd} Command"
|
36
39
|
say("Finished in #{(Time.now - @start_time).round(2)} seconds", true)
|
37
40
|
rescue CommandFailError => e
|
41
|
+
log.error "#{e.class}: #{e.message}\n #{e.backtrace.join("\n ")}"
|
38
42
|
raise e
|
39
43
|
rescue => e
|
44
|
+
log.error "#{e.class}: #{e.message}\n #{e.backtrace.join("\n ")}"
|
40
45
|
raise CommandFailError.new('An Unexpected Error Has Occurred', e)
|
41
46
|
end
|
42
47
|
end
|
@@ -11,11 +11,17 @@ module DoiExtractor
|
|
11
11
|
highered: IpumsConfig.new('highered.ipums.org'),
|
12
12
|
nhis: IpumsConfig.new('nhis.ipums.org'),
|
13
13
|
ipumsi: IpumsConfig.new('international.ipums.org', nil, 'international'),
|
14
|
+
meps: IpumsConfig.new('meps.ipums.org'),
|
14
15
|
mtus: IpumsConfig.new('mtusdata.org', 'www.'),
|
15
16
|
napp: IpumsConfig.new('nappdata.org', 'www.'),
|
17
|
+
pma: IpumsConfig.new('pma.ipums.org'),
|
16
18
|
usa: IpumsConfig.new('usa.ipums.org'),
|
17
19
|
}
|
18
20
|
|
21
|
+
def self.project_list
|
22
|
+
CONFIGS.keys.map(&:to_s)
|
23
|
+
end
|
24
|
+
|
19
25
|
attr_reader :project, :environment, :config
|
20
26
|
|
21
27
|
def initialize(project, environment)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module DoiExtractor
|
2
|
+
module Logger
|
3
|
+
def self.get_log
|
4
|
+
pkg_path = '/pkg/ipums/programming/doi_extractor/current/log'
|
5
|
+
local_path = File.expand_path(File.dirname(__FILE__) + '/../../log')
|
6
|
+
|
7
|
+
if Dir::exists?(pkg_path) && File.writable?(pkg_path)
|
8
|
+
log_path = pkg_path
|
9
|
+
else
|
10
|
+
log_path = local_path
|
11
|
+
end
|
12
|
+
|
13
|
+
::Logger.new("#{log_path}/doi_extractor.log", 15, 1073741824)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module DoiExtractor
|
2
2
|
class Options
|
3
3
|
|
4
|
-
PROJECTS =
|
4
|
+
PROJECTS = IpumsUriBuilder::project_list
|
5
5
|
ENVIRONMENTS = %w(local demo internal staging live)
|
6
6
|
COMMANDS = %w(create download status cancel)
|
7
7
|
|
@@ -101,6 +101,10 @@ module DoiExtractor
|
|
101
101
|
errors.empty?
|
102
102
|
end
|
103
103
|
|
104
|
+
def to_hash
|
105
|
+
Hash[OPTIONS.map { |o| [o, self.send(o)] }].merge(errors: self.errors)
|
106
|
+
end
|
107
|
+
|
104
108
|
private
|
105
109
|
|
106
110
|
def calculate_api_uri
|
@@ -113,8 +117,11 @@ module DoiExtractor
|
|
113
117
|
|
114
118
|
def calculate_download_base_path
|
115
119
|
if project && environment
|
116
|
-
|
117
|
-
|
120
|
+
if environment == 'live'
|
121
|
+
"/pkg/ipums/preservationarchive/#{project}"
|
122
|
+
else
|
123
|
+
"/pkg/ipums/programming/doi_extractor/temp_archive/#{project}/#{environment}"
|
124
|
+
end
|
118
125
|
else
|
119
126
|
nil
|
120
127
|
end
|
@@ -50,6 +50,7 @@ module DoiExtractor
|
|
50
50
|
|
51
51
|
say("DOI Extract (ID: #{doi_extract.id})")
|
52
52
|
say("\tStatus: #{doi_extract.status}")
|
53
|
+
say("\tCreated: #{doi_extract.created_at}")
|
53
54
|
say("\tSubmitted: #{doi_extract.submit_date}")
|
54
55
|
say("\tFinished: #{doi_extract.finish_date}")
|
55
56
|
say("\tData Available: #{doi_extract.all_data_available}")
|
@@ -32,6 +32,11 @@ describe DoiExtractor::DownloadLocation do
|
|
32
32
|
expect(location.extract_request_path(extract)).to eq File.join(path, '1990a - US 1990 5%.tar.gz')
|
33
33
|
end
|
34
34
|
|
35
|
+
it 'handles slashes in sample names' do
|
36
|
+
extract.samples.first.long_description = 'US 1990 Urban/Rural'
|
37
|
+
expect(location.extract_request_path(extract)).to eq File.join(path, '1990a - US 1990 Urban_Rural.tar.gz')
|
38
|
+
end
|
39
|
+
|
35
40
|
it 'can create itself' do
|
36
41
|
expect(Dir.exist?(path)).to be_falsey
|
37
42
|
location.ensure!
|
@@ -13,9 +13,9 @@ describe DoiExtractor::IpumsClient do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'handles HTTP 500' do
|
16
|
-
stub_request(:get, '
|
16
|
+
stub_request(:get, 'https://localhost:3003/cps-action/api/extracts/v1/extract_request_groups/1').to_return(status: 500, body: '{"error": "bad stuff"}')
|
17
17
|
|
18
|
-
client = DoiExtractor::IpumsClient.new('
|
18
|
+
client = DoiExtractor::IpumsClient.new('https://localhost:3003/cps-action', 'user', 'pass')
|
19
19
|
|
20
20
|
expect { client.get_doi_extract(1) }.to raise_error(DoiExtractor::ApiError, /invalid/i)
|
21
21
|
end
|
data/spec/unit/options_spec.rb
CHANGED
@@ -57,11 +57,17 @@ describe DoiExtractor::Options do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
context 'when setting path values' do
|
60
|
-
let(:options) { DoiExtractor::Options.for_command('download', project: 'cps', environment: '
|
60
|
+
let(:options) { DoiExtractor::Options.for_command('download', project: 'cps', environment: 'internal', extract_group_id: 1) }
|
61
61
|
|
62
62
|
it 'defaults the base path' do
|
63
63
|
expect(options.valid?).to be_truthy
|
64
|
-
expect(options.download_base_path).to eq "/pkg/ipums/programming/doi_extractor/temp_archive/cps/
|
64
|
+
expect(options.download_base_path).to eq "/pkg/ipums/programming/doi_extractor/temp_archive/cps/internal"
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'defaults the base path for live' do
|
68
|
+
options.environment = 'live'
|
69
|
+
expect(options.valid?).to be_truthy
|
70
|
+
expect(options.download_base_path).to eq "/pkg/ipums/preservationarchive/cps"
|
65
71
|
end
|
66
72
|
|
67
73
|
it 'allows overriding the base path' do
|
@@ -83,4 +89,11 @@ describe DoiExtractor::Options do
|
|
83
89
|
expect(opts.api_password).to eq '1234'
|
84
90
|
end
|
85
91
|
|
92
|
+
it 'supports meps' do
|
93
|
+
opts = DoiExtractor::Options.for_command('download', project: 'meps', environment: 'internal', extract_group_id: 1)
|
94
|
+
opts.validate
|
95
|
+
expect(opts.valid?).to eq true
|
96
|
+
expect(opts.api_uri).to eq 'https://internal.meps.ipums.org/meps-action'
|
97
|
+
end
|
98
|
+
|
86
99
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: doi_extractor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Elbert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "<"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '12.3'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "<"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '12.3'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: public_suffix
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -163,6 +163,7 @@ files:
|
|
163
163
|
- lib/doi_extractor/errors.rb
|
164
164
|
- lib/doi_extractor/ipums_client.rb
|
165
165
|
- lib/doi_extractor/ipums_uri_builder.rb
|
166
|
+
- lib/doi_extractor/logger.rb
|
166
167
|
- lib/doi_extractor/old_ruby_patch.rb
|
167
168
|
- lib/doi_extractor/options.rb
|
168
169
|
- lib/doi_extractor/secrets.rb
|
@@ -231,7 +232,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
231
232
|
version: '0'
|
232
233
|
requirements: []
|
233
234
|
rubyforge_project:
|
234
|
-
rubygems_version: 2.6.
|
235
|
+
rubygems_version: 2.6.14
|
235
236
|
signing_key:
|
236
237
|
specification_version: 4
|
237
238
|
summary: Command line tool to package IPUMS DOI extracts
|