Class: Smithy::ModuleFile

Inherits:
Object
  • Object
show all
Defined in:
lib/smithy/module_file.rb

Constant Summary collapse

PackageModulePathName =
"modulefile"
SystemModulePathName =
"modulefiles"
Environments =
[
  {:prg_env => "PrgEnv-gnu",       :compiler_name => "gcc",       :human_name => "gnu",       :regex => /(gnu|gcc)(.*)/,
    :build_name_regex => /(gnu|gcc)([\d\.]+)/ },
  {:prg_env => "PrgEnv-pgi",       :compiler_name => "pgi",       :human_name => "pgi",       :regex => /(pgi)(.*)/,
    :build_name_regex => /(pgi)([\d\.]+)/ },
  {:prg_env => "PrgEnv-intel",     :compiler_name => "intel",     :human_name => "intel",     :regex => /(intel)(.*)/,
    :build_name_regex => /(intel)([\d\.]+)/ },
  {:prg_env => "PrgEnv-cray",      :compiler_name => "cce",       :human_name => "cray",      :regex => /(cce|cray)(.*)/,
    :build_name_regex => /(cce|cray)([\d\.]+)/ }
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ ModuleFile

Returns a new instance of ModuleFile.



61
62
63
64
# File 'lib/smithy/module_file.rb', line 61

def initialize(args = {})
  @package = args[:package]
  @builds = @package.alternate_builds
end

Instance Attribute Details

#buildsObject

Returns the value of attribute builds.



40
41
42
# File 'lib/smithy/module_file.rb', line 40

def builds
  @builds
end

#packageObject

Returns the value of attribute package.



40
41
42
# File 'lib/smithy/module_file.rb', line 40

def package
  @package
end

Class Method Details

.compilersObject

=> “PrgEnv-pathscale”, :compiler_name => “pathscale”, :human_name => “pathscale”, :regex => /(pathscale)(.*)/



57
58
59
# File 'lib/smithy/module_file.rb', line 57

def self.compilers
  Smithy::Config.compilers || Environments
end

.get_module_names(options = {}) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/smithy/module_file.rb', line 188

def self.get_module_names(options = {})
  if options[:only]
    module_dirs = options[:only].split(':')
    raise "No module directories could be found" if module_dirs.empty?
  else
    raise "$MODULEPATH is not set" unless ENV.has_key?('MODULEPATH')
    module_dirs = ENV['MODULEPATH'].split(':')
    raise "$MODULEPATH is empty" if module_dirs.empty?
  end

  system_module_names = []
  system_module_defaults = []
  if options[:except]
    module_dirs.delete_if{|p| options[:except].split(":").include?(p)}
  end
  module_dirs.each do |p|
    module_files          = Dir.glob(p+"/*/*").sort
    module_files_defaults = module_files.dup
    version_files         = Dir.glob(p+"/*/.version").sort

    version_files.each do |version_file|
      module_name = File.basename(File.dirname(version_file))
      file_content = ""
      File.open(version_file).readlines.each { |line| file_content << line.chomp }

      if file_content =~ /ModulesVersion "(.*?)"/
        version = $1
        module_files_defaults.collect! do |m|
          if m =~ /#{module_name}\/#{version}$/
            m+"(default)"
          else
            m
          end
        end
      end

    end

    module_files.collect!{|s| s.gsub(p+"/", '')}
    system_module_names += module_files
    system_module_defaults += module_files_defaults
  end

  # desired_modules = %w{ ^cce ^pgi ^intel ^gcc ^hdf5 ^netcdf ^fftw ^petsc ^trilinos ^chapel ^java ^ntk ^papi ^stat ^gdb ^perftools ^tpsl ^ga\/ ^libsci_acc ^acml }
  # stub_packages = system_module_names.select{|m| m =~ /(#{desired_modules.join('|')})/}

  return system_module_names, system_module_defaults
end

Instance Method Details

#create(args = {}) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/smithy/module_file.rb', line 86

def create(args = {})
  notice "Creating Modulefile for #{package.prefix}"
  notice_warn "Dry Run! (no files will be created or changed)" if args[:dry_run]

  options = {:noop => false, :verbose => false}
  options[:noop] = true if args[:dry_run]

  FileUtils.mkdir_p(File.join(module_path, package.name), options)

  if args[:existing]
    existing_modulefile = File.join(args[:existing], "../modulefile", package.name, package.version)
    FileOperations.install_file(existing_modulefile, module_file, options) if File.exists?(existing_modulefile)
  else
    FileOperations.render_erb :destination => module_file,
      :erb => File.join(@@smithy_bin_root, "/etc/templates/modulefile.erb"),
      :binding => get_binding, :options => options
  end

  FileOperations.make_group_writable(module_path, options.merge(:recursive => true))
  FileOperations.set_group(module_path, package.group, options.merge(:recursive => true))
end

#deploy(args = {}) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/smithy/module_file.rb', line 108

def deploy(args = {})
  options = {:noop => false, :verbose => false}
  options[:noop] = true if args[:dry_run]

  g = system_module_path+"/*#{package.name}*/*#{package.version}*"
  module_matches = Dir.glob(g)
  if module_matches.size > 1
    notice_warn "Warning - multiple existing modulefiles found:"
    puts module_matches
  end

  if module_matches.empty?
    destination = system_module_file
  else
    destination = module_matches.first
  end

  notice "Deploying modulefile #{destination}"
  install_dir = File.join(system_module_path, package.name)
  FileOperations.make_directory install_dir, options
  FileOperations.install_file module_file, destination, options
  FileOperations.make_group_writable(install_dir, options.merge(:recursive => true))
  FileOperations.set_group(install_dir, package.group, options.merge(:recursive => true))
end

#get_bindingObject



66
67
68
# File 'lib/smithy/module_file.rb', line 66

def get_binding
  binding
end

#module_build_list(package, builds, args = {}) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/smithy/module_file.rb', line 133

def module_build_list(package, builds, args = {})
  output = ""

  notice "Multiple Builds Found" if Smithy::Config.global[:verbose]
  notice_info "Build Name".rjust(25)+"   Required Modules" if Smithy::Config.global[:verbose]
  ModuleFile::compilers.each_with_index do |e,i|

    prgenv =  e[:prg_env]
    prgenv.gsub!(/PrgEnv-/, args.fetch(:prgenv_prefix)) if args[:prgenv_prefix]

    if i == 0
      output << "if "
    else
      output << "} elseif "
    end
    output << "[ is-loaded #{e[:prg_env]} ] {\n"
    if j=builds.index{|b|b=~e[:regex]}
      sub_builds = builds.select{|b|b=~e[:regex]}
      if sub_builds.size > 1
        sub_builds.each_with_index do |b,k|
          b =~ e[:build_name_regex]
          name = e[:compiler_name]
          version = $2
          if k == 0
            output << "  if "
          else
            output << "  } elseif "
          end
          output << "[ is-loaded #{name}/#{version} ] {\n"
          output << "    set BUILD #{b}\n"
          notice_info b.rjust(25) + "   #{e[:prg_env]} + #{name}/#{version}" if Smithy::Config.global[:verbose]
        end
        output << "  } else {\n"
        output << "    set BUILD #{sub_builds.last}\n"
        output << "  }\n"
      else
        output << "  set BUILD #{builds[j]}\n"
        notice_info builds[j].rjust(25) + "   #{e[:prg_env]}" if Smithy::Config.global[:verbose]
      end
    else
      output << "  puts stderr \"Not implemented for the #{e[:human_name]} compiler\"\n"
    end
  end

  output << "}\n"
  output << "if {![info exists BUILD]} {\n"
  output << "  puts stderr \"[module-info name] is only available for the following environments:\"\n"
  builds.each do |build|
    output << "  puts stderr \"#{build}\"\n"
  end
  output << "  break\n}\n"

  return output
end

#module_fileObject



74
75
76
# File 'lib/smithy/module_file.rb', line 74

def module_file
  File.join(module_path, package.name, package.version)
end

#module_pathObject



70
71
72
# File 'lib/smithy/module_file.rb', line 70

def module_path
  File.join(package.version_directory, PackageModulePathName)
end

#system_module_fileObject



82
83
84
# File 'lib/smithy/module_file.rb', line 82

def system_module_file
  File.join(system_module_path, package.name, package.version)
end

#system_module_pathObject



78
79
80
# File 'lib/smithy/module_file.rb', line 78

def system_module_path
  File.join(package.software_root, SystemModulePathName)
end