Skip to content

Commit

Permalink
Support for spiderPathFilter hook added
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert McLay committed Sep 9, 2021
1 parent dd78f41 commit 8d64851
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 23 deletions.
2 changes: 2 additions & 0 deletions README.new
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ Lmod 8.5+
* Change MasterControl:myShellType() to use Shell:type() and change shells to report
have local variable myType.
* Issue #528: Added support for the RC shell.
(8.5.14) * Added spiderPathFilter hook so that sites can control what paths are kept or ignored.

7 changes: 7 additions & 0 deletions docs/source/170_hooks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ Hook functions
property table. See *rt/uitSitePkg/mf/site_scripts/SitePackage.lua*
for a complete example.

**spiderPathFilter** (keepA, ignoreA):
This hook returns two arrays: *keepA* and *ignoreA*. The *keepA* is
an array of paths patterns that a site wishes to be stored in the spider
cache. The *ignoreA* is an array of path patterns to ignore in the
cache. See *src/StandardPackage.lua* has an example on how to
implement this hook.


Example Hook: msgHook
---------------------
Expand Down
2 changes: 2 additions & 0 deletions src/Hook.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ local validT =
isVisibleHook = false, -- Called to evalate if a module should be hidden or not
spider_decoration = false, -- This hook adds decoration to spider level one output.
-- It can be the category or a property.
spiderPathFilter = false, -- This hook returns two arrays keepA, ignoreA to keep or
-- ignore a path in the spider cache
}

--------------------------------------------------------------------------
Expand Down
24 changes: 24 additions & 0 deletions src/StandardPackage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,28 @@ end

hook.register("groupName",groupName)

local ignoreA = {
"^$",
"^%.$",
"^%$",
"^%%",
"^/bin/",
"^/bin$",
"^/sbin$",
"^/usr/bin$",
"^/usr/sbin$",
"^/usr/local/share/bin$",
"^/usr/lib/?",
"^/opt/local/bin$",
}

local keepA = {}

local function spiderPathFilterHook(keepA, ignoreA)
return
end

hook.register("spiderPathFilter",spiderPathFilterHook)


sandbox_registration { Pkg = Pkg }
42 changes: 19 additions & 23 deletions src/spider.in.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,38 +113,26 @@ local Spider = require("Spider")
local concatTbl = table.concat
local cosmic = require("Cosmic"):singleton()
local dbg = require("Dbg"):dbg()
local hook = require("Hook")
local i18n = require("i18n")
local lfs = require("lfs")
local sort = table.sort
local pack = (_VERSION == "Lua 5.1") and argsPack or table.pack -- luacheck: compat


local ignoreA = {
"^$",
"^%.$",
"^%$",
"^%%",
"^/bin/",
"^/bin$",
"^/sbin$",
"^/usr/bin$",
"^/usr/sbin$",
"^/usr/local/share/bin$",
"^/usr/lib/?",
"^/opt/local/bin$",
}

-- key: /opt/apps/gcc-4_8/mpich/3.1.1,
-- path: /opt/apps/gcc-4_8/mpich/3.1.1/lib, i: nil, j: nil


local keepA = {}
local ignoreA = {}
hook.apply("spiderPathFilter", keepA,ignoreA)

--------------------------------------------------------------------------
-- Check path against the *ignoreT* table. Also it must be "in" dirA if
-- dirA exists.
-- @param path input path.
local function keepThisPath2(path, dirA)
dbg.start{"keepThisPath2(",path,", dirA)"}
local function l_keepThisPath(path, dirA)
dbg.start{"l_keepThisPath(",path,", dirA)"}

if (dirA) then
local match = false
Expand All @@ -158,20 +146,28 @@ local function keepThisPath2(path, dirA)
end
if (not match) then
dbg.print{"No match\n"}
dbg.fini("keepThisPath2")
dbg.fini("l_keepThisPath")
return false
end
end

for i = 1, #keepA do
if (path:find(keepA[i])) then
dbg.print{"In keepA list: path:",path,"\n"}
dbg.fini("l_keepThisPath")
return true
end
end

for i = 1, #ignoreA do
if (path:find(ignoreA[i])) then
dbg.print{"In ignore list\n"}
dbg.fini("keepThisPath2")
dbg.print{"In ignore list: path:",path,"\n"}
dbg.fini("l_keepThisPath")
return false
end
end
dbg.print{"Keep: true\n"}
dbg.fini("keepThisPath2")
dbg.fini("l_keepThisPath")
return true
end

Expand All @@ -186,7 +182,7 @@ local function add2map(entry, tbl, dirA, moduleFn, kind, rmapT)
for path in pairs(tbl) do
local attr = lfs.attributes(path)
local a = attr or {}
local keep = keepThisPath2(path,dirA)
local keep = l_keepThisPath(path,dirA)
dbg.print{"path: ",path,", keep: ",keep,", attr.mode: ",a.mode,"\n"}

if (keep and attr and attr.mode == "directory") then
Expand Down

0 comments on commit 8d64851

Please sign in to comment.