Class: Panoramix::MPI

Inherits:
Object
  • Object
show all
Defined in:
lib/panoramix/mpi.rb

Class Method Summary collapse

Class Method Details

.diff_shObject



57
58
59
# File 'lib/panoramix/mpi.rb', line 57

def diff_sh
   system("bash -c \"diff <(echo '#{@final_mpi.pretty_inspect}') <(echo '#{@project_mpi.pretty_inspect}')| colordiff\"")
end

.generateObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/panoramix/mpi.rb', line 61

def generate
  # Check whether the file already exists
  if File.exists? @mpi_path
    puts "Error: mpi.rb already exists in this project. Please, remove it before in order to create a newest version.".red
    exit 0
  end

  # Get directory containing MPI.rb
  dir = Rake.application.original_dir
  
  # Replace each key path with the variable current_dir
  new_file = {} 
  @project_mpi.each do |host ,deps|
    new_hash = {} 
    deps.each do |k, v| 
      key = k.gsub(dir, '#{current_dir}')
      new_hash[key] = v
    end
    new_file[host] = new_hash
  end

  header = 
%&current_dir = File.expand_path(File.dirname(__FILE__))

Panoramix::MPI::Deps =& 

  File.open(@mpi_path,"w") do |f|
    f.write(header)
    f.write(new_file.pretty_inspect.gsub('\#','#'))
  end
end

.handle_external(key, value) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/panoramix/mpi.rb', line 22

def handle_external(key, value)
  # Get current scope
  scope = "local"

  # Save dependency into @project_mpi
  @project_mpi[scope] = {} if @project_mpi[scope].nil?
  @project_mpi[scope].merge!({key => value})

  @final_mpi[scope] = {} if @final_mpi[scope].nil?
  @final_mpi[scope].merge!({key => value})

  # Check whether dependencies can be overriden by an MPI file
  if (@mpi_file && @mpi_file[scope] && @mpi_file[scope][key])

    # Generate the new value from MPI
    mpi_value =  @mpi_file[scope][key]

    # Save overriden value to @final_mpi
    @final_mpi[scope] = {} if @final_mpi[scope].nil?
    @final_mpi[scope].merge!({key => mpi_value})

    return {key => mpi_value}
  end

  {key => value}
end

.initializeObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/panoramix/mpi.rb', line 9

def initialize
   @mpi_path = "MPI.rb"
  @mpi_file = {}
   @project_mpi = {}
   @final_mpi = {}

   # Read MPI.rb if exists
   if File.exists?(@mpi_path)
     load @mpi_path
     @mpi_file = Panoramix::MPI::Deps
   end
end


49
50
51
# File 'lib/panoramix/mpi.rb', line 49

def print_final_mpi
  puts @final_mpi.pretty_inspect
end


53
54
55
# File 'lib/panoramix/mpi.rb', line 53

def print_mpi
   puts @project_mpi.pretty_inspect
end