Class: Smithy::Config

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

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.archObject

Returns the value of attribute arch.



41
42
43
# File 'lib/smithy/config.rb', line 41

def arch
  @arch
end

.config_file_hashObject

Returns the value of attribute config_file_hash.



41
42
43
# File 'lib/smithy/config.rb', line 41

def config_file_hash
  @config_file_hash
end

.config_file_nameObject

Returns the value of attribute config_file_name.



41
42
43
# File 'lib/smithy/config.rb', line 41

def config_file_name
  @config_file_name
end

.descriptions_rootObject

Returns the value of attribute descriptions_root.



41
42
43
# File 'lib/smithy/config.rb', line 41

def descriptions_root
  @descriptions_root
end

.file_groupObject

Returns the value of attribute file_group.



41
42
43
# File 'lib/smithy/config.rb', line 41

def file_group
  @file_group
end

.full_rootObject

Returns the value of attribute full_root.



41
42
43
# File 'lib/smithy/config.rb', line 41

def full_root
  @full_root
end

.globalObject

Returns the value of attribute global.



41
42
43
# File 'lib/smithy/config.rb', line 41

def global
  @global
end

.hostnameObject

Returns the value of attribute hostname.



41
42
43
# File 'lib/smithy/config.rb', line 41

def hostname
  @hostname
end

.rootObject

Returns the value of attribute root.



41
42
43
# File 'lib/smithy/config.rb', line 41

def root
  @root
end

.web_architecture_namesObject

Returns the value of attribute web_architecture_names.



41
42
43
# File 'lib/smithy/config.rb', line 41

def web_architecture_names
  @web_architecture_names
end

.web_rootObject

Returns the value of attribute web_root.



41
42
43
# File 'lib/smithy/config.rb', line 41

def web_root
  @web_root
end

Class Method Details

.architectures(options) ⇒ Object



112
113
114
115
116
117
118
119
120
# File 'lib/smithy/config.rb', line 112

def architectures(options)
  if options[:all]
    puts @config_file_hash["hostname-architectures"].values.uniq.sort.join(" ")
  else
    notice_command "Current Hostname: ", @hostname, 30
    notice_command "Current Architecture: ", @arch, 30
    notice_command "All Architectures: ", @config_file_hash["hostname-architectures"].values.uniq.sort.join(", "), 30
  end
end

.compilersObject



122
123
124
# File 'lib/smithy/config.rb', line 122

def compilers
  config_file_hash.try(:[], "compilers")
end

.example_configObject



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
236
237
238
239
240
241
242
243
244
# File 'lib/smithy/config.rb', line 206

def example_config
  example = {}
  example["software-root"]       = "/sw"
  example["download-cache"]      = "/sw/sources"
  example["formula-directories"] = [
    "/sw/tools/smithy/formulas",
    "/sw/tools/smithy/another_formula_directory"
  ]
  example["global-error-log"]    = "/sw/tools/smithy/exceptions.log"
  example["file-group-name"]        = "ccsstaff"
  example["descriptions-root"]      = "/sw/descriptions"
  example["web-root"]               = "/sw/descriptions_in_html"
  example["web-architecture-names"] = {
    "xk6"          => "titan",
    "xk7"          => "titan",
    "analysis-x64" => "lens",
    "smoky"        => "smoky"
  }
  # example["programming-environment-prefix"] = {
  #   "default" => "PrgEnv-",
  #   "smoky"   => "PE-",
  #   "sith"    => "PE-"
  # }
  example["hostname-architectures"] = {
    "everest-login" => "redhat6",
    "everest"       => "redhat6",
    "lens"          => "analysis-x64",
    "sith-login"    => "redhat6",
    "sith"          => "redhat6",
    "smoky-login"   => "smoky",
    "titan-login"   => "xk6",
    "titan-ext"     => "xk6",
    "yona-login"    => "yona",
    "yona"          => "yona"
  }
  example["compilers"] = ModuleFile::Environments

  return example.to_yaml
end

.get_software_rootObject



152
153
154
155
156
157
158
159
160
161
162
# File 'lib/smithy/config.rb', line 152

def get_software_root
  if @root.blank? || @arch.blank?
    raise """Cannot determine which architecture we are using.
 Please specify using --arch or add a '#{@hostname}' hostname entry to:
 #{@config_file_name}"""
  end

  s = File.join(@root, @arch)
  raise "The software-root directory '#{s}' does not exist" unless Dir.exist?(s)
  return s
end

.group_writable?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/smithy/config.rb', line 45

def group_writable?
  @global[:"disable-group-writable"] ? false : true
end

.homedirObject



164
165
166
167
# File 'lib/smithy/config.rb', line 164

def homedir
  @homedir ||= File.join(Dir.home(Etc.getlogin))
  @homedir
end

.last_prefixObject



169
170
171
172
173
174
175
176
177
# File 'lib/smithy/config.rb', line 169

def last_prefix
  rc_file = File.join(homedir, '.smithyrc')
  if File.exists?(rc_file)
    h = YAML.load_file(rc_file).stringify_keys rescue nil
    return h["last"]
  else
    return nil
  end
end

.load_config_yamlObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/smithy/config.rb', line 93

def load_config_yaml
  config_path = File.expand_path(ENV['SMITHY_CONFIG']) if ENV['SMITHY_CONFIG']
  config_path = File.expand_path(global[:"config-file"]) if global[:"config-file"]

  if config_path.present? && File.exists?(config_path)
    @config_file_name = config_path
    begin
      @config_file_hash = YAML.load_file(config_path).stringify_keys
    rescue
      raise """Cannot interpret smithy config file. This is probably caused by malformed YAML.
 #{config_path}"""
    end
  else
    raise """Cannot read config file: #{@config_file_name}
 Please set the $SMITHY_CONFIG variable to a config file location
 Or use the --config-file=FILE option"""
  end
end

.load_configuration(gli_options = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
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/smithy/config.rb', line 49

def load_configuration(gli_options = {})
  @global = gli_options
  options_to_merge = {}
  load_config_yaml

  return nil unless @config_file_hash

  # Pick some values from the config file
  options_to_merge[:"software-root"]   = @config_file_hash.try(:[], "software-root")
  options_to_merge[:"web-root"]        = @config_file_hash.try(:[], "web-root")
  options_to_merge[:"file-group-name"] = @config_file_hash.try(:[], "file-group-name")
  options_to_merge[:"descriptions-root"] = @config_file_hash.try(:[], "descriptions-root")
  options_to_merge[:"web-architecture-names"] = @config_file_hash.try(:[], "web-architecture-names")
  options_to_merge[:"download-cache"] = @config_file_hash.try(:[], "download-cache")
  options_to_merge[:"formula-directories"] = @config_file_hash.try(:[], "formula-directories")
  options_to_merge[:"global-error-log"] = @config_file_hash.try(:[], "global-error-log")

  set_hostname_and_arch
  options_to_merge[:arch] = @arch
  # options_to_merge[:"prgenv-prefix"] = get_prgenv_prefix

  # Merge the config file values with command line values,
  # options on the command line take precedence.
  @global.merge!(options_to_merge) do |key, values_command_line, values_config|
    if values_command_line.nil?
      values_config
    else
      values_command_line
    end
  end

  @arch = @global[:arch]
  @root = @global[:"software-root"]
  @file_group = @global[:"file-group-name"]
  @full_root = get_software_root
  @web_root = @global[:"web-root"]
  @descriptions_root = @global[:"descriptions-root"]
  @web_architecture_names = @global[:"web-architecture-names"]

  # Add new info
  @global[:full_software_root_path] = @full_root
  @global[:"file-group-id"]   = Etc.getgrnam(options_to_merge[:"file-group-name"]).try(:gid) if @global[:"file-group-name"]
end

.reindex_completion_cachesObject



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

def reindex_completion_caches
  notice "Reindexing packages"
  FormulaCommand.initialize_directories
  formulas = FormulaCommand.formula_names
  packages = Package.all.collect{|s| s.gsub(/#{full_root}\//, '')}

  FileUtils.mkdir_p(File.join(homedir, ".smithy"))

  File.open(File.join(homedir, ".smithy", "completion_formulas"), "w+") do |f|
    f.puts formulas
  end
  File.open(File.join(homedir, ".smithy", "completion_packages"), "w+") do |f|
    f.puts packages
  end
  File.open(File.join(homedir, ".smithy", "completion_arches"), "w+") do |f|
    f.puts @config_file_hash["hostname-architectures"].values.uniq.sort
  end
end

.save_last_prefix(prefix) ⇒ Object



179
180
181
182
183
184
185
# File 'lib/smithy/config.rb', line 179

def save_last_prefix(prefix)
  rc_file = File.join(homedir, '.smithyrc')
  h = {:last => prefix.encode('UTF-8')}
  File.open(rc_file, "w+") do |f|
    f.write(h.to_yaml)
  end
end

.set_hostname_and_archObject

return default_prefix end



139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/smithy/config.rb', line 139

def set_hostname_and_arch
  @hostname ||= ENV.try(:[], 'HOSTNAME').try(:dup)
  @hostname ||= `hostname -s`.try(:dup)
  @hostname.chomp!
  # Remove trailing numbers (if they exist) and a possible single trailing period
  @hostname.gsub!(/\.?$/,'')
  machine = @hostname.gsub(/(\d*)$/,'')

  @arch = global[:arch] if @arch.nil?
  @arch = @config_file_hash.try(:[], "hostname-architectures").try(:[], machine) if @arch.nil?
  @arch = @config_file_hash.try(:[], "hostname-architectures").try(:[], @hostname) if @arch.nil?
end