File: version.in

package info (click to toggle)
modules 5.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 22,996 kB
  • sloc: exp: 79,667; sh: 6,142; tcl: 5,895; makefile: 1,478; ansic: 474; python: 272; csh: 202; perl: 47; ruby: 44; lisp: 13
file content (65 lines) | stat: -rw-r--r-- 2,255 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#%Module

module-help {    version - initializes new version of the module command.}
module-help "    Version $::version"
module-help {}

module-whatis {initializes new version of the module command}

# for Tcl script use only
set version @VERSION@
set shell [module-info shell]

# get rid of old version
if {[module-info mode] in {load display}} {
    module unload --not-req null
    module unload --not-req modules
    setenv MODULE_VERSION @VERSION@
}

# version stack
prepend-path MODULE_VERSION_STACK @VERSION@

if {[module-info mode remove]} {
    # unload modules modulefile to get PATHs refreshed after previous module
    # command restoration
    module load modules
    set prevversion [lindex [split $env(MODULE_VERSION_STACK) :] 0]
    unsetenv MODULE_VERSION $prevversion

    # re-initialize previous module command version by sourcing its
    # initialization script, as module function definition is not compatible
    # between Modules 3 and Modules 4
    switch -- $shell {
        sh - bash - ksh - zsh - csh - tcsh - fish {
            set versionre [regsub -all "\(\[.+?\]\)" $version {\\\1}]
            regsub $versionre "@initdir@/$shell" $prevversion previnitshell
            if {[file exists $previnitshell]} {
                switch -- $shell {
                    sh - bash - ksh - zsh {
                        set sourcecmd .
                    }
                    csh - tcsh - fish {
                        set sourcecmd source
                    }
                }
                puts stdout "$sourcecmd $previnitshell"
                puts stdout {module load modules}
            } else {
                puts stderr "No initialization script for '$shell' on version '$prevversion'"
            }
        }
        default {
            # no support for re-initializing module command on scripting shell
            # as it is not a common practice for most of these languages to
            # redefine an already set function
            puts stderr "No re-initialization supported for '$shell' on version '$prevversion'"
        }
    }
}

# bring in new version
if {[module-info mode] in {load display}} {
    module load modules
    puts stdout [exec @TCLSH@ {@libexecdir@/modulecmd.tcl} $shell autoinit]
}