mesa_cli 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +59 -1
  3. data/bin/mesa +158 -1
  4. metadata +8 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2908874ec54278806e2984d1e0f60076bbb94e6d
4
- data.tar.gz: 7fdc828dbc702fc9bd3ce850db318f1f4300a49f
3
+ metadata.gz: 3a497f66bb80bf3e052db6cb16a5ffb001a526f1
4
+ data.tar.gz: 9a048c142c45c45fb7d32c742cecb5d504a2ac1a
5
5
  SHA512:
6
- metadata.gz: 09c4ef4e454b92891033436bb9e8625c3a2f4ac52fd8cd52573c9dc0b72625bedc6abd60920d518d2759655e703e31c1d3458e8c3a55218e4352152bf6846096
7
- data.tar.gz: 1cee8d38e282cc546c626fae00500dc66fd6fad9762f47f0b68f810715dfc4548d865d48a97f1b4dd33b23ae95e343c45d20beebfc6cfb418ee7e11f4c95292d
6
+ metadata.gz: 74ecd902c0c213c4c13a7853e1aa96286489d8695211b807673e4315e602d8f860576d60cbef2c0eb776bc30d32945d98941e18d65ce80bd880051918180d12e
7
+ data.tar.gz: f3755547aea252100207d6ed222bfb0470ff4b278d1556e28541d3ac7568e593836da14c646403bd9d78ed33e724844de652aead7c249562a4634b56ef7f4b06
data/README.md CHANGED
@@ -40,7 +40,8 @@ as detailed below.
40
40
 
41
41
  To get quick information, type `mesa help` to list the commands and see what
42
42
  they do. For detailed information on a particular command, type `mesa help
43
- command` to learn about an individual command (replacing the word "command" with the actual subcommand name). Brief summaries of commands are below.
43
+ command` to learn about an individual command (replacing the word "command"
44
+ with the actual subcommand name). Brief summaries of commands are below.
44
45
 
45
46
  ### default
46
47
 
@@ -59,6 +60,56 @@ instance,
59
60
 
60
61
  will open `$MESA_DIR/star/defaults/star_job.defaults` in vim or whatever default editor you've set up.
61
62
 
63
+ ### install
64
+
65
+ To use, just type
66
+
67
+ mesa install VERSION_NUMBER [DIR_NAME] --shell=MYSHELL
68
+
69
+ This will do a fresh checkout of mesa (version number given by VERSION_NUMBER)
70
+ into a directory (named DIR_NAME, default is mesa-rXXXX, where XXXX is the
71
+ version number). After the checkout, mesa will install, and your login scripts
72
+ will be updated to point MESA_DIR to this new installation directory.
73
+
74
+ By default, the shell is assumed to be bash, so `~/.bash_profile` and
75
+ `~/.bashrc` will be checked for instances of `MESA_DIR=` in these files, which
76
+ are then updated to point to the new installation path. If no such assignments
77
+ are found, one will be added to `~/.bash_profile` (if that file does not
78
+ exist, it will be added to `~/.bashrc`, if it exists). There is a `--shell=`
79
+ option, but it is currently useless since there is only one shell option.
80
+
81
+ Currently there is no support for the C shell, but this will be an feature in a future version. For a basic installation with no mucking around of shell scripts, add the `--basic` or `-b` flag.
82
+
83
+ Some examples:
84
+
85
+ mesa install 9999
86
+
87
+ will download and install mesa revision 9999 into a directory named
88
+ `mesa-r9999` in the current directory. It will then try to find the files
89
+ `~/.bash_profile` and `~/.bashrc`. If it finds them, it will first try to
90
+ update any lines conatining `MESA_DIR=` to point them to the new,
91
+ fully-qualified path to `mesa-r9999`. If no such lines are added, it will add
92
+ the appropriate line (`export MESA_DIR=/PATH/TO/mesa-r9999`) at the end of one
93
+ of those scripts, preferring `~/.bash_profile`.
94
+
95
+ mesa install $HOME/mesa_installations/my_latest_mesa 9999
96
+
97
+ will download and install mesa revision 9999 into the directory
98
+ `$HOME/mesa_installations/my_latest_mesa`. Then it will set `MESA_DIR` in
99
+ login scripts as in the previous example.
100
+
101
+ mesa install 9999 -b
102
+
103
+ will download and install mesa revision 9999 into a directory named
104
+ `mesa-r9999` in the current directory. It will not attempt to change login
105
+ scripts.
106
+
107
+ mesa install $HOME/mesa_installations/my_latest_mesa 9999 -b
108
+
109
+ will download and install mesa revision 9999 into the directory
110
+ `$HOME/mesa_installations/my_latest_mesa`. It will not attempt to change login
111
+ scripts.
112
+
62
113
  ### new
63
114
 
64
115
  To use, just type
@@ -117,6 +168,13 @@ from this process is `inlist_test_suite` which currently only serves to set
117
168
  the `mesa_dir` via a local path, so references to this inlist are always
118
169
  deleted.
119
170
 
171
+ ### version
172
+
173
+ To use, just type
174
+
175
+ mesa version
176
+
177
+ This will just print out the version number of mesa that is currently installed in your MESA_DIR.
120
178
 
121
179
 
122
180
 
data/bin/mesa CHANGED
@@ -8,7 +8,20 @@ rescue LoadError
8
8
  $use_mesascript = false
9
9
  end
10
10
 
11
+ ALL_POSSIBLE_SCRIPTS = {"bash" => [".bash_profile", ".bashrc"]}
12
+
11
13
  class MyCLI < Thor
14
+ desc "version", "Display the version number of currently installed MESA."
15
+
16
+ def version
17
+ return unless check_for_mesa_dir
18
+ v_num = IO.read(File.join(ENV['MESA_DIR'], 'data', 'version_number')).to_i
19
+ puts v_num
20
+ return v_num
21
+ end
22
+
23
+
24
+
12
25
  option :simple, :type => :boolean, :aliases => :s,
13
26
  :desc => "Just copy work directory and rename it. Nothing done with " +
14
27
  "MesaScript."
@@ -178,6 +191,84 @@ class MyCLI < Thor
178
191
  system("#{editor} #{File.join(defaults_dir, filename)}#{suffix}")
179
192
  end
180
193
 
194
+ desc "install VER_NUMBER [DIR_NAME]", "Installs mesa version VER_NUMBER."
195
+ long_desc <<-LONGDESC
196
+ Installs a user-specified version of MESA (latest version number is typically
197
+ found at http://mesa.sourceforge.net/prereqs.html). The login scripts will
198
+ also be updated to have the MESA_DIR environment variable point to the new
199
+ installation location. Currently only the Bourne again shell (bash) is
200
+ supported, though the actual installation (without login script adjustments)
201
+ can still be accomplished in other shells.
202
+ LONGDESC
203
+ method_option :shell, :type => "string", :aliases => "-s", :default => "bash",
204
+ :required => "true", :desc => "The shell to be used when editing login "+
205
+ "scripts. Default is 'bash'. Currently no other options."
206
+ method_option :basic, :type => "boolean", :aliases => "-b", :desc => "Force "+
207
+ "a basic installation, which skips any manipulation of login scripts."
208
+
209
+ def install(ver_number, custom_name=nil)
210
+
211
+ # download proper version of MESA via SVN
212
+ puts "Downloading MESA version #{ver_number}. This will take awhile."
213
+ puts ''
214
+ dir_name = custom_name || "mesa-r#{ver_number}"
215
+ dir_name = File.absolute_path(dir_name)
216
+ system("svn co -r #{ver_number} " +
217
+ "svn://svn.code.sf.net/p/mesa/code/trunk #{dir_name}")
218
+ puts "Downloaded MESA version #{ver_number}."
219
+ puts ''
220
+
221
+ # install MESA
222
+ unless have_mesasdk?
223
+ puts "Installation failed: MESA SDK not set up properly."
224
+ puts ''
225
+ return
226
+ end
227
+ puts "Now installing. This will take awhile."
228
+ puts ''
229
+ start_dir = FileUtils::pwd
230
+ FileUtils::cd dir_name
231
+ system("./clean")
232
+ system("./install")
233
+ FileUtils::cd(start_dir)
234
+
235
+ # detect login scripts
236
+ shell = options[:shell]
237
+ possible_scripts = ALL_POSSIBLE_SCRIPTS[shell] || []
238
+
239
+ # stop if basic installation or if we don't know how to handle the shell
240
+
241
+ if options[:basic] or possible_scripts.empty?
242
+ if possible_scripts.empty? and not options[:basic]
243
+ puts "Don't know how to adjust login scripts for shell #{shell}. Exiting."
244
+ puts ''
245
+ end
246
+ puts "Installed MESA version #{ver_number} in #{dir_name}. Your login " +
247
+ "scripts likely still need to be updated. See \"Set your environment " +
248
+ "variables\" in http://mesa.sourceforge.net/prereqs.html for details."
249
+ puts ''
250
+ return
251
+ end
252
+
253
+ # detect login scripts
254
+ possible_scripts.map! { |script| File.join(ENV['HOME'], script) }
255
+ login_scripts = []
256
+ possible_scripts.each do |script|
257
+ login_scripts << script if File.exist?(script)
258
+ end
259
+
260
+ # update login scripts to set MESA_DIR properly
261
+ have_fixed = login_scripts.empty?
262
+ login_scripts.each do |script|
263
+ fixed_this_one = adjust_script(script, dir_name, shell)
264
+ have_fixed = fixed_this_one unless have_fixed
265
+ end
266
+
267
+ # add MESA_DIR assignment if none are present, favoring .bash_profile
268
+ unless (have_fixed or login_scripts.empty?)
269
+ script = login_scripts[0]
270
+ end
271
+ end
181
272
 
182
273
  private
183
274
  def create_ms_file(inlist_name, ms_name)
@@ -190,7 +281,18 @@ class MyCLI < Thor
190
281
  def check_for_mesa_dir
191
282
  return true if ENV['MESA_DIR']
192
283
 
193
- puts "WARNING: No environment variable $MESA_DIR found. Exiting."
284
+ puts "WARNING: No environment variable MESA_DIR found. Exiting."
285
+ return false
286
+ end
287
+
288
+ def have_mesasdk?
289
+ return true if ENV['MESASDK_ROOT']
290
+
291
+ puts "No environment variable MESASDK_ROOT found. Be sure to download and "+
292
+ "install the latest MESA SDK for your system from "+
293
+ "http://www.astro.wisc.edu/~townsend/static.php?ref=mesasdk, being sure to"+
294
+ "set the MESASDK_ROOT environment variable and sourcing the SDK " +
295
+ "initialization script."
194
296
  return false
195
297
  end
196
298
 
@@ -206,6 +308,61 @@ class MyCLI < Thor
206
308
  extra_pgstar_inlist1_name pgstar
207
309
  end
208
310
  end
311
+
312
+ def adjust_script(script, dir_name, shell="bash")
313
+ have_fixed = false
314
+ case shell
315
+ when "bash"
316
+ # read in script to array of strings
317
+ contents = IO.readlines(script)
318
+
319
+ # identify lines with MESA_DIR assignment
320
+ lines_to_fix = []
321
+ contents.each_with_index do |line, i|
322
+ if line =~ /export MESA_DIR=.*/
323
+ lines_to_fix << i
324
+ end
325
+ end
326
+
327
+ # adjust MESA_DIR location and document changes
328
+ lines_to_fix.reverse.each do |i|
329
+ have_fixed = true
330
+ line = contents[i]
331
+ contents[i].sub!(/=.*/, "=#{dir_name}")
332
+ contents.insert(i-1, '# ' + "Changed MESA_DIR to #{dir_name} on " +
333
+ "#{Time.now.ctime} from mesa install script.")
334
+ end
335
+
336
+ # write out adjusted contents to file
337
+ if have_fixed
338
+ IO.write(script, contents.join)
339
+ puts "Adjusted MESA_DIR variable in #{script}."
340
+ end
341
+
342
+ else
343
+ raise "Cannot adjust #{script} because shell \"#{shell}\" is unsupported."
344
+ end
345
+ return have_fixed
346
+ end
347
+
348
+ def add_assignment_to_script(script, dir_name, shell="bash")
349
+ contents = IO.readlines(script)
350
+ contents << "\n"
351
+ contents << '# Added by mesa install tool on ' + Time.now.to_s + ".\n"
352
+ contents << assignment_line('MESA_DIR', dir_name, shell)
353
+ IO.write(script, contents.join)
354
+ puts "Added MESA_DIR environment variable to #{script}."
355
+ end
356
+
357
+ def assignment_line(var_name, value, shell)
358
+ case shell
359
+ when bash
360
+ "export #{var_name}=#{value}\n"
361
+ else
362
+ raise "Cannot make assignments for shell #{shell} because #{shell} is " +
363
+ "not a supported shell."
364
+ end
365
+ end
209
366
  end
210
367
 
211
368
  MyCLI.start(ARGV)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mesa_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Wolf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-30 00:00:00.000000000 Z
11
+ date: 2015-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.1.2
33
+ version: 0.1.4
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.1.2
40
+ version: 0.1.4
41
41
  description: " MESA CLI is a command-line interface for doing several tasks with
42
42
  Modules\n for Experiments in Stellar Astrophysics (MESA; mesa.sourceforge.net).
43
43
  This\n package includes one executable, `mesa`. Actions are performed by entering\n
@@ -59,7 +59,10 @@ homepage: https://wmwolf.github.io
59
59
  licenses:
60
60
  - MIT
61
61
  metadata: {}
62
- post_install_message:
62
+ post_install_message: " Thanks for installing mesa_cli!\n\n To learn more about
63
+ how to use the mesa command line tool and to keep up to\n date with its features,
64
+ check out the README at the project homepage:\n\n https://github.com/wmwolf/mesa_cli\n
65
+ \ \n"
63
66
  rdoc_options: []
64
67
  require_paths:
65
68
  - lib