Class: OSwitch

Inherits:
Object
  • Object
show all
Includes:
OS, Timeout
Defined in:
lib/oswitch.rb,
lib/oswitch/os.rb,
lib/oswitch/pkg.rb,
lib/oswitch/image.rb,
lib/oswitch/os/linux.rb,
lib/oswitch/os/darwin.rb,
lib/oswitch/exceptions.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: OS Classes: ENODKR, ENOPKG, Image

Constant Summary collapse

DOTDIR =
File.expand_path('~/.oswitch')
PREFIX =
File.expand_path('../..', File.dirname(__FILE__))

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from OS

#cwd, #home, #shell, #username

Constructor Details

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

Returns a new instance of OSwitch.



42
43
44
45
46
47
48
# File 'lib/oswitch.rb', line 42

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.



50
51
52
# File 'lib/oswitch.rb', line 50

def cntname
  @cntname
end

#commandObject (readonly)

Returns the value of attribute command.



50
51
52
# File 'lib/oswitch.rb', line 50

def command
  @command
end

#imgnameObject (readonly)

Returns the value of attribute imgname.



50
51
52
# File 'lib/oswitch.rb', line 50

def imgname
  @imgname
end

#packageObject (readonly)

Returns the value of attribute package.



50
51
52
# File 'lib/oswitch.rb', line 50

def package
  @package
end

Class Method Details

.packagesObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/oswitch.rb', line 29

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



52
53
54
55
56
57
# File 'lib/oswitch.rb', line 52

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