software_smithy 1.1 → 1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,30 +4,46 @@ _smithy_packages() {
4
4
  packages=(`smithy search --format=name`)
5
5
  }
6
6
 
7
+ _smithy_formulas() {
8
+ formulas=(`smithy formula list`)
9
+ }
10
+
11
+ _smithy_architectures() {
12
+ arches=(`smithy show arch --all`)
13
+ _wanted packages expl 'architectures' compadd -a arches
14
+ }
15
+
7
16
  local -a _1st_arguments
8
17
  _1st_arguments=(
9
- 'build:Build software'
10
- 'deploy:Deploy a package'
18
+ 'build:Build software'
11
19
  'edit:Edit package support files'
12
- 'help:Shows list of commands or help for one command'
20
+ 'formula:Install software from predefined formulas'
21
+ 'help:Shows a list of commands or help for one command'
13
22
  'module:Manage modulefiles for a package'
14
- 'new:Generate a new build and all necessary files'
15
- 'repair:Repair a package'
16
- 'search:Search currently installed software'
17
- 'test:Test software'
23
+ 'new:Generate a new build and all necessary files'
24
+ 'publish:Publish packages to web'
25
+ 'repair:Repair a package'
26
+ 'search:Search currently installed software'
27
+ 'show:Display internal smithy values'
28
+ 'test:Test software'
18
29
  )
19
30
 
20
31
  local expl
21
32
  local -a formulae
22
33
 
23
34
  _arguments \
24
- '(--arch=)--arch=[Machine architecture to operate on]' \
35
+ '(--arch=)--arch=[Machine architecture to operate on]:architecture:_smithy_architectures' \
36
+ '(--no-color)--no-color[Disable colored output]' \
37
+ '(--color)--color[Enable colored output]' \
25
38
  '(--config-file=)--config-file=[Alternate config file]:file:_files' \
39
+ '(--descriptions-root=)--descriptions-root=[The root level directory for global description files]:directory:_files -/' \
26
40
  '(--disable-group-writeable)--disable-group-writeable[Disable group writable file creation]' \
41
+ '(-f --force)'{-f,--force}'[Always overwrite existing files]' \
27
42
  '(--file-group-name=)--file-group-name=[Group name for files created by smithy]' \
28
43
  '(--help)--help[Show help]' \
29
- '(--no-color)--no-color[Hide coloring]' \
44
+ '(--prgenv-prefix=)--prgenv-prefix=[The prefix of programming environments for this machine]' \
30
45
  '(--software-root=)--software-root=[The root level directory for software]:directory:_files -/' \
46
+ '(-v --verbose)'{-v,--verbose}'[Be more verbose]' \
31
47
  '(--web-root=)--web-root=[The root level directory for web files]:directory:_files -/' \
32
48
  '*:: :->subcmds' && return 0
33
49
  #[[ "$PREFIX" = --* ]] && _arguments -- \
@@ -41,10 +57,15 @@ if (( CURRENT == 1 )); then
41
57
  return
42
58
  fi
43
59
 
60
+ # echo $words >/dev/ttys004
61
+ # echo $CURRENT >/dev/ttys004
62
+
44
63
  # completion for each sub command
45
64
  case "$words[1]" in
46
65
  help)
47
- _describe -t commands "smithy subcommand" _1st_arguments ;;
66
+ _describe -t commands "smithy subcommand" _1st_arguments
67
+ ;;
68
+
48
69
  build|test)
49
70
  _arguments \
50
71
  '(--disable-log)--disable-log[Disable logging]' \
@@ -57,21 +78,14 @@ case "$words[1]" in
57
78
  if [[ "$state" == forms ]]; then
58
79
  _smithy_packages
59
80
  _wanted packages expl 'packages' compadd -a packages
60
- fi ;;
61
- deploy)
62
- _arguments \
63
- '(-n --dry-run)'{-n,--dry-run}'[See what files will be created without creating them]' \
64
- '1: :->forms' && return 0
81
+ fi
82
+ ;;
65
83
 
66
- if [[ "$state" == forms ]]; then
67
- _smithy_packages
68
- _wanted packages expl 'packages' compadd -a packages
69
- fi ;;
70
84
  edit)
71
85
  _subsub_commands=(
72
86
  'build:Edit a build script'
73
87
  'test:Edit a test script'
74
- 'environment:Edit modules loaded for the build script'
88
+ 'env:Edit modules loaded for the build script'
75
89
  'modulefile:Edit modulefile'
76
90
  )
77
91
  # Match subsub-command
@@ -88,12 +102,15 @@ case "$words[1]" in
88
102
  if [[ "$state" == forms ]]; then
89
103
  _smithy_packages
90
104
  _wanted packages expl 'packages' compadd -a packages
91
- fi ;;
105
+ fi
106
+ ;;
107
+
92
108
  module)
93
109
  _subsub_commands=(
94
110
  'create:Generate a modulefile for a given package'
95
- 'use:Add a modulefile to the MODULEPATH'
96
111
  'deploy:Copy a modulefile to the system MODULEPATH'
112
+ 'edit:Alias for "smithy edit modulefile"'
113
+ 'use:Add a modulefile to the MODULEPATH'
97
114
  )
98
115
  # Match subsub-command
99
116
  if (( CURRENT == 2 )); then
@@ -103,18 +120,23 @@ case "$words[1]" in
103
120
 
104
121
  _arguments \
105
122
  '(-n --dry-run)'{-n,--dry-run}'[See what files will be created without creating them]' \
106
- '2: :->forms' && return 0
123
+ '1: :->forms' && return 0
107
124
 
108
125
  if [[ "$state" == forms ]]; then
109
126
  _smithy_packages
110
127
  _wanted packages expl 'packages' compadd -a packages
111
- fi ;;
128
+ fi
129
+ ;;
130
+
112
131
  new)
113
132
  _arguments \
133
+ '(--existing-scripts)--existing-scripts[Use an existing softwares build scripts]' \
114
134
  '(--skip-modulefile)--skip-modulefile[Skip modulefile generation]' \
115
135
  '(--web-description)--web-description[Create description file for website]' \
116
136
  '(-n --dry-run)'{-n,--dry-run}'[See what files will be created without creating them]' \
117
- '(-t --tarball=)'{-t,--tarball=}'[Provide a source tarball to unpack (optional)]:file:_files' ;;
137
+ '(-t --tarball=)'{-t,--tarball=}'[Provide a source tarball to unpack (optional)]:file:_files'
138
+ ;;
139
+
118
140
  repair)
119
141
  _arguments \
120
142
  '(-n --dry-run)'{-n,--dry-run}'[Verify permissions only]' \
@@ -123,8 +145,80 @@ case "$words[1]" in
123
145
  if [[ "$state" == forms ]]; then
124
146
  _smithy_packages
125
147
  _wanted packages expl 'packages' compadd -a packages
126
- fi ;;
148
+ fi
149
+ ;;
150
+
127
151
  search)
128
152
  _arguments \
129
- '(--format=)--format=[Format of the output]:format:(path name table csv)' ;;
153
+ '(--format=)--format=[Format of the output]:format:(path name table csv dokuwiki)'
154
+ ;;
155
+
156
+ show)
157
+ _subsub_commands=(
158
+ 'arch:List all architectures know to smithy.'
159
+ 'example_config:Display an example config file.'
160
+ 'last:Display the package name used in the last smithy command. This is stored in the ~/.smithyrc file.'
161
+ )
162
+ # Match subsub-command
163
+ if (( CURRENT == 2 )); then
164
+ _describe -t subcommands "show subcommand" _subsub_commands
165
+ return
166
+ fi
167
+ ;;
168
+
169
+ publish)
170
+ _arguments \
171
+ '(-n --dry-run)'{-n,--dry-run}'[See what files will be created without creating them]' \
172
+ '1: :->forms' && return 0
173
+
174
+ if [[ "$state" == forms ]]; then
175
+ _smithy_packages
176
+ _wanted packages expl 'packages' compadd -a packages
177
+ fi
178
+ ;;
179
+
180
+ formula)
181
+ # echo $words[$CURRENT] > /dev/ttys004
182
+
183
+ _subsub_commands=(
184
+ 'create_modulefile:Create a modulefile for a given package'
185
+ 'display:Display a formula'
186
+ 'install:Install a package using a formula'
187
+ 'list:List known formulas'
188
+ 'new:Create a new formula'
189
+ 'which:Display a formula location'
190
+ )
191
+
192
+ # not sure how to make this work right
193
+ # _arguments \
194
+ # '(-d --directories=)'{-d,--directories=}'[Specify one or more additional formula directories separated with commas]:directory:_files -/' \
195
+ # '1: :->forms' && return 0
196
+
197
+ # Match subsub-command
198
+ if (( CURRENT == 2 )); then
199
+ _describe -t subcommands "formula subcommand" _subsub_commands
200
+ return
201
+ fi
202
+
203
+ # Match subsub-command arguments
204
+ if (( CURRENT == 3 )); then
205
+ case "$words[2]" in
206
+ install)
207
+ _arguments \
208
+ '(--clean)--clean[clean existing install prefix]' \
209
+ '(--no-clean)--no-clean[leave existing install prefix files intact]' \
210
+ '(-f --formula-name)'{-f,--formula-name}'[Formula name]' \
211
+ '(-m --modulefile)'{-m,--modulefile}'[Create modulefiles as well]' \
212
+ '1: :->forms' && return 0
213
+ if [[ "$state" == forms ]]; then
214
+ _smithy_formulas
215
+ _wanted packages expl 'formulas' compadd -a formulas
216
+ fi
217
+ ;;
218
+ esac
219
+
220
+ return
221
+ fi
222
+
223
+ ;;
130
224
  esac
@@ -0,0 +1,11 @@
1
+ class <%= @formula_name %>Formula < Formula
2
+ homepage "<%= @formula_homepage %>"
3
+ url "<%= @formula_url %>"
4
+
5
+ def install
6
+ module_list
7
+ system "./configure --prefix=#{prefix}"
8
+ system "make"
9
+ system "make install"
10
+ end
11
+ end
@@ -6,13 +6,6 @@
6
6
  <td style="text-align:center;"><b>System</b></td>
7
7
  <td style="text-align:center;"><b>Application/Version</b></td>
8
8
  <td style="text-align:center;"><b>Build</b></td>
9
- <!-- <%# ModuleFile::Environments.reject{|e| e[:human_name]=="pathscale"}.each do |e| %> -->
10
- <!-- <td style="text-align:center;"> -->
11
- <!-- <b> -->
12
- <!-- <%#= e[:human_name].upcase %> -->
13
- <!-- </b> -->
14
- <!-- </td> -->
15
- <!-- <%# end %> -->
16
9
  </tr>
17
10
  </thead>
18
11
 
@@ -6,7 +6,7 @@ Checkmarks indicate a given version is available for the compiler specified in e
6
6
  <thead>
7
7
  <tr>
8
8
  <td style="text-align:center;"><b>Version</b></td>
9
- <% ModuleFile::Environments.reject{|e| e[:human_name]=="pathscale"}.each do |e| %>
9
+ <% ModuleFile::compilers.reject{|e| e[:human_name]=="pathscale"}.each do |e| %>
10
10
  <td style="text-align:center;"><b><%= e[:human_name].upcase %></b></td>
11
11
  <% end %>
12
12
  </tr>
@@ -15,7 +15,7 @@ Checkmarks indicate a given version is available for the compiler specified in e
15
15
  <% @version_table.each do |version, builds| %>
16
16
  <tr>
17
17
  <td style="text-align:center;"><b><%= "#{@name}/#{version}" %></b></td>
18
- <% ModuleFile::Environments.reject{|e| e[:human_name]=="pathscale"}.each do |e| %>
18
+ <% ModuleFile::compilers.reject{|e| e[:human_name]=="pathscale"}.each do |e| %>
19
19
  <td style="text-align:center;"><% if builds.select{|b|b=~e[:regex]}.size > 0 %><img width="23" height="18" style="margin:0;" title="checkmark" alt="" src="http://www.olcf.ornl.gov/wp-content/uploads/2011/03/checkmark.png"><% end %></td>
20
20
  <% end %>
21
21
  </tr>
data/lib/smithy/config.rb CHANGED
@@ -42,7 +42,7 @@ module Smithy
42
42
  :arch, :root, :full_root, :web_root, :file_group, :descriptions_root,
43
43
  :web_architecture_names
44
44
 
45
- def group_writeable?
45
+ def group_writable?
46
46
  @global[:"disable-group-writable"] ? false : true
47
47
  end
48
48
 
@@ -59,6 +59,9 @@ module Smithy
59
59
  options_to_merge[:"file-group-name"] = @config_file_hash.try(:[], "file-group-name")
60
60
  options_to_merge[:"descriptions-root"] = @config_file_hash.try(:[], "descriptions-root")
61
61
  options_to_merge[:"web-architecture-names"] = @config_file_hash.try(:[], "web-architecture-names")
62
+ options_to_merge[:"download-cache"] = @config_file_hash.try(:[], "download-cache")
63
+ options_to_merge[:"formula-directories"] = @config_file_hash.try(:[], "formula-directories")
64
+ options_to_merge[:"global-error-log"] = @config_file_hash.try(:[], "global-error-log")
62
65
 
63
66
  set_hostname_and_arch
64
67
  options_to_merge[:arch] = @arch
@@ -90,21 +93,34 @@ module Smithy
90
93
  def load_config_yaml
91
94
  config_path = File.expand_path(ENV['SMITHY_CONFIG']) if ENV['SMITHY_CONFIG']
92
95
  config_path = File.expand_path(global[:"config-file"]) if global[:"config-file"]
93
- config_path = File.expand_path(@config_file_name) if config_path.blank?
94
96
 
95
- if File.exists? config_path
97
+ if config_path.present? && File.exists?(config_path)
96
98
  @config_file_name = config_path
97
- @config_file_hash = YAML.load_file(config_path).stringify_keys
99
+ begin
100
+ @config_file_hash = YAML.load_file(config_path).stringify_keys
101
+ rescue
102
+ raise """Cannot interpret smithy config file. This is probably caused by malformed YAML.
103
+ #{config_path}"""
104
+ end
105
+ else
106
+ raise """Cannot read config file: #{@config_file_name}
107
+ Please set the $SMITHY_CONFIG variable to a config file location
108
+ Or use the --config-file=FILE option"""
109
+ end
110
+ end
111
+
112
+ def architectures(options)
113
+ if options[:all]
114
+ puts @config_file_hash["hostname-architectures"].values.uniq.sort.join(" ")
98
115
  else
99
- raise """warning: Cannot read config file: #{@config_file_name}
100
- Please update the file or set SMITHY_CONFIG """
116
+ notice_command "Current Hostname: ", @hostname, 30
117
+ notice_command "Current Architecture: ", @arch, 30
118
+ notice_command "All Architectures: ", @config_file_hash["hostname-architectures"].values.uniq.sort.join(", "), 30
101
119
  end
102
120
  end
103
121
 
104
- def architectures
105
- notice_command "Current Hostname: ", @hostname, 30
106
- notice_command "Current Architecture: ", @arch, 30
107
- notice_command "All Architectures: ", @config_file_hash["hostname-architectures"].values.uniq.sort.join(", "), 30
122
+ def compilers
123
+ config_file_hash.try(:[], "compilers")
108
124
  end
109
125
 
110
126
  def get_prgenv_prefix
@@ -136,8 +152,8 @@ module Smithy
136
152
  def get_software_root
137
153
  if @root.blank? || @arch.blank?
138
154
  raise """Cannot determine which architecture we are using.
139
- Please specify using --arch or add a '#{@hostname}' hostname entry to:
140
- #{@config_file_name}"""
155
+ Please specify using --arch or add a '#{@hostname}' hostname entry to:
156
+ #{@config_file_name}"""
141
157
  end
142
158
 
143
159
  s = File.join(@root, @arch)
@@ -157,11 +173,52 @@ module Smithy
157
173
 
158
174
  def save_last_prefix(prefix)
159
175
  rc_file = File.join(ENV['HOME'], '.smithyrc')
160
- h = {:last => prefix}
176
+ h = {:last => prefix.encode('UTF-8')}
161
177
  File.open(rc_file, "w+") do |f|
162
178
  f.write(h.to_yaml)
163
179
  end
164
180
  end
181
+
182
+ def example_config
183
+ example = {}
184
+ example["software-root"] = "/sw"
185
+ example["download-cache"] = "/sw/sources"
186
+ example["formula-directories"] = [
187
+ "/sw/tools/smithy/formulas",
188
+ "/sw/tools/smithy/another_formula_directory"
189
+ ]
190
+ example["global-error-log"] = "/sw/tools/smithy/exceptions.log"
191
+ example["file-group-name"] = "ccsstaff"
192
+ example["descriptions-root"] = "/sw/descriptions"
193
+ example["web-root"] = "/sw/descriptions_in_html"
194
+ example["web-architecture-names"] = {
195
+ "xk6" => "titan",
196
+ "xk7" => "titan",
197
+ "analysis-x64" => "lens",
198
+ "smoky" => "smoky"
199
+ }
200
+ example["programming-environment-prefix"] = {
201
+ "default" => "PrgEnv-",
202
+ "smoky" => "PE-",
203
+ "sith" => "PE-"
204
+ }
205
+ example["hostname-architectures"] = {
206
+ "everest-login" => "redhat6",
207
+ "everest" => "redhat6",
208
+ "lens" => "analysis-x64",
209
+ "sith-login" => "redhat6",
210
+ "sith" => "redhat6",
211
+ "smoky-login" => "smoky",
212
+ "titan-login" => "xk6",
213
+ "titan-ext" => "xk6",
214
+ "yona-login" => "yona",
215
+ "yona" => "yona"
216
+ }
217
+ example["compilers"] = ModuleFile::Environments
218
+
219
+ return example.to_yaml
220
+ end
221
+
165
222
  end
166
223
  end
167
224
  end
@@ -43,7 +43,7 @@ module Smithy
43
43
  def initialize(args = {})
44
44
  @www_root = Smithy::Config.web_root
45
45
  @package = args[:package]
46
- @global_description = true if Smithy::Config.descriptions_root
46
+ @global_description = Smithy::Config.descriptions_root if Smithy::Config.descriptions_root
47
47
 
48
48
  if @package.class == Package
49
49
  @root = @package.root
@@ -57,12 +57,12 @@ module Smithy
57
57
 
58
58
  if @global_description
59
59
  @name = @package.gsub(/#{Smithy::Config.descriptions_root}\/?/, "")
60
- @path = @package
60
+ @path = File.join(Smithy::Config.descriptions_root, @name) if @global_description
61
61
  else
62
62
  if @package == 'last'
63
63
  @name = last_prefix.split('/').try(:first)
64
64
  else
65
- @name = Package.normalize_name :name => args[:package], :root => @root, :arch => @arch
65
+ @name = Package.normalize_name(args[:package])
66
66
  end
67
67
  @path = File.join @root, @arch, @name
68
68
  end
@@ -254,7 +254,7 @@ module Smithy
254
254
  if Smithy::Config.descriptions_root
255
255
  File.basename(p)
256
256
  else
257
- Package.normalize_name(:name => p, :root => root, :arch => arch)
257
+ Package.normalize_name(p)
258
258
  end
259
259
  end
260
260
  @packages.sort!
@@ -0,0 +1,120 @@
1
+ module Smithy
2
+ class DownloadCache
3
+ attr_accessor :url, :name, :version, :checksums
4
+
5
+ def initialize(p, fname = nil)
6
+ @url = ''
7
+ @checksums = {}
8
+ if p.is_a? Formula
9
+ @url = p.try(:url)
10
+ @checksums.merge!(:md5 => p.md5) if p.try(:md5)
11
+ @checksums.merge!(:sha1 => p.sha1) if p.try(:sha1)
12
+ @checksums.merge!(:sha256 => p.sha256) if p.try(:sha256)
13
+ @name = p.try(:package).try(:name)
14
+ @version = p.try(:package).try(:version)
15
+ elsif p.is_a? Package
16
+ @name = p.name
17
+ @version = p.version
18
+ end
19
+
20
+ @name = fname unless fname.blank?
21
+ end
22
+
23
+ def download_cache_dir
24
+ dir = Smithy::Config.global[:"download-cache"]
25
+ dir = File.join(ENV['HOME'], '.smithy/cache') if dir.blank?
26
+ dir
27
+ end
28
+
29
+ def downloaded_file_name
30
+ url_filename(url)
31
+ end
32
+
33
+ def downloaded_file_dir
34
+ File.join(download_cache_dir, name, version)
35
+ end
36
+
37
+ def downloaded_file_path
38
+ File.join(downloaded_file_dir, downloaded_file_name)
39
+ end
40
+
41
+ def downloaded?
42
+ File.exists?(downloaded_file_path)
43
+ end
44
+
45
+ def checksum_download
46
+ return true if checksums.empty?
47
+ return false unless downloaded?
48
+
49
+ checksums.keys.each do |type|
50
+ checksum = checksums[type]
51
+ digest = ''
52
+ case type
53
+ when :md5
54
+ require 'digest/md5'
55
+ digest = Digest::MD5.hexdigest(File.read(downloaded_file_path))
56
+ when :sha1
57
+ require 'digest/sha1'
58
+ digest = Digest::SHA1.hexdigest(File.read(downloaded_file_path))
59
+ when :sha256
60
+ require 'digest/sha2'
61
+ digest = Digest::SHA256.hexdigest(File.read(downloaded_file_path))
62
+ end
63
+
64
+ if checksum != digest
65
+ raise <<-EOF.strip_heredoc
66
+ file does not match expected #{type.to_s.upcase} checksum
67
+ expected: #{checksum}
68
+ got: #{digest}
69
+ EOF
70
+ else
71
+ return true
72
+ end
73
+ end
74
+ end
75
+
76
+ def download
77
+ curl = '/usr/bin/curl'
78
+ curl = `which curl` unless File.exist? curl
79
+ raise "curl cannot be located, without it files cannot be downloaded" if curl.blank?
80
+
81
+ if downloaded?
82
+ puts "downloaded ".rjust(12).color(:green).bright + downloaded_file_path
83
+ return true
84
+ else
85
+ puts "download ".rjust(12).color(:green).bright + url
86
+ end
87
+
88
+ args = ['-qf#L']
89
+ args << "--silent" unless $stdout.tty?
90
+ args << '-o'
91
+ args << downloaded_file_path
92
+ args << url
93
+
94
+ FileUtils.mkdir_p downloaded_file_dir
95
+ [downloaded_file_dir, File.join(downloaded_file_dir, '..')].each do |dir|
96
+ FileOperations.set_group(dir, Smithy::Config.global[:"file-group-name"])
97
+ FileOperations.make_group_writable(dir) unless Smithy::Config.global[:"disable-group-writable"]
98
+ end
99
+
100
+ if system(curl, *args)
101
+ FileOperations.set_group(downloaded_file_path, Smithy::Config.global[:"file-group-name"])
102
+ FileOperations.make_group_writable(downloaded_file_path) unless Smithy::Config.global[:"disable-group-writable"]
103
+ return true
104
+ else
105
+ return false
106
+ end
107
+ end
108
+
109
+ def get(passed_url= nil)
110
+ @url = passed_url if passed_url
111
+ if download && checksum_download
112
+ return downloaded_file_path
113
+ else
114
+ return false
115
+ end
116
+ end
117
+
118
+ end
119
+ end
120
+