mtx-cache.lua /size: 3691 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
mtx-cache
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to mtxrun.lua
"
,
4
author
=
"
Hans Hagen, PRAGMA-ADE, Hasselt NL
"
,
5
copyright
=
"
PRAGMA ADE / ConTeXt Development Team
"
,
6
license
=
"
see context related readme files
"
7
}
8 9
local
helpinfo
=
[[
10<?xml version="1.0"?> 11<application> 12 <metadata> 13 <entry name="name">mtx-cache</entry> 14 <entry name="detail">ConTeXt &amp; MetaTeX Cache Management</entry> 15 <entry name="version">1.01</entry> 16 </metadata> 17 <flags> 18 <category name="basic"> 19 <subcategory> 20 <flag name="make"><short>generate databases and formats</short></flag> 21 <flag name="erase"><short>completely remove cache</short></flag> 22 <flag name="list"><short>show cache</short></flag> 23 </subcategory> 24 <subcategory> 25 <flag name="fonts"><short>only wipe fonts</short></flag> 26 </subcategory> 27 </category> 28 </flags> 29</application> 30
]]
31 32 33
local
find
=
string
.
find
34
local
filesuffix
,
replacesuffix
=
file
.
suffix
,
file
.
replacesuffix
35
local
isfile
=
lfs
.
isfile
36
local
remove
=
os
.
remove
37 38
local
application
=
logs
.
application
{
39
name
=
"
mtx-cache
"
,
40
banner
=
"
ConTeXt & MetaTeX Cache Management 0.10
"
,
41
helpinfo
=
helpinfo
,
42
}
43 44
local
report
=
application
.
report
45 46
scripts
=
scripts
or
{
}
47
scripts
.
cache
=
scripts
.
cache
or
{
}
48 49
local
function
collect
(
path
)
50
local
all
=
dir
.
glob
(
path
.
.
"
/**/*
"
)
51
local
ext
=
table
.
setmetatableindex
(
"
table
"
)
52
for
i
=
1
,
#
all
do
53
local
name
=
all
[
i
]
54
local
list
=
ext
[
filesuffix
(
name
)
]
55
list
[
#
list
+
1
]
=
name
56
end
57
return
ext
58
end
59 60
local
function
list
(
banner
,
path
,
ext
)
61
local
total
=
0
62
report
(
"
%s: %s
"
,
banner
,
path
)
63
report
(
)
64
for
k
,
v
in
table
.
sortedhash
(
ext
)
do
65
total
=
total
+
#
v
66
report
(
"
%-6s : %4i
"
,
k
,
#
v
)
67
end
68
report
(
)
69
report
(
"
total : %4i
"
,
total
)
70
report
(
)
71
end
72 73
local
function
erase
(
banner
,
path
,
list
)
74
report
(
"
%s: %s
"
,
banner
,
path
)
75
report
(
)
76
for
ext
,
list
in
table
.
sortedhash
(
list
)
do
77
local
gone
=
0
78
local
kept
=
0
79
for
i
=
1
,
#
list
do
80
local
filename
=
list
[
i
]
81
if
find
(
filename
,
"
luatex%-cache
"
)
then
82
remove
(
filename
)
83
if
isfile
(
filename
)
then
84
kept
=
kept
+
1
85
else
86
gone
=
gone
+
1
87
end
88
end
89
end
90
report
(
"
%-6s : %4i gone, %4i kept
"
,
ext
,
gone
,
kept
)
91
end
92
report
(
)
93
end
94 95
function
scripts
.
cache
.
make
(
)
96
os
.
execute
(
"
mtxrun --generate
"
)
97
os
.
execute
(
"
context --make
"
)
98
os
.
execute
(
"
mtxrun --script font --reload
"
)
99
end
100 101
function
scripts
.
cache
.
erase
(
)
102
local
writable
=
caches
.
getwritablepath
(
)
103
local
groups
=
collect
(
writable
)
104
list
(
"
writable path
"
,
writable
,
groups
)
105
erase
(
"
writable path
"
,
writable
,
groups
)
106
if
environment
.
argument
(
"
make
"
)
then
107
scripts
.
cache
.
make
(
)
108
end
109
end
110 111
function
scripts
.
cache
.
list
(
)
112
local
readables
=
caches
.
getreadablepaths
(
)
113
local
writable
=
caches
.
getwritablepath
(
)
114
local
groups
=
collect
(
writable
)
115
list
(
"
writable path
"
,
writable
,
groups
)
116
for
i
=
1
,
#
readables
do
117
local
readable
=
readables
[
i
]
118
if
readable
~
=
writable
then
119
local
groups
=
collect
(
readable
)
120
list
(
"
readable path
"
,
readable
,
groups
)
121
end
122
end
123
end
124 125
if
environment
.
argument
(
"
erase
"
)
then
126
scripts
.
cache
.
erase
(
)
127
elseif
environment
.
argument
(
"
list
"
)
then
128
scripts
.
cache
.
list
(
)
129
elseif
environment
.
argument
(
"
make
"
)
then
130
scripts
.
cache
.
make
(
)
131
elseif
environment
.
argument
(
"
exporthelp
"
)
then
132
application
.
export
(
environment
.
argument
(
"
exporthelp
"
)
,
environment
.
files
[
1
]
)
133
else
134
application
.
help
(
)
135
end
136