Module: VMC::Micro

Defined in:
lib/cli.rb,
lib/vmc/micro.rb,
lib/vmc/micro/vmrun.rb

Defined Under Namespace

Modules: Switcher Classes: VMrun

Class Method Summary collapse

Class Method Details

.config_file(file) ⇒ Object



4
5
6
# File 'lib/vmc/micro.rb', line 4

def config_file(file)
  File.join(File.dirname(__FILE__), '..', '..', 'config', 'micro', file)
end

.escape_path(path) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/vmc/micro.rb', line 8

def escape_path(path)
  path = File.expand_path(path)
  if RUBY_PLATFORM =~ /mingw|mswin32|cygwin/
    if path.include?(' ')
      return '"' + path + '"'
    else
      return path
    end
  else
    return path.gsub(' ', '\ ')
  end
end

.locate_file(file, directory, search_paths) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/vmc/micro.rb', line 21

def locate_file(file, directory, search_paths)
  search_paths.each do |path|
    expanded_path = File.expand_path(path)
    if File.exists?(expanded_path)
      Find.find(expanded_path) do |current|
        if File.directory?(current) && current.include?(directory)
          full_path = File.join(current, file)
          return self.escape_path(full_path) if File.exists?(full_path)
        end
      end
    end
  end

  false
end

.run_command(command, args = nil) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/vmc/micro.rb', line 37

def run_command(command, args=nil)
  # TODO switch to using posix-spawn instead
  result = %x{#{command} #{args} 2>&1}
  unless $?.exitstatus == 0
    if block_given?
      yield
    else
      raise "failed to execute #{command} #{args}:\n#{result}"
    end
  else
    result.split(/\n/)
  end
end