libroute 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9d093523558122cc8e521e21c316f93bf3289e1a
4
+ data.tar.gz: 7b7989390d2ae25b6afc9297904bae9447dac209
5
+ SHA512:
6
+ metadata.gz: eba54ff35cefb2409f9979d72ef9eaf2e16f6a4632faf78449e3ff72587ef681c7df35efe8c04a25a319fe16993b34b5131929ffd9091fc19d770567382d4c5f
7
+ data.tar.gz: 733c25332d5d443eeccc855a31355405a84d656e6a2cc1dade50e05ed7c38743ec21d19a67481b51c9c9c3e088647bc97cb011bfd5f1809ec062f233482e8f45
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /*.gem
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in libroute.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 XS Research Ltd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # Libroute
2
+ {http://libroute.io Home}
3
+ {https://github.com/xsresearch/libroute-client-ruby GitHib}
4
+
5
+ Libroute is a generic client interface to libraries which standardises and simplifies the process of running third party libraries.
6
+
7
+ No need to battle with compile and build processes - install libroute once for a standard interface to third party libraries providing compute, scientific and mathematical functions.
8
+
9
+ Libroute offers several benefits over installing libraries locally:
10
+
11
+ * **Automated installation**
12
+
13
+ No manual compile, build or installation process, start using third party libraries within minutes.
14
+
15
+ * **Efficient processing**
16
+
17
+ Interact with the library in its native language with a common, straightforward interface.
18
+
19
+ * **Cross-platform capability**
20
+
21
+ Make calls to the library using standard TCP sockets from any platform, anywhere.
22
+
23
+ #### Quick start tutorial
24
+
25
+ Visit the {http://libroute.io/getting-started getting started} page for a 5 minute tutorial on using libroute.
26
+
27
+ ## Installation
28
+
29
+ Add this line to your application's Gemfile:
30
+
31
+ ```ruby
32
+ gem 'libroute'
33
+ ```
34
+
35
+ And then execute:
36
+
37
+ $ bundle
38
+
39
+ Or install it yourself as:
40
+
41
+ $ gem install libroute
42
+
43
+ Note: Docker is required to use libroute. This can be installed depending on your operating system using either of the following:
44
+
45
+ $ apt-get install docker
46
+ $ yum install docker
47
+
48
+ ## Libroute Client Usage
49
+
50
+ Libroute is installed on the command line. The full range of options can be obtained by running the command:
51
+
52
+ $ libroute --help
53
+
54
+ Running libroute consists of 3 steps
55
+
56
+ 1. Downloading the library onto your local machine
57
+ 2. Building and installing the library (an automated process)
58
+ 3. Running the library using the libroute command
59
+
60
+ ### Downloading the library
61
+
62
+ First download and extract the library to a local directory. See the {http://libroute.io/libraries libroute libraries} page for instructions on how to download the currently supported libraries.
63
+
64
+ If the library you wish to use is not supported, see the section on 'Adding support for additional libraries' below.
65
+
66
+ ### Building and installing the library
67
+
68
+ To build a library called mylib which has been downloaded to /home/user/mylib, use the command:
69
+
70
+ $ libroute -l MYLIB -b /home/user/mylib
71
+
72
+ The library will be built and installed. This process can take several minutes after which the library will be ready for use.
73
+
74
+ ### Running the library
75
+
76
+ The installed library can be run either from the command line or directly from Ruby.
77
+
78
+ #### From the command line
79
+
80
+ To run a library called mylib with parameters param1 and param2 with values value1 and value2 correspondingly, use the command:
81
+
82
+ $ libroute -l mylib -p "param1=value1,param2=value2"
83
+
84
+ #### From Ruby
85
+
86
+ If necessary, require that the gem is loaded using:
87
+
88
+ ```ruby
89
+ require 'libroute'
90
+ ```
91
+
92
+ The following example shows how to launch a library called mylib with parameters param1 and param2 equal to value1 and value2:
93
+
94
+ ```ruby
95
+ l = Libroute.exec('mylib', {'param1'=>'value1','param2'=>'value2'})
96
+ ```
97
+
98
+ The return value is a Hash object with keys and values set. Check each library interface implementation for details on the return values.
99
+
100
+
101
+ ### Supporting additional libraries
102
+
103
+ Support for additional libraries can be added by implementing the libroute-component interface.
104
+
105
+ See the libroute-component gem for more information on how to do this.
106
+
107
+ ## Contributing
108
+
109
+ Bug reports and pull requests are welcome on GitHub at https://github.com/xsresearch/libroute-ruby-client.
110
+
111
+ ## License
112
+
113
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
114
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "libroute/component"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/libroute ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'libroute'
4
+
5
+
6
+ options = Libroute.parse(ARGV)
7
+
8
+ if options.library.empty?
9
+ puts "Error: No LIBRARY specified"
10
+ exit 1
11
+ end
12
+
13
+ if !options.build.empty?
14
+ puts "Building #{options.library} library... (todo)"
15
+ Libroute.build(options)
16
+ exit 0
17
+ end
18
+
19
+ puts "Running #{options.library} library... (todo)"
20
+
21
+ params = options.params.split(",")
22
+ paramshash = Hash.new
23
+ params.each do |p|
24
+ key,val = p.split("=",2)
25
+ paramshash[key]=val
26
+ end
27
+
28
+ result = Libroute.exec(options.library, paramshash)
29
+
30
+ result.each do |k,v|
31
+ puts k + ": " + v
32
+ end
33
+
@@ -0,0 +1,64 @@
1
+ module Libroute
2
+
3
+ class << self
4
+
5
+ def build(options)
6
+ puts "Building #{options.library} from directory #{options.build}"
7
+ im = Docker::Image.build_from_dir(options.build) do |v|
8
+ if (log = JSON.parse(v)) && log.has_key?("stream")
9
+ puts log["stream"]
10
+ end
11
+ end
12
+ im.tag('repo' => 'libroute_image-'+options.library)
13
+ end
14
+
15
+ def exec(library, params)
16
+
17
+ # Check if existing container running
18
+ c = Docker::Container.all(all: true).select{|c| c.info['Names'][0].eql?('/libroute_instance-' + library)}
19
+
20
+ if c.length == 1
21
+ # Check status
22
+ if c[0].info['State'].eql?('exited')
23
+ # Kill and request start
24
+ c[0].delete
25
+ c = []
26
+ end
27
+ end
28
+
29
+ if c.length == 0
30
+
31
+ # Launch container from image
32
+ image = Docker::Image.all.select{|x| x.info['RepoTags'][0].split(':')[0].include?('libroute_image-' + library)}.first
33
+ c = Docker::Container.create('Image' => image.id, 'name' => 'libroute_instance-' + library, 'Tty' => true)
34
+ c.start
35
+
36
+ # Wait for container to start
37
+ sleep 1
38
+
39
+ else
40
+ c = c[0]
41
+ end
42
+
43
+ ip_address = c.json['NetworkSettings']['IPAddress']
44
+
45
+ # Send and retrieve data from container
46
+ #s = TCPSocket.new(ip_address, 2000)
47
+ #s.write(Marshal.dump(params))
48
+ #s.close_write
49
+ #outp = Marshal.load(s.read)
50
+ #s.close
51
+
52
+ s = TCPSocket.new(ip_address, 2000)
53
+ s.write(params.to_bson.to_s)
54
+ s.close_write
55
+ outp = Hash.from_bson(BSON::ByteBuffer.new(s.read))
56
+ s.close
57
+
58
+ # Return response
59
+ return outp
60
+
61
+ end
62
+ end
63
+
64
+ end
@@ -0,0 +1,71 @@
1
+ module Libroute
2
+
3
+ class << self
4
+
5
+ CODES = %w[iso-2022-jp shift_jis euc-jp utf8 binary]
6
+ CODE_ALIASES = { "jis" => "iso-2022-jp", "sjis" => "shift_jis" }
7
+
8
+ #
9
+ # Return a structure describing the options.
10
+ #
11
+ def parse(args)
12
+ # The options specified on the command line will be collected in *options*.
13
+ # We set default values here.
14
+ options = OpenStruct.new
15
+ options.library = []
16
+ options.build = []
17
+ options.params = []
18
+ options.showhelp = false
19
+
20
+ opt_parser = OptionParser.new do |opts|
21
+ opts.banner = "Usage: libroute.rb [options]"
22
+
23
+ opts.separator ""
24
+ opts.separator "Required:"
25
+
26
+ # Mandatory argument.
27
+ #opts.on("-r", "--require LIBRARY",
28
+ # "Require the LIBRARY before executing your script") do |lib|
29
+ # options.library << lib
30
+ #end
31
+
32
+ opts.on("-l", "--lib LIBRARY","Name of the LIBRARY") do |lib|
33
+ options.library = lib
34
+ end
35
+
36
+ opts.separator ""
37
+ opts.separator "Options:"
38
+
39
+ opts.on("-b","--build DIR","Build the library from the specified directory") do |o|
40
+ options.build = o
41
+ end
42
+
43
+ opts.on("-p","--params PARAMETERS","Parameters","Comma separated list of parameters") do |p|
44
+ options.params = p
45
+ end
46
+
47
+ opts.on_tail("-h", "--help", "Show command options","Show library options (-l LIBRARY)") do |h|
48
+ if options.library.empty?
49
+ puts opts
50
+ exit
51
+ else
52
+ options.showhelp = h
53
+ end
54
+ end
55
+
56
+ # Another typical switch to print the version.
57
+ opts.on_tail("--version", "Show version") do
58
+ puts Libroute::VERSION
59
+ exit
60
+ end
61
+ end
62
+
63
+ opt_parser.parse!(args)
64
+ options
65
+
66
+ end # parse()
67
+
68
+ end
69
+
70
+ end
71
+
@@ -0,0 +1,3 @@
1
+ module Libroute
2
+ VERSION = "0.1.0"
3
+ end
data/lib/libroute.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'docker'
2
+ require 'optparse'
3
+ require 'optparse/time'
4
+ require 'ostruct'
5
+ require 'pp'
6
+ require 'bson'
7
+
8
+ require 'libroute/librouteexec'
9
+ require 'libroute/librouteparse'
10
+ require 'libroute/version'
11
+
12
+ module Libroute
13
+
14
+ class << self
15
+
16
+ end
17
+
18
+ end
data/libroute.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'libroute/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "libroute"
8
+ spec.version = Libroute::VERSION
9
+ spec.authors = ["David Lisk (XS Research Ltd)"]
10
+ spec.email = ["david.lisk@xsresearch.co.uk"]
11
+
12
+ spec.summary = %q{Libroute standardises and simplifies the process of running third party libraries}
13
+ spec.homepage = "http://libroute.io"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "docker-api", "~> 1.31"
22
+ spec.add_runtime_dependency "bson", "~> 4.1"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.12"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "minitest", "~> 5.0"
27
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: libroute
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Lisk (XS Research Ltd)
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: docker-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.31'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.31'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bson
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ description:
84
+ email:
85
+ - david.lisk@xsresearch.co.uk
86
+ executables:
87
+ - libroute
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - exe/libroute
100
+ - lib/libroute.rb
101
+ - lib/libroute/librouteexec.rb
102
+ - lib/libroute/librouteparse.rb
103
+ - lib/libroute/version.rb
104
+ - libroute.gemspec
105
+ homepage: http://libroute.io
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.6.6
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Libroute standardises and simplifies the process of running third party libraries
129
+ test_files: []