summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/context/lua/mtx-watch.lua
diff options
context:
space:
mode:
authorTaco Hoekwater <taco@elvenkind.com>2009-08-23 11:11:32 +0000
committerTaco Hoekwater <taco@elvenkind.com>2009-08-23 11:11:32 +0000
commit8fc3039c82d48605b5ca8b2eda3f4fdd755681e1 (patch)
tree3cd9bbdd599bc4d1ac0409e167fee2136e4c0ec9 /Master/texmf-dist/scripts/context/lua/mtx-watch.lua
parent850fc99b7cd3ae7a20065531fe866ff7bae642ec (diff)
this is context 2009.08.19 17:10
git-svn-id: svn://tug.org/texlive/trunk@14827 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/context/lua/mtx-watch.lua')
-rw-r--r--Master/texmf-dist/scripts/context/lua/mtx-watch.lua49
1 files changed, 41 insertions, 8 deletions
diff --git a/Master/texmf-dist/scripts/context/lua/mtx-watch.lua b/Master/texmf-dist/scripts/context/lua/mtx-watch.lua
index f9e81da4257..2e4dcf6efec 100644
--- a/Master/texmf-dist/scripts/context/lua/mtx-watch.lua
+++ b/Master/texmf-dist/scripts/context/lua/mtx-watch.lua
@@ -6,13 +6,29 @@ if not modules then modules = { } end modules ['mtx-watch'] = {
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.watch = scripts.watch or { }
do
+ function scripts.watch.save_exa_modes(joblog,ctmname)
+ local t= { }
+ if joblog then
+ t[#t+1] = "<?xml version='1.0' standalone='yes'?>\n"
+ t[#t+1] = "<exa:variables xmlns:exa='htpp://www.pragma-ade.com/schemas/exa-variables.rng'>"
+ if joblog.values then
+ for k, v in pairs(joblog.values) do
+ t[#t+1] = string.format("\t<exa:variable label='%s'>%s</exa:variable>", k, tostring(v))
+ end
+ else
+ t[#t+1] = "<!-- no modes -->"
+ end
+ t[#t+1] = "</exa:variables>"
+ end
+ os.remove(ctmname)
+ io.savedata(ctmname,table.concat(t,"\n"))
+ end
+
function scripts.watch.watch()
local delay = environment.argument("delay") or 5
local logpath = environment.argument("logpath") or ""
@@ -42,6 +58,20 @@ do
end
end
end
+ local function toset(t)
+ if type(t) == "table" then
+ return table.concat(t,",")
+ else
+ return t
+ end
+ end
+ local function noset(t)
+ if type(t) == "table" then
+ return t[1]
+ else
+ return t
+ end
+ end
local function process()
local done = false
for _, path in ipairs(environment.files) do
@@ -61,8 +91,8 @@ do
local command = joblog.command
if command then
local replacements = {
- inputpath = (joblog.paths and joblog.paths.input ) or ".",
- outputpath = (joblog.paths and joblog.paths.output) or ".",
+ inputpath = toset((joblog.paths and joblog.paths.input ) or "."),
+ outputpath = noset((joblog.paths and joblog.paths.output) or "."),
filename = joblog.filename or "",
}
command = command:gsub("%%(.-)%%", replacements)
@@ -74,12 +104,17 @@ do
local newpath = file.dirname(name)
io.flush()
local result = ""
+ local ctmname = file.basename(replacements.filename)
+ if ctmname == "" then ctmname = name end -- use self as fallback
+ ctmname = file.replacesuffix(ctmname,"ctm")
if newpath ~= "" and newpath ~= "." then
local oldpath = lfs.currentdir()
lfs.chdir(newpath)
+ scripts.watch.save_exa_modes(joblog,ctmname)
if pipe then result = os.resultof(command) else result = os.spawn(command) end
lfs.chdir(oldpath)
else
+ scripts.watch.save_exa_modes(joblog,ctmname)
if pipe then result = os.resultof(command) else result = os.spawn(command) end
end
logs.report("watch",string.format("return value: %s", result))
@@ -204,7 +239,7 @@ function scripts.watch.show_logs(path) -- removes duplicates
end
end
-banner = banner .. " | watchdog"
+logs.extendbanner("Watchdog 1.00",true)
messages.help = [[
--logpath optional path for log files
@@ -215,8 +250,6 @@ messages.help = [[
--showlog show log data
]]
-input.verbose = true
-
if environment.argument("watch") then
scripts.watch.watch()
elseif environment.argument("collect") then
@@ -224,5 +257,5 @@ elseif environment.argument("collect") then
elseif environment.argument("showlog") then
scripts.watch.show_logs()
else
- input.help(banner,messages.help)
+ logs.help(messages.help)
end