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
|
#!/usr/bin/env lua
--------------------------------------------------------------------------
-- 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-2016 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.
--
--------------------------------------------------------------------------
-- cache_check.lua - intended to be hooked or cron'd
-- does a quick check of all modules in module_dir for corresponding entry in dbT.lua in system_cache
-- prints modules from module_dir not in dbT.lua cache on STDOUT, otherwise is quiet
-- cache_check.lua -c system_cache_dir_containing_dbT.lua -m module_dir
-- Ben McGough bmcgough@fredhutch.org 8.8.16
local lfs = require("lfs")
cachedir = ""
moduledir = ""
exit_value = 0
function check_module(mod)
for pkg_name, pkgT in pairs(dbT) do
for cached_mod, modT in pairs(dbT[pkg_name]) do
if cached_mod == mod then
return
end
end
end
exit_value = 1
print("module "..mod.." is not in cache at "..cachedir)
return
end
function scan_dir(directory)
for file in lfs.dir(directory) do
full_filename = directory..file
if lfs.attributes(full_filename, "mode") == "file" then
check_module(full_filename)
elseif lfs.attributes(full_filename, "mode") == "directory" then
if file == "." or file == ".." then
else
scan_dir(full_filename.."/")
end
end
end
return
end
function argparse()
for i, v in ipairs(arg) do
if v == "-h" or v == "--help" then
exit_value = 1
usage()
end
if v == "-c" then
cachedir = arg[i+1]
end
if v == "-m" then
moduledir = arg[i+1]
if string.sub(moduledir,-1) ~= "/" then
moduledir = moduledir.."/"
end
end
end
if cachedir == "" or moduledir == "" then
exit_value = 1
usage()
end
end
function usage()
print("Usage: arg[0] -c system_cache_dir -m module_dir")
os.exit(exit_value)
end
argparse()
dofile(cachedir.."/dbT.lua")
scan_dir(moduledir)
os.exit(exit_value)
|