Class: OSwitch

Inherits:
Object
  • Object
show all
Includes:
Timeout
Defined in:
lib/oswitch.rb

Overview

OSwitch leverages docker to provide access to complex Bioinformatics software (even Biolinux!) in just one command.

Images are built on the user’s system on demand and executed in a container. Containers are removed after execution.

Volumes from host OS are mounted in the container just the same, including home directory. USER, HOME, SHELL, and PWD are preserved.

Defined Under Namespace

Modules: Darwin, Linux Classes: ENODKR, ENOPKG, Image

Constant Summary collapse

DOTDIR =
File.expand_path('~/.oswitch')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(package, command = []) ⇒ OSwitch

Returns a new instance of OSwitch.



159
160
161
162
163
164
165
# File 'lib/oswitch.rb', line 159

def initialize(package, command = [])
  @package = package.strip
  @command = command.join(' ')
  @imgname = "oswitch_#{@package}"
  @cntname = "#{@package.gsub(%r{/|:}, '_')}-#{Process.pid}"
  exec
end

Instance Attribute Details

#cntnameObject (readonly)

Returns the value of attribute cntname.



167
168
169
# File 'lib/oswitch.rb', line 167

def cntname
  @cntname
end

#commandObject (readonly)

Returns the value of attribute command.



167
168
169
# File 'lib/oswitch.rb', line 167

def command
  @command
end

#imgnameObject (readonly)

Returns the value of attribute imgname.



167
168
169
# File 'lib/oswitch.rb', line 167

def imgname
  @imgname
end

#packageObject (readonly)

Returns the value of attribute package.



167
168
169
# File 'lib/oswitch.rb', line 167

def package
  @package
end

Class Method Details

.packagesObject



146
147
148
149
150
151
152
153
154
155
156
# File 'lib/oswitch.rb', line 146

def packages
  Dir["#{DOTDIR}/*"].map do |rep|
    pkgs = Dir["#{rep}/*"].select {|pkg| File.directory?(pkg)}
    pkgs = [rep] if pkgs.empty?
    pkgs
  end.
  flatten.
  map {|pkg|
    pkg.gsub("#{DOTDIR}/", '')
  }
end

Instance Method Details

#execObject



169
170
171
172
173
174
# File 'lib/oswitch.rb', line 169

def exec
  ping and build and switch
rescue ENODKR, ENOPKG => e
  puts e
  exit
end