opener-core 2.4.0 → 2.5.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 +5 -5
- data/README.md +0 -4
- data/lib/opener/core.rb +0 -2
- data/lib/opener/core/version.rb +3 -1
- data/opener-core.gemspec +0 -1
- metadata +8 -24
- data/lib/opener/core/resource_switcher.rb +0 -136
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 5e21e457a99dcc64b76d2840230b2b3e7265e6f4af85e85a34cf3d4a906ac492
|
|
4
|
+
data.tar.gz: 887abb3273444413eaa746a8a113f4ebd64e20d936dfe742f5049758153aa688
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0ad70d679479832376301b1c8ce03a18bd5c8bc5149728ec9e3788e4321da05fd61784497f81bf7dc68846ecc6d791452d96fedbb57901c84e2a4c706488d67c
|
|
7
|
+
data.tar.gz: 5060d1a70ecf85d08e3608046be6e01ed439ea5eaff689b28601cd210cf6110aa090173c9a94bd5dbc1f2fb80c1538b47966fac47b05234f44a2b7c33a355134
|
data/README.md
CHANGED
|
@@ -10,10 +10,6 @@ A Gem that provides commonly re-used functionality for the various OpeNER Gems.
|
|
|
10
10
|
| Rubinius | >= 2.2 | >= 2.3.0 |
|
|
11
11
|
| JRuby | >= 1.7 | >= 1.7.16 |
|
|
12
12
|
|
|
13
|
-
For the resource switcher you'll need to have
|
|
14
|
-
[libarchive](http://www.libarchive.org/) installed as it's used for unpacking
|
|
15
|
-
archives.
|
|
16
|
-
|
|
17
13
|
## Installation
|
|
18
14
|
|
|
19
15
|
You can install opener-core as a Gem by running:
|
data/lib/opener/core.rb
CHANGED
|
@@ -5,10 +5,8 @@ require 'fileutils'
|
|
|
5
5
|
|
|
6
6
|
require 'slop'
|
|
7
7
|
require 'httpclient'
|
|
8
|
-
require 'archive'
|
|
9
8
|
|
|
10
9
|
require_relative 'core/version'
|
|
11
|
-
require_relative 'core/resource_switcher'
|
|
12
10
|
require_relative 'core/syslog'
|
|
13
11
|
require_relative 'core/language_error'
|
|
14
12
|
require_relative 'core/language_code'
|
data/lib/opener/core/version.rb
CHANGED
data/opener-core.gemspec
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: opener-core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- development@olery.com
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-01-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: slop
|
|
@@ -38,20 +38,6 @@ dependencies:
|
|
|
38
38
|
- - ">="
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '0'
|
|
41
|
-
- !ruby/object:Gem::Dependency
|
|
42
|
-
name: archive
|
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
|
44
|
-
requirements:
|
|
45
|
-
- - ">="
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
47
|
-
version: '0'
|
|
48
|
-
type: :runtime
|
|
49
|
-
prerelease: false
|
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
-
requirements:
|
|
52
|
-
- - ">="
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
version: '0'
|
|
55
41
|
- !ruby/object:Gem::Dependency
|
|
56
42
|
name: bundler
|
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -95,7 +81,7 @@ dependencies:
|
|
|
95
81
|
- !ruby/object:Gem::Version
|
|
96
82
|
version: '0'
|
|
97
83
|
description: Gem that contains some low level generic functions for all OpeNER components.
|
|
98
|
-
email:
|
|
84
|
+
email:
|
|
99
85
|
executables: []
|
|
100
86
|
extensions: []
|
|
101
87
|
extra_rdoc_files: []
|
|
@@ -105,7 +91,6 @@ files:
|
|
|
105
91
|
- lib/opener/core.rb
|
|
106
92
|
- lib/opener/core/language_code.rb
|
|
107
93
|
- lib/opener/core/language_error.rb
|
|
108
|
-
- lib/opener/core/resource_switcher.rb
|
|
109
94
|
- lib/opener/core/syslog.rb
|
|
110
95
|
- lib/opener/core/version.rb
|
|
111
96
|
- opener-core.gemspec
|
|
@@ -113,7 +98,7 @@ homepage: http://opener-project.github.com
|
|
|
113
98
|
licenses:
|
|
114
99
|
- Apache 2.0
|
|
115
100
|
metadata: {}
|
|
116
|
-
post_install_message:
|
|
101
|
+
post_install_message:
|
|
117
102
|
rdoc_options: []
|
|
118
103
|
require_paths:
|
|
119
104
|
- lib
|
|
@@ -128,10 +113,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
128
113
|
- !ruby/object:Gem::Version
|
|
129
114
|
version: '0'
|
|
130
115
|
requirements: []
|
|
131
|
-
rubyforge_project:
|
|
132
|
-
rubygems_version: 2.
|
|
133
|
-
signing_key:
|
|
116
|
+
rubyforge_project:
|
|
117
|
+
rubygems_version: 2.7.8
|
|
118
|
+
signing_key:
|
|
134
119
|
specification_version: 4
|
|
135
120
|
summary: Gem that contains some low level generic functions for all OpeNER components.
|
|
136
121
|
test_files: []
|
|
137
|
-
has_rdoc:
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
module Opener
|
|
2
|
-
module Core
|
|
3
|
-
##
|
|
4
|
-
# Class for downloading and extracting external resources such as
|
|
5
|
-
# models/lexicons.
|
|
6
|
-
#
|
|
7
|
-
# Resource paths specified using the `--resource-path` option are stored in
|
|
8
|
-
# the environment variable `RESOURCE_PATH`. This variable should be used in
|
|
9
|
-
# webservice/daemon code instead of said code re-parsing CLI arguments.
|
|
10
|
-
#
|
|
11
|
-
# @!attribute [r] http
|
|
12
|
-
# @return [HTTPClient]
|
|
13
|
-
#
|
|
14
|
-
class ResourceSwitcher
|
|
15
|
-
attr_reader :http
|
|
16
|
-
|
|
17
|
-
def initialize
|
|
18
|
-
@http = HTTPClient.new
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
##
|
|
22
|
-
# Adds extra CLI options to the given Slop instance.
|
|
23
|
-
#
|
|
24
|
-
# @param [Slop] slop
|
|
25
|
-
#
|
|
26
|
-
def bind(slop)
|
|
27
|
-
slop.separator "\nResource Options:\n"
|
|
28
|
-
|
|
29
|
-
slop.on :'resource-url=',
|
|
30
|
-
'URL pointing to a .zip/.tar.gz file to download',
|
|
31
|
-
:as => String
|
|
32
|
-
|
|
33
|
-
slop.on :'resource-path=',
|
|
34
|
-
'Path where the resources should be saved',
|
|
35
|
-
:as => String
|
|
36
|
-
|
|
37
|
-
# Hijack Slop's run block so we can inject our own code before it. This
|
|
38
|
-
# is quite grotesque, but sadly the only way.
|
|
39
|
-
old_runner = slop.instance_variable_get(:@runner)
|
|
40
|
-
|
|
41
|
-
slop.run do |opts, args|
|
|
42
|
-
if opts[:'resource-path'] and opts[:'resource-url']
|
|
43
|
-
download_and_extract(opts[:'resource-url'], opts[:'resource-path'])
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# Allow daemons/webservices to use the path without having to re-parse
|
|
47
|
-
# CLI options.
|
|
48
|
-
ENV['RESOURCE_PATH'] = opts[:'resource-path']
|
|
49
|
-
|
|
50
|
-
old_runner.call(opts, args)
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
##
|
|
55
|
-
# @param [String] url
|
|
56
|
-
# @param [String] path
|
|
57
|
-
#
|
|
58
|
-
def download_and_extract(url, path)
|
|
59
|
-
filename = filename_from_url(url)
|
|
60
|
-
temp_path = File.join(path, filename)
|
|
61
|
-
|
|
62
|
-
create_directory(path)
|
|
63
|
-
|
|
64
|
-
download(url, temp_path)
|
|
65
|
-
|
|
66
|
-
Archive.extract(temp_path, path)
|
|
67
|
-
|
|
68
|
-
remove_file(temp_path)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
##
|
|
72
|
-
# Downloads the given file.
|
|
73
|
-
#
|
|
74
|
-
# @param [String] url
|
|
75
|
-
# @param [String] path
|
|
76
|
-
#
|
|
77
|
-
def download(url, path)
|
|
78
|
-
File.open(path, 'w', :encoding => Encoding::BINARY) do |handle|
|
|
79
|
-
http.get(url) do |chunk|
|
|
80
|
-
handle.write(chunk)
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
##
|
|
86
|
-
# Returns the filename of the file located at `url`.
|
|
87
|
-
#
|
|
88
|
-
# @param [String] url
|
|
89
|
-
# @return [String]
|
|
90
|
-
#
|
|
91
|
-
def filename_from_url(url)
|
|
92
|
-
headers = get_headers(url)
|
|
93
|
-
|
|
94
|
-
unless headers['Content-Disposition']
|
|
95
|
-
raise "The URL #{url.inspect} did not return a Content-Disposition " \
|
|
96
|
-
"header. This header is required to figure out the filename"
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
matches = headers['Content-Disposition'].match(/filename=(.+)/)
|
|
100
|
-
|
|
101
|
-
if !matches or !matches[1]
|
|
102
|
-
raise 'No filename could be found in the Content-Disposition header'
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
return matches[1]
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
##
|
|
109
|
-
# Creates the path. This method mainly exists to make testing a bit
|
|
110
|
-
# easier.
|
|
111
|
-
#
|
|
112
|
-
# @param [String] path
|
|
113
|
-
#
|
|
114
|
-
def create_directory(path)
|
|
115
|
-
FileUtils.mkdir_p(path)
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
##
|
|
119
|
-
# Removes the given file, mainly exists to make testing easier.
|
|
120
|
-
#
|
|
121
|
-
# @param [String] path
|
|
122
|
-
#
|
|
123
|
-
def remove_file(path)
|
|
124
|
-
File.unlink(path)
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
##
|
|
128
|
-
# @param [String] url
|
|
129
|
-
# @return [Hash]
|
|
130
|
-
#
|
|
131
|
-
def get_headers(url)
|
|
132
|
-
return http.head(url).headers
|
|
133
|
-
end
|
|
134
|
-
end # ResourceSwitcher
|
|
135
|
-
end # Core
|
|
136
|
-
end # Opener
|