-
Notifications
You must be signed in to change notification settings - Fork 122
/
MC_Spider.lua
278 lines (251 loc) · 9.65 KB
/
MC_Spider.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
194
195
196
197
198
199
200
201
202
203
204
205
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
--------------------------------------------------------------------------
-- This derived class of MasterControl is how Spider reads
-- in modulefiles. It uses masterTbl() to hold the moduleStack.
-- It looks for adding paths to MODULEPATH. It also keeps track
-- of properties.
--
-- @classmod MC_Spider
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 dbg = require("Dbg"):dbg()
local concatTbl = table.concat
local hook = require("Hook")
local MasterControl = require("MasterControl")
MC_Spider = inheritsFrom(MasterControl)
MC_Spider.my_name = "MC_Spider"
MC_Spider.my_sType = "load"
MC_Spider.my_tcl_mode = "display"
local M = MC_Spider
M.always_load = MasterControl.quiet
M.always_unload = MasterControl.quiet
M.conflict = MasterControl.quiet
M.depends_on = MasterControl.quiet
M.error = MasterControl.quiet
M.execute = MasterControl.execute
M.family = MasterControl.quiet
M.inherit = MasterControl.quiet
M.load = MasterControl.quiet
M.load_usr = MasterControl.quiet
M.message = MasterControl.quiet
M.prereq = MasterControl.quiet
M.prereq_any = MasterControl.quiet
M.pushenv = MasterControl.quiet
M.remove_path = MasterControl.quiet
M.report = MasterControl.warning
M.set_alias = MasterControl.quiet
M.set_shell_function = MasterControl.quiet
M.try_load = MasterControl.quiet
M.unload = MasterControl.quiet
M.unload_usr = MasterControl.quiet
M.unsetenv = MasterControl.quiet
M.unset_alias = MasterControl.quiet
M.unset_shell_function = MasterControl.quiet
M.usrload = MasterControl.quiet
M.warning = MasterControl.warning
--------------------------------------------------------------------------
-- use the moduleStack to return the filename of the modulefile.
-- @param self A MasterControl object.
function M.myFileName(self)
local moduleStack = masterTbl().moduleStack
local iStack = #moduleStack
return moduleStack[iStack].fn
end
--------------------------------------------------------------------------
-- Use the moduleStack to return the full name of the module. This is
-- typically name/version. For Spider we assume that the user name is
-- the full name.
-- @param self A MasterControl object.
function M.myModuleFullName(self)
local moduleStack = masterTbl().moduleStack
local iStack = #moduleStack
return moduleStack[iStack].fullName
end
M.myModuleUsrName = M.myModuleFullName
--------------------------------------------------------------------------
-- Use the moduleStack to return the short name of the module.
-- @param self A MasterControl object.
function M.myModuleName(self)
local moduleStack = masterTbl().moduleStack
local iStack = #moduleStack
return moduleStack[iStack].sn
end
--------------------------------------------------------------------------
-- Use the moduleStack to return the version of the module. For meta
-- modules the version will be "".
-- @param self A MasterControl object.
function M.myModuleVersion(self)
local moduleStack = masterTbl().moduleStack
local iStack = #moduleStack
local fullName = moduleStack[iStack].fullName
local sn = moduleStack[iStack].sn
return extractVersion(fullName, sn) or ""
end
--------------------------------------------------------------------------
-- MC_Spider:help(): Collect the help message into moduleT
-- @param self A MasterControl object.
function M.help(self,...)
dbg.start{"MC_Spider:help(...)"}
local moduleStack = masterTbl().moduleStack
local iStack = #moduleStack
local path = moduleStack[iStack].path
local moduleT = moduleStack[iStack].moduleT
moduleT.help = concatTbl({...},"")
dbg.fini()
return true
end
--------------------------------------------------------------------------
-- MC_Spider:whatis(): Collect the whatis messages into moduleT
-- @param self A MasterControl object.
-- @param s whatis string.
function M.whatis(self,s)
dbg.start{"MC_Spider:whatis(...)"}
local moduleStack = masterTbl().moduleStack
local iStack = #moduleStack
local path = moduleStack[iStack].path
local moduleT = moduleStack[iStack].moduleT
local _,_, key, value = s:find('^%s*([^: ]+)%s*:%s*(.*)')
local k = KeyT[key]
if (k) then
moduleT[key] = value
end
if (moduleT.whatis == nil) then
moduleT.whatis ={}
end
moduleT.whatis[#moduleT.whatis+1] = s
dbg.fini()
return true
end
s_patLib = false
s_patDir = false
--------------------------------------------------------------------------
-- Track "LMOD_.*_LIB" and LMOD_.*_DIR environment variables or whatever
-- the site is called (See SitePackage.lua and StandardPackage.lua.)
-- @param self A MasterControl object.
-- @param name the environment variable name.
-- @param value the environment variable value.
function M.setenv(self, name, value)
dbg.start{"MC_Spider:setenv(name, value)"}
if (not s_patLib) then
local a = {}
a[#a+1] = "^"
a[#a+1] = hook.apply("SiteName")
a[#a+1] = "_.*_LIB"
s_patLib = concatTbl(a,"")
a = {}
a[#a+1] = "^"
a[#a+1] = hook.apply("SiteName")
a[#a+1] = "_.*_DIR"
s_patDir = concatTbl(a,"")
local t = {patDir = s_patDir, patLib = s_patLib}
hook.apply("packagebasename", t)
s_patDir = t.patDir
s_patLib = t.patLib
dbg.print{"Using s_patDir: ", s_patDir, " s_patLib: ", s_patLib, "\n"}
end
if (name:find(s_patLib)) then
processLPATH(value)
end
if (name:find(s_patDir)) then
processDIR(value)
end
dbg.fini()
return true
end
--------------------------------------------------------------------------
-- Pass-thru to Spider_append_path().
-- @param self A MasterControl object.
-- @param t input table.
function M.prepend_path(self,t)
dbg.start{"MC_Spider:prepend_path(t)"}
Spider_append_path("prepend",t)
dbg.fini()
return true
end
--------------------------------------------------------------------------
-- Pass-thru to Spider_append_path().
-- @param self A MasterControl object.
-- @param t input table.
function M.append_path(self,t)
dbg.start{"MC_Spider:append_path(t)"}
Spider_append_path("append",t)
dbg.fini()
return true
end
--------------------------------------------------------------------------
-- Return True when in spider mode.
-- @param self A MasterControl object.
function M.is_spider(self)
dbg.start{"MC_Spider:is_spider()"}
dbg.fini()
return true
end
--------------------------------------------------------------------------
-- Copy the property to moduleT
-- @param self A MasterControl object.
-- @param name the property name.
-- @param value the value.
function M.add_property(self, name, value)
dbg.start{"MC_Spider:add_property(name=\"",name,"\", value=\"",value,"\")"}
local moduleStack = masterTbl().moduleStack
local iStack = #moduleStack
local path = moduleStack[iStack].path
local moduleT = moduleStack[iStack].moduleT
local t = moduleT.propT or {}
t[name] = t[name] or {}
t[name][value] = 1
moduleT.propT = t
dbg.fini()
return true
end
--------------------------------------------------------------------------
-- MC_Spider:remove_property: Remove the property to moduleT
-- @param self A MasterControl object.
-- @param name the of the property.
-- @param value the value.
function M.remove_property(self, name, value)
dbg.start{"MC_Spider:remove_property(name=\"",name,"\", value=\"",value,"\")"}
local moduleStack = masterTbl().moduleStack
local iStack = #moduleStack
local path = moduleStack[iStack].path
local moduleT = moduleStack[iStack].moduleT
local t = moduleT.propT or {}
t[name] = t[name] or {}
t[name][value] = nil
moduleT.propT = t
dbg.fini()
return true
end
return M