opener-core 0.0.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 +15 -0
- data/README.md +29 -0
- data/lib/opener/core/opt_parser.rb +62 -0
- data/lib/opener/core/resource_switcher.rb +80 -0
- data/lib/opener/core/version.rb +5 -0
- data/lib/opener/core.rb +7 -0
- data/opener-core.gemspec +24 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YThlMjhjYzdhNWY2NWVhNTIwZTM3Mjg4ODc5N2U4YzU3ZTQwYTgwMQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NTNiY2JlNDVkN2FiNjg1NThmN2E4OWVlOGE0ZWNkZmJkYmNmZGE3NA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NmJkOTkyZDdhOTZhZmM3YWM4OGM3NTBkY2JhMDBkMWM1NzIzZGYyZDZhYzlk
|
10
|
+
MjQ2MDM0NjcxYmYxOTgyMTMzZDI1NTFkYjM4YzU3M2JjMjhiOWIwMTc1NDAy
|
11
|
+
ODc3ZjhiNWUwNDQ1MDdlNTAxMWY5OGQ5MjNkMjMwMjYyNDNlOTM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZjE2ZDZkNGNkZTJlYWRiYTEyYWJmMmRhMDNhZDcxZGQ1MDBiZGQxMTg0MmZm
|
14
|
+
NTVhZmZjNzNkNTgyMmQwN2IxOGE5Y2Q5NGQzYjVhMzdmMmRlNWNlYjA4MWM1
|
15
|
+
ZWY1MjU3ZWFkYTg2NWZjZjM0MGRmYWUyNmM0MzE4NTFjZDhiM2Q=
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Opener::Core
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'opener-core'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install opener-core
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/<my-github-username>/opener-core/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module Opener
|
4
|
+
module Core
|
5
|
+
class OptParser
|
6
|
+
attr_accessor :option_parser, :options
|
7
|
+
|
8
|
+
def initialize(&block)
|
9
|
+
@options = {}
|
10
|
+
@option_parser = construct_option_parser(options, &block)
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse(args)
|
14
|
+
process(:parse, args)
|
15
|
+
end
|
16
|
+
|
17
|
+
def parse!(args)
|
18
|
+
process(:parse!, args)
|
19
|
+
end
|
20
|
+
|
21
|
+
def pre_parse!(args)
|
22
|
+
delete_double_dash = false
|
23
|
+
process(:parse!, args, delete_double_dash)
|
24
|
+
end
|
25
|
+
|
26
|
+
def pre_parse(args)
|
27
|
+
delete_double_dash = false
|
28
|
+
process(:parse, args, delete_double_dash)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.parse(args)
|
32
|
+
new.parse(args)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.parse!(args)
|
36
|
+
new.parse!(args)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.pre_parse!(args)
|
40
|
+
new.pre_parse!(args)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.pre_parse(args)
|
44
|
+
new.pre_parse(args)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def process(call, args, delete_double_dash=true)
|
50
|
+
args.delete("--") if delete_double_dash
|
51
|
+
option_parser.send(call, args)
|
52
|
+
return options
|
53
|
+
end
|
54
|
+
|
55
|
+
def construct_option_parser(options, &block)
|
56
|
+
raise NotImplementedError
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
require 'uri'
|
3
|
+
require_relative 'opt_parser'
|
4
|
+
|
5
|
+
module Opener
|
6
|
+
module Core
|
7
|
+
class ResourceSwitcher
|
8
|
+
|
9
|
+
def bind(opts, options)
|
10
|
+
OptParser.bind(opts,options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def install(options)
|
14
|
+
Installer.new(options).install
|
15
|
+
end
|
16
|
+
|
17
|
+
class Installer
|
18
|
+
attr_reader :options
|
19
|
+
|
20
|
+
def initialize(options={})
|
21
|
+
@options = options
|
22
|
+
end
|
23
|
+
|
24
|
+
def install
|
25
|
+
path = options.fetch(:resource_path) { raise ArgumentError, "No resource-path given" }
|
26
|
+
if url = options[:resource_url]
|
27
|
+
download_and_unzip_resource(url,path)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def download_and_unzip_resource(url, path)
|
32
|
+
filename = download(url)
|
33
|
+
unzip(filename, path)
|
34
|
+
end
|
35
|
+
|
36
|
+
def download(url)
|
37
|
+
filename = get_filename_from_url(url)
|
38
|
+
destination = "/tmp/#{filename}"
|
39
|
+
`wget -N -O #{destination} #{url}`
|
40
|
+
|
41
|
+
return destination
|
42
|
+
end
|
43
|
+
|
44
|
+
def unzip(file, path)
|
45
|
+
extname = File.extname(file)
|
46
|
+
if extname == ".zip"
|
47
|
+
`unzip #{file} -o -d #{path}`
|
48
|
+
else
|
49
|
+
`tar -zxvf #{file} --directory #{path}`
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_filename_from_url(url)
|
54
|
+
URI.parse(url).path[1..-1].split("/").last
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class OptParser < Opener::Core::OptParser
|
59
|
+
attr_accessor :option_parser, :options
|
60
|
+
|
61
|
+
def self.bind(opts, options)
|
62
|
+
opts.on("--resource-path PATH", "Path where the resources are located. In combination with the --resource-url option this is also the path where the resources will be installed") do |v|
|
63
|
+
options[:resource_path] = v
|
64
|
+
end
|
65
|
+
|
66
|
+
opts.on("--resource-url URL", "URL where a zip file containing all resources can be downloaded") do |v|
|
67
|
+
options[:resource_url] = v
|
68
|
+
end
|
69
|
+
end
|
70
|
+
private
|
71
|
+
|
72
|
+
def construct_option_parser(options, &block)
|
73
|
+
OptionParser.new do |opts|
|
74
|
+
self.class.bind(opts, options)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/lib/opener/core.rb
ADDED
data/opener-core.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require File.expand_path('../lib/opener/core/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "opener-core"
|
6
|
+
spec.version = Opener::Core::VERSION
|
7
|
+
spec.authors = ["development@olery.com"]
|
8
|
+
spec.summary = %q{Gem that contains some low lever generic functions for all OpeNER components.}
|
9
|
+
spec.description = spec.summary
|
10
|
+
spec.homepage = "http://opener-project.github.com"
|
11
|
+
spec.license = "Apachev2"
|
12
|
+
|
13
|
+
spec.files = Dir.glob([
|
14
|
+
'lib/**/*',
|
15
|
+
'*.gemspec',
|
16
|
+
'README.md'
|
17
|
+
]).select { |file| File.file?(file) }
|
18
|
+
|
19
|
+
spec.executables = Dir.glob('bin/*').map { |file| File.basename(file) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: opener-core
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- development@olery.com
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Gem that contains some low lever generic functions for all OpeNER components.
|
42
|
+
email:
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- lib/opener/core/opt_parser.rb
|
48
|
+
- lib/opener/core/resource_switcher.rb
|
49
|
+
- lib/opener/core/version.rb
|
50
|
+
- lib/opener/core.rb
|
51
|
+
- opener-core.gemspec
|
52
|
+
- README.md
|
53
|
+
homepage: http://opener-project.github.com
|
54
|
+
licenses:
|
55
|
+
- Apachev2
|
56
|
+
metadata: {}
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 2.1.11
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: Gem that contains some low lever generic functions for all OpeNER components.
|
77
|
+
test_files: []
|