Module: Smithy

Defined in:
lib/smithy/config.rb,
lib/smithy/format.rb,
lib/smithy/formula.rb,
lib/smithy/helpers.rb,
lib/smithy/package.rb,
lib/smithy_version.rb,
lib/smithy/description.rb,
lib/smithy/module_file.rb,
lib/smithy/download_cache.rb,
lib/smithy/file_operations.rb,
lib/smithy/formula_command.rb

Overview

Smithy is freely available under the terms of the BSD license given below.

Copyright © 2012. UT-BATTELLE, LLC. All rights reserved.

Produced by the National Center for Computational Sciences at Oak Ridge National Laboratory. Smithy is a based on SWTools, more information on SWTools can be found at: www.olcf.ornl.gov/center-projects/swtools/

This product includes software produced by UT-Battelle, LLC under Contract No. DE-AC05-00OR22725 with the Department of Energy.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  • Neither the name of the UT-BATTELLE nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. }}

Defined Under Namespace

Modules: Format Classes: Config, Description, DownloadCache, FileOperations, Formula, FormulaCommand, ModuleFile, Package

Constant Summary collapse

VERSION =
'1.6.5'
FILE_NOTICE_COLUMNS =
12

Instance Method Summary collapse

Instance Method Details

#launch_editor(args = {}) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/smithy/helpers.rb', line 88

def launch_editor(args = {})
  editor = args[:editor] || ENV['EDITOR']
  raise """Please specify which editor to launch using the
     $EDITOR environment variable or the --editor option.""" if editor.blank?

  arg_list = [ editor ]
  arg_list << "-O" if args[:split] && editor =~ /vim/

  if args[:split]
    args[:files].each{|f| arg_list << f}
  else
    arg_list << args[:files].first
  end

  status = Kernel::system(*arg_list)
end

#log_exception(e, argv, config) ⇒ Object



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/smithy/helpers.rb', line 186

def log_exception(e, argv, config)
  logfile = Smithy::Config.global[:"global-error-log"]
  if logfile.present?
    exception = {
     "time"        => DateTime.now,
     "user"        => `whoami`.chomp,
     "hostname"    => `hostname`.chomp,
     "working_dir" => Dir.getwd,
     "argv"        => argv,
     "config"      => config,
     "exception"   => e,
     "backtrace"   => e.backtrace
    }
    File.open(logfile, "a") do |f|
      f.write(exception.to_yaml)
    end
  end
end

#modulehelp(name) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/smithy/helpers.rb', line 105

def modulehelp(name)
  raise "$MODULEPATH is not set" unless ENV.has_key?('MODULEPATH')
  sout = ""
  #serr = ""
  status = Open4::popen4("script -q -c '#{ENV['MODULESHOME']}/bin/modulecmd sh help #{name}' /dev/null") do |pid, stdin, stdout, stderr|
    sout += stdout.read.strip
    #serr += stderr.read.strip
  end
  #if status.exitstatus.eql?(0)
  sout.gsub!(/\r/, '')
  #serr.gsub!(/\r/, '')
  return sout
  #list = ""
  # status = Open4::popen4(ENV['MODULESHOME']+"/bin/modulecmd ruby avail -t") do |pid, stdin, stdout, stderr|
  #   list = stderr.read.strip
  # end
  # if status.exitstatus.eql?(0)
  #   m = {}
  #   key = nil
  #   list.split(/^(.*:)$/).each do |line|
  #     next if line.empty?
  #     if key.nil?
  #       if line =~ /^(.*):$/
  #         key = $1
  #       end
  #     else
  #       m[key] = line.split("\n")
  #       m[key].reject!{|l| l.empty?}
  #       key = nil
  #     end
  #   end
  # end
end

#notice(message) ⇒ Object



39
40
41
# File 'lib/smithy/helpers.rb', line 39

def notice(message)
  STDOUT.puts "==> ".color(:blue)+message #if STDOUT.tty?
end

#notice_command(command, comment, width = 40) ⇒ Object



51
52
53
# File 'lib/smithy/helpers.rb', line 51

def notice_command(command, comment, width=40)
  STDOUT.puts command.ljust(width)+comment.color(:blue) #if STDOUT.tty?
end

#notice_conflict(file) ⇒ Object



55
56
57
# File 'lib/smithy/file_operations.rb', line 55

def notice_conflict(file)
  puts "conflict ".rjust(12).color(:red) + file
end

#notice_create(file) ⇒ Object



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

def notice_create(file)
  puts "create ".rjust(12).color(:green) + file
end

#notice_exception(message) ⇒ Object



71
72
73
# File 'lib/smithy/helpers.rb', line 71

def notice_exception(message)
  STDERR.puts "==> ERROR: ".color(:red) + message
end

#notice_exist(file) ⇒ Object



43
44
45
# File 'lib/smithy/file_operations.rb', line 43

def notice_exist(file)
  puts "exists ".rjust(12).color(:blue) + file
end

#notice_fail(message) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/smithy/helpers.rb', line 63

def notice_fail(message)
  # if STDOUT.tty?
    STDOUT.puts ("==> "+message).color(:red)
  # else
  #   STDOUT.puts message
  # end
end

#notice_force(file) ⇒ Object



58
59
60
# File 'lib/smithy/file_operations.rb', line 58

def notice_force(file)
  puts "force ".rjust(12).color(:yellow) + file
end

#notice_identical(file) ⇒ Object



52
53
54
# File 'lib/smithy/file_operations.rb', line 52

def notice_identical(file)
  puts "identical ".rjust(12).color(:blue) + file
end

#notice_info(message) ⇒ Object



47
48
49
# File 'lib/smithy/helpers.rb', line 47

def notice_info(message)
  STDOUT.puts (message).color(:blue) #if STDOUT.tty?
end


49
50
51
# File 'lib/smithy/file_operations.rb', line 49

def notice_link(file1, file2)
  puts "link ".rjust(12) + file1 + " -> " + file2
end

#notice_skip(file) ⇒ Object



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

def notice_skip(file)
  puts "skip ".rjust(12) + file
end

#notice_success(message) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/smithy/helpers.rb', line 55

def notice_success(message)
  # if STDOUT.tty?
    STDOUT.puts "==> ".color(:green) + message.color(:green)
  # else
  #   STDOUT.puts message
  # end
end

#notice_using(file) ⇒ Object



46
47
48
# File 'lib/smithy/file_operations.rb', line 46

def notice_using(file)
  puts "using ".rjust(12).color(:blue) + file
end

#notice_warn(message) ⇒ Object



43
44
45
# File 'lib/smithy/helpers.rb', line 43

def notice_warn(message)
  STDOUT.puts ("==> "+message).color(:yellow) #if STDOUT.tty?
end

#operating_systemObject



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
# File 'lib/smithy/helpers.rb', line 139

def operating_system
  b = `uname -m`.chomp
  redhat = "/etc/redhat-release"
  suse = "/etc/SuSE-release"
  if File.exists? redhat
    # Red Hat Enterprise Linux Server release 6.3 (Santiago)
    # CentOS release 5.9 (Final)
    content = File.read(redhat)
    content =~ /([\d\.]+)/
    version = $1
    b = "rhel" if content =~ /Red Hat/
    b = "centos" if content =~ /CentOS/
    b += version
  elsif File.exists? suse
    # SUSE Linux Enterprise Server 11 (x86_64)
    # VERSION = 11
    # PATCHLEVEL = 1
    content = File.read(suse)
    content =~ /VERSION = (\d+)/
    version = $1
    content =~ /PATCHLEVEL = (\d+)/
    patch = $1
    b = "sles#{version}.#{patch}"
  end

  if `gcc --version 2>&1` =~ /gcc \((.*)\) ([\d\.]+)/
    b << "_gnu#{$2}"
  end
  return b
end

#process_ouput(stdout, stderr, suppress_stdout = false, log_file = nil) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/smithy/helpers.rb', line 75

def process_ouput(stdout, stderr, suppress_stdout = false, log_file = nil)
  unless stdout.empty?
    puts stdout unless suppress_stdout
    log_file.puts stdout unless log_file.nil?
    stdout.replace("")
  end
  unless stderr.empty?
    puts stderr unless suppress_stdout
    log_file.puts stderr unless log_file.nil?
    stderr.replace("")
  end
end

#url_filename(url) ⇒ Object



170
171
172
# File 'lib/smithy/helpers.rb', line 170

def url_filename(url)
  File.basename(URI(url).path)
end

#url_filename_basename(url) ⇒ Object



180
181
182
183
184
# File 'lib/smithy/helpers.rb', line 180

def url_filename_basename(url)
  name = url_filename(url)
  name = $1 if name =~ /(.*?)-([\d\.]+[\d])/
  name
end

#url_filename_version_number(url) ⇒ Object



174
175
176
177
178
# File 'lib/smithy/helpers.rb', line 174

def url_filename_version_number(url)
  version = url_filename(url)
  version = $1 if version =~ /([\d\.]+[\d])/
  version
end