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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '092d2a2486613b1db9414d267cfccef66d4adc17'
4
- data.tar.gz: 36df18eeaba0c2999ef7d7b448fa83543f1787c2
3
+ metadata.gz: 116f301792c96628d4f5517bd4f7efc864634341
4
+ data.tar.gz: d44bd7726b32645b97c1f6e929ad2e067ae028f2
5
5
  SHA512:
6
- metadata.gz: 9022ebc38079cf1d779a006ca8a91aee2aab6f298245d2af300493a7653e4754be9e45df3d579e3374229c3991af24c9a41c7719eb451d9f10884cbcd5d8bdd1
7
- data.tar.gz: b46e08cd9ef16a96c4d54e140b87e1a752200bc2cad89f1ca88af54eb3a9b02ce2ff2428a6404c1f61db118a1d18d7969882159cc1a33c7cafff75171cb1dfea
6
+ metadata.gz: 7fd0b1509417dd41a767c8b5ff8549f7232c06e7907af4531a8076401e0f75716f8706eb0372789412d9887d9932b9fc455f5f9589d0d03a636ddfcc8a14974f
7
+ data.tar.gz: f53dabd2f7125f14976657de55d977c4a6b5ab13f50dca19c1fa838bded20bc814d91a1dcbcdf9853ae53fd7304150ae0c76649576318b6e326e9e4053a72ac1
data/bin/doi_extractor CHANGED
@@ -15,4 +15,4 @@ if parser.valid?
15
15
  else
16
16
  puts parser
17
17
  exit 1
18
- end
18
+ end
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
- # set :linked_dirs, %w{vendor/bundle}
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" }
@@ -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
@@ -79,7 +79,7 @@ module DoiExtractor
79
79
 
80
80
  def extract_request_name(er)
81
81
  s = er.samples.first
82
- [s.name, s.long_description].compact.join(' - ')
82
+ [s.name, s.long_description].compact.join(' - ').gsub('/', '_')
83
83
  end
84
84
 
85
85
  end
@@ -15,6 +15,8 @@ module DoiExtractor
15
15
  raise 'Invalid uri'
16
16
  end
17
17
 
18
+ raise("Invalid uri: #{uri}") unless @uri.is_a?(URI::HTTP)
19
+
18
20
  @username = username
19
21
  @password = password
20
22
  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 = %w(ahtus atus cps dhs highered nhis ipumsi mtus napp usa)
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
- # "/pkg/ipums/programming/#{project}/#{environment}"
117
- "/pkg/ipums/programming/doi_extractor/temp_archive/#{project}/#{environment}"
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}")
@@ -1,3 +1,3 @@
1
1
  module DoiExtractor
2
- VERSION = '1.0.5'
2
+ VERSION = '1.0.16'
3
3
  end
@@ -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, 'http://localhost:3003/cps-action/api/extracts/v1/extract_request_groups/1').to_return(status: 500, body: '{"error": "bad stuff"}')
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('http://localhost:3003/cps-action', 'user', 'pass')
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
@@ -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: 'live', extract_group_id: 1) }
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/live"
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.5
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: 2017-09-19 00:00:00.000000000 Z
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: '0'
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: '0'
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.11
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