From 6ab4432f6fe56cc63e53aeb256c89f01a04fb84f Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Wed, 2 Oct 2019 13:21:40 +0200 Subject: 2019-10-02 12:50:00 --- scripts/context/lua/mtx-cache.lua | 99 +++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 55 deletions(-) (limited to 'scripts/context/lua/mtx-cache.lua') diff --git a/scripts/context/lua/mtx-cache.lua b/scripts/context/lua/mtx-cache.lua index 56d3df188..4f378ff0a 100644 --- a/scripts/context/lua/mtx-cache.lua +++ b/scripts/context/lua/mtx-cache.lua @@ -12,12 +12,12 @@ local helpinfo = [[ mtx-cache ConTeXt & MetaTeX Cache Management - 0.10 + 1.01 - remove not used files + generate databases and formats completely remove cache show cache @@ -48,97 +48,86 @@ scripts.cache = scripts.cache or { } local function collect(path) local all = dir.glob(path .. "/**/*") - local tmas, tmcs, rest = { }, { }, { } + local ext = table.setmetatableindex("table") for i=1,#all do local name = all[i] - local suffix = filesuffix(name) - if suffix == "tma" then - tmas[#tmas+1] = name - elseif suffix == "tmc" then - tmcs[#tmcs+1] = name - else - rest[#rest+1] = name - end + local list = ext[filesuffix(name)] + list[#list+1] = name end - return tmas, tmcs, rest, all + return ext end -local function list(banner,path,tmas,tmcs,rest) +local function list(banner,path,ext) + local total = 0 report("%s: %s",banner,path) report() - report("tma : %4i",#tmas) - report("tmc : %4i",#tmcs) - report("rest : %4i",#rest) - report("total : %4i",#tmas+#tmcs+#rest) + for k, v in table.sortedhash(ext) do + total = total + #v + report("%-6s : %4i",k,#v) + end + report() + report("total : %4i",total) report() end -local function purge(banner,path,list,all) +local function erase(banner,path,list) report("%s: %s",banner,path) report() - local fonts = environment.argument("fonts") - local n = 0 - for i=1,#list do - local filename = list[i] - if find(filename,"luatex%-cache") then -- safeguard - if fonts and not find(filename,"fonts") then - -- skip - elseif all then + for ext, list in table.sortedhash(list) do + local gone = 0 + local kept = 0 + for i=1,#list do + local filename = list[i] + if find(filename,"luatex%-cache") then remove(filename) - n = n + 1 - elseif not fonts or find(filename,"fonts") then - local suffix = filesuffix(filename) - if suffix == "tma" then - local checkname = replacesuffix(filename,"tma","tmc") - if isfile(checkname) then - remove(filename) - n = n + 1 - end + if isfile(filename) then + kept = kept + 1 + else + gone = gone + 1 end end end + report("%-6s : %4i gone, %4i kept",ext,gone,kept) end - report("removed tma files : %i",n) report() - return n end -function scripts.cache.purge() - local writable = caches.getwritablepath() - local tmas, tmcs, rest = collect(writable) - list("writable path",writable,tmas,tmcs,rest) - purge("writable path",writable,tmas) - list("writable path",writable,tmas,tmcs,rest) +function scripts.cache.make() + os.execute("mtxrun --generate") + os.execute("context --make") + os.execute("mtxrun --script font --reload") end function scripts.cache.erase() local writable = caches.getwritablepath() - local tmas, tmcs, rest, all = collect(writable) - list("writable path",writable,tmas,tmcs,rest) - purge("writable path",writable,all,true) - list("writable path",writable,tmas,tmcs,rest) + local groups = collect(writable) + list("writable path",writable,groups) + erase("writable path",writable,groups) + if environment.argument("make") then + scripts.cache.make() + end end function scripts.cache.list() local readables = caches.getreadablepaths() - local writable = caches.getwritablepath() - local tmas, tmcs, rest = collect(writable) - list("writable path",writable,tmas,tmcs,rest) + local writable = caches.getwritablepath() + local groups = collect(writable) + list("writable path",writable,groups) for i=1,#readables do local readable = readables[i] if readable ~= writable then - local tmas, tmcs = collect(readable) - list("readable path",readable,tmas,tmcs,rest) + local groups = collect(readable) + list("readable path",readable,groups) end end end -if environment.argument("purge") then - scripts.cache.purge() -elseif environment.argument("erase") then +if environment.argument("erase") then scripts.cache.erase() elseif environment.argument("list") then scripts.cache.list() +elseif environment.argument("make") then + scripts.cache.make() elseif environment.argument("exporthelp") then application.export(environment.argument("exporthelp"),environment.files[1]) else -- cgit v1.2.3