-
Notifications
You must be signed in to change notification settings - Fork 122
/
MC_ComputeHash.lua
193 lines (173 loc) · 7.31 KB
/
MC_ComputeHash.lua
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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
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
138
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
--------------------------------------------------------------------------
-- This class is used to detect when a module file changes
-- in a way that will tell the user that their collection
-- of modules has to be reformed. The problem is that if
-- a modulefile changes the directory that it prepends to
-- MODULEPATH or prereq or conflicts change, then the
-- current is considered no-longer valid.
--
-- The way this works is that this class sets most Lmod functions to be
-- quiet. Mainly any loads, or changes to MODULEPATH generate output.
-- This output is collect into the array *ShowResultsA*.
-- Then the command computeHashSum takes that array output and computes
-- either mdsum or sha1sum of the text. When a collection is stored,
-- this hash sum is computed. When a collection is reloaded the hash sum
-- is recomputed for each modulefile. If the sums are different then
-- the collection is no longer valid.
-- @classmod MC_ComputeHash
require("strict")
--------------------------------------------------------------------------
-- Lmod License
--------------------------------------------------------------------------
--
-- Lmod is licensed under the terms of the MIT license reproduced below.
-- This means that Lmod is free software and can be used for both academic
-- and commercial purposes at absolutely no cost.
--
-- ----------------------------------------------------------------------
--
-- Copyright (C) 2008-2017 Robert McLay
--
-- Permission is hereby granted, free of charge, to any person obtaining
-- a copy of this software and associated documentation files (the
-- "Software"), to deal in the Software without restriction, including
-- without limitation the rights to use, copy, modify, merge, publish,
-- distribute, sublicense, and/or sell copies of the Software, and to
-- permit persons to whom the Software is furnished to do so, subject
-- to the following conditions:
--
-- The above copyright notice and this permission notice shall be
-- included in all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
-- BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
-- ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-- THE SOFTWARE.
--
--------------------------------------------------------------------------
require("utils")
local MasterControl = require("MasterControl")
MC_ComputeHash = inheritsFrom(MasterControl)
MC_ComputeHash.my_name = "MC_ComputeHash"
MC_ComputeHash.my_sType = "load"
MC_ComputeHash.my_tcl_mode = "load"
local M = MC_ComputeHash
local dbg = require("Dbg"):dbg()
local A = ShowResultsA
local function ShowCmd(name, ...)
A[#A+1] = ShowCmdStr(name, ...)
end
M.add_property = MasterControl.quiet
M.execute = MasterControl.quiet
M.help = MasterControl.quiet
M.inherit = MasterControl.quiet
M.myFileName = MasterControl.myFileName
M.myModuleFullName = MasterControl.myModuleFullName
M.myModuleUsrName = MasterControl.myModuleUsrName
M.myModuleName = MasterControl.myModuleName
M.myModuleVersion = MasterControl.myModuleVersion
M.pushenv = MasterControl.quiet
M.remove_property = MasterControl.quiet
M.report = MasterControl.quiet
M.set_alias = MasterControl.quiet
M.set_shell_function = MasterControl.quiet
M.setenv = MasterControl.quiet
M.unset_alias = MasterControl.quiet
M.unset_alias = MasterControl.quiet
M.unset_shell_function = MasterControl.quiet
M.unsetenv = MasterControl.quiet
M.whatis = MasterControl.quiet
M.family = MasterControl.quiet
M.prereq = MasterControl.quiet
M.prereq_any = MasterControl.quiet
M.conflict = MasterControl.quiet
M.error = MasterControl.quiet
M.message = MasterControl.quiet
--------------------------------------------------------------------------
-- Print always_load and arguments
-- @param self A MasterControl object
-- @param mA An array of module names (MName objects)
function M.always_load(self, mA)
A[#A+1] = ShowCmdA("always_load", mA)
end
--------------------------------------------------------------------------
-- Print always_unload and arguments
-- @param self A MasterControl object
-- @param mA An array of module names (MName objects)
function M.always_unload(self, mA)
A[#A+1] = ShowCmdA("always_unload", mA)
end
--------------------------------------------------------------------------
-- Print prepend_path command iff the env var. is MODULEPATH.
-- @param self A MasterControl object
-- @param t input table
function M.prepend_path(self, t)
local name = t[1]
if (name ~= "MODULEPATH") then return end
ShowCmd("prepend_path", name, t[2], t.sep)
end
--------------------------------------------------------------------------
-- Print append_path command iff the env var. is MODULEPATH.
-- @param self A MasterControl object
-- @param t input table
function M.append_path(self, t)
local name = t[1]
if (name ~= "MODULEPATH") then return end
ShowCmd("append_path", name, t[2], t.sep)
end
--------------------------------------------------------------------------
-- Print remove_path command iff the env var. is MODULEPATH.
-- @param self A MasterControl object
-- @param t input table
function M.remove_path(self, t)
local name = t[1]
if (name ~= "MODULEPATH") then return end
ShowCmd("remove_path", name, t[2], t.sep)
end
--------------------------------------------------------------------------
-- Print load command.
-- @param self A MasterControl object
-- @param mA An array of module names (MName objects)
function M.load(self, mA)
A[#A+1] = ShowCmdA("load", mA)
end
--------------------------------------------------------------------------
-- Print depends_on command.
-- @param self A MasterControl object
-- @param mA An array of module names (MName objects)
function M.depends_on(self, mA)
A[#A+1] = ShowCmdA("depends_on", mA)
end
--------------------------------------------------------------------------
-- Print load command.
-- @param self A MasterControl object
-- @param mA An array of module names (MName objects)
function M.load_usr(self, mA)
A[#A+1] = ShowCmdA("load", mA)
end
--------------------------------------------------------------------------
-- Print try_load command.
-- @param self A MasterControl object
-- @param mA An array of module names (MName objects)
function M.try_load(self, mA)
A[#A+1] = ShowCmdA("try_load", mA)
end
M.try_add = M.try_load
--------------------------------------------------------------------------
-- Print the inherit command.
-- @param self A MasterControl object
function M.inherit(self, ...)
ShowCmd("inherit",...)
end
--------------------------------------------------------------------------
-- Print the unload command.
-- @param self A MasterControl object
-- @param mA An array of module names (MName objects)
function M.unload(self, mA)
A[#A+1] = ShowCmdA("unload", mA)
end
return M