summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/context/lua/mtx-cache.lua
diff options
context:
space:
mode:
authorTaco Hoekwater <taco@elvenkind.com>2008-06-12 10:42:53 +0000
committerTaco Hoekwater <taco@elvenkind.com>2008-06-12 10:42:53 +0000
commit0d01365d53c456d246da0ca1f0b3cd9868f02b35 (patch)
tree01a655c8028e17cfb371456b299c1848fe08c05b /Master/texmf-dist/scripts/context/lua/mtx-cache.lua
parent44f3714442da07fdfc36a7f2a8dcd5d4294c5d26 (diff)
ConTeXt release 2008.05.21
git-svn-id: svn://tug.org/texlive/trunk@8691 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/context/lua/mtx-cache.lua')
-rw-r--r--Master/texmf-dist/scripts/context/lua/mtx-cache.lua99
1 files changed, 99 insertions, 0 deletions
diff --git a/Master/texmf-dist/scripts/context/lua/mtx-cache.lua b/Master/texmf-dist/scripts/context/lua/mtx-cache.lua
new file mode 100644
index 00000000000..8091eaa6515
--- /dev/null
+++ b/Master/texmf-dist/scripts/context/lua/mtx-cache.lua
@@ -0,0 +1,99 @@
+if not modules then modules = { } end modules ['mtx-cache'] = {
+ version = 1.001,
+ comment = "companion to mtxrun.lua",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+texmf.instance = instance -- we need to get rid of this / maybe current instance in global table
+
+scripts = scripts or { }
+scripts.cache = scripts.cache or { }
+
+function scripts.cache.collect_one(...)
+ local path = caches.setpath(instance,...)
+ local tmas = dir.glob(path .. "/*.tma")
+ local tmcs = dir.glob(path .. "/*.tmc")
+ return path, tmas, tmcs
+end
+
+function scripts.cache.collect_two(...)
+ local path = caches.setpath(instance,...)
+ local rest = dir.glob(path .. "/**/*")
+ return path, rest
+end
+
+function scripts.cache.process_one(action)
+ for k, v in ipairs({ "afm", "tfm", "def", "enc", "otf", "mp", "data" }) do
+ action("fonts", v)
+ end
+end
+
+function scripts.cache.process_two(action)
+ action("curl")
+end
+
+-- todo: recursive delete of paths
+
+function scripts.cache.remove(list,keep)
+ local keepsuffixes = { }
+ for _, v in ipairs(keep or {}) do
+ keepsuffixes[v] = true
+ end
+ local n = 0
+ for _,filename in ipairs(list) do
+ if filename:find("luatex%-cache") then -- safeguard
+ if not keepsuffixes[file.extname(filename) or ""] then
+ os.remove(filename)
+ n = n + 1
+ end
+ end
+ end
+ return n
+end
+
+function scripts.cache.delete(all,keep)
+ scripts.cache.process_one(function(...)
+ local path, rest = scripts.cache.collect_one(...)
+ local n = scripts.cache.remove(rest,keep)
+ logs.report("cache path",string.format("%4i files out of %4i deleted on %s",n,#rest,path))
+ end)
+ scripts.cache.process_two(function(...)
+ local path, rest = scripts.cache.collect_two(...)
+ local n = scripts.cache.remove(rest,keep)
+ logs.report("cache path",string.format("%4i files out of %4i deleted on %s",n,#rest,path))
+ end)
+end
+
+function scripts.cache.list(all)
+ scripts.cache.process_one(function(...)
+ local path, tmas, tmcs = scripts.cache.collect_one(...)
+ logs.report("cache path",string.format("%4i (tma:%4i, tmc:%4i) %s",#tmas+#tmcs,#tmas,#tmcs,path))
+ logs.report("cache path",string.format("%4i (tma:%4i, tmc:%4i) %s",#tmas+#tmcs,#tmas,#tmcs,path))
+ end)
+ scripts.cache.process_two(function(...)
+ local path, rest = scripts.cache.collect_two("curl")
+ logs.report("cache path",string.format("%4i %s",#rest,path))
+ end)
+end
+
+banner = banner .. " | cache tools "
+
+messages.help = [[
+--purge remove not used files
+--erase completely remove cache
+--list show cache
+
+--all all (not yet implemented)
+]]
+
+if environment.argument("purge") then
+ scripts.cache.delete(environment.argument("all"),{"tmc"})
+elseif environment.argument("erase") then
+ scripts.cache.delete(environment.argument("all"))
+elseif environment.argument("list") then
+ scripts.cache.list(environment.argument("all"))
+else
+ input.help(banner,messages.help)
+end