summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNorbert Preining <preining@logic.at>2008-07-22 06:32:31 +0000
committerNorbert Preining <preining@logic.at>2008-07-22 06:32:31 +0000
commit820735ab6c6dfe255c36807a1e389e7ca3271b01 (patch)
tree88aef1b183619237088c65b68b895777343ea979
parentb237791ce66ebc6f9cb18141774b22ca94958d92 (diff)
add a texlua tlpdb reading module, and a test function
git-svn-id: svn://tug.org/texlive/trunk@9696 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Master/texmf/scripts/texlive/lua/texlive/tlpdb.tlu236
-rwxr-xr-xMaster/texmf/scripts/texlive/test-tlpdb.tlu45
2 files changed, 281 insertions, 0 deletions
diff --git a/Master/texmf/scripts/texlive/lua/texlive/tlpdb.tlu b/Master/texmf/scripts/texlive/lua/texlive/tlpdb.tlu
new file mode 100644
index 00000000000..d6dd1901f63
--- /dev/null
+++ b/Master/texmf/scripts/texlive/lua/texlive/tlpdb.tlu
@@ -0,0 +1,236 @@
+#! /usr/bin/env texlua
+-- texlive/tlpdb.tlu
+-- $Id$
+--
+-- Copyright (C) 2008 Norbert Preining
+-- This file is licensed under the GNU General Public License version 2
+-- or any later version.
+--
+-- TODO: tag evaluation of docfiles lines ...
+--
+-- providing the tlpdb as a lua table
+--
+-- format
+-- tlpobj = tlpdb[packagename]
+-- tlpobj.name string
+-- tlpobj.revision string
+-- tlpobj.category string
+-- tlpobj.shortdesc string
+-- tlpobj.longdesc string
+-- tlpobj.catalogue string
+-- tlpobj.cataloguedata table indexed by various catalogue values
+-- tlpobj.containersize string
+-- tlpobj.srccontainersize string
+-- tlpobj.doccontainersize string
+-- tlpobj.containermd5 string
+-- tlpobj.srccontainermd5 string
+-- tlpobj.doccontainermd5 string
+-- tlpobj.binfiles table indexed by archs giving table indexed by numbers
+-- tlpobj.binsize table indexed by archs giving strings
+-- tlpobj.docfiles = table indexed by numbers
+-- tlpobj.docsize string
+-- tlpobj.srcfiles = table indexed by numbers
+-- tlpobj.srcsize string
+-- tlpobj.runfiles = table indexed by numbers
+-- tlpobj.runsize string
+-- tlpobj.depend = table indexed by numbers
+-- tlpobj.execute = table indexed by numbers
+--
+--*-Lua-*-
+
+function read_tlpdb(root)
+ local fn = root..'/tlpkg/texlive.tlpdb'
+ if (lfs.isfile(fn)) then -- tlpdb exists
+ local started = false
+ local lastcmd = ""
+ local arch
+ local size
+ local line
+ local tlpobj = {}
+ local name
+ local tlpdb = {}
+ for line in io.lines(fn) do
+ if string.match(line, '^%s*$') then
+ if started then
+ -- we have encountered an empty line while creating a tlpobj, so
+ -- stop that tlpobj, add it to the tlpdb, and restart
+ --tlpdb[name] = tlpobj
+ tlpdb[name] = tlpobj
+ tlpobj = {}
+ --print ("adding "..name.." to tlpdb")
+ started = false
+ end
+ else
+ if string.match(line, '^ ') then
+ if lastcmd == 'runfiles' or
+ lastcmd == 'binfiles' or
+ lastcmd == 'docfiles' or
+ lastcmd == 'srcfiles' or
+ lastcmd == 'execute' or
+ lastcmd == 'depend' then
+ line = string.gsub(line, '^ ', lastcmd.."continued ")
+ else
+ io.stderr:write('Error reading tlpdb: continuation of '..lastcmd..' not allowed in line\n>>'..line..'<<\n')
+ os.exit(1)
+ end
+ end
+ local first
+ local rest
+ first, rest = string.match(line,'^(%S+)%s*(.*)%s*$')
+ --print ("DEBUG: line = "..line)
+ --print ("DEBUG: first = "..first)
+ lastcmd = first
+ if first == "name" then
+ tlpobj.name = rest
+ name = rest
+ started = true
+ elseif first == "revision" then
+ tlpobj.revision = rest
+ elseif first == "category" then
+ tlpobj.category = rest
+ elseif first == "shortdesc" then
+ tlpobj.shortdesc = rest
+ elseif first == "catalogue" then
+ tlpobj.catalogue = rest
+ elseif string.match(first,'^catalogue-') then
+ --local data = string.match(first,'^catalogue-(.*)$')
+ local cdata = string.gsub(first,'^catalogue-', '')
+ --print("DEBUG: cdata = "..cdata..", first = "..first)
+ if not(tlpobj.cataloguedata) then
+ tlpobj.cataloguedata = {}
+ end
+ tlpobj.cataloguedata[cdata] = rest
+ elseif first == "containersize" then
+ tlpobj.containersize = rest
+ elseif first == "srccontainersize" then
+ tlpobj.srccontainersize = rest
+ elseif first == "doccontainersize" then
+ tlpobj.doccontainersize = rest
+ elseif first == "containermd5" then
+ tlpobj.containermd5 = rest
+ elseif first == "srccontainermd5" then
+ tlpobj.srccontainermd5 = rest
+ elseif first == "doccontainermd5" then
+ tlpobj.doccontainermd5 = rest
+ elseif first == "runfiles" then
+ local rsize = string.match(rest,'size=([0-9]*)')
+ if (rsize) then
+ tlpobj.runsize = rsize
+ else
+ if #rest > 0 then
+ io.stderr:write('Unknown tag in line\n>>'..line.."<<\n")
+ os.exit(1)
+ end
+ end
+ elseif first == "docfiles" then
+ local dsize = string.match(rest,'size=([0-9]*)')
+ if (dsize) then
+ tlpobj.docsize = dsize
+ else
+ if #rest > 0 then
+ io.stderr:write('Unknown tag in line\n>>'..line.."<<\n")
+ os.exit(1)
+ end
+ end
+ elseif first == "srcfiles" then
+ local ssize = string.match(rest,'size=([0-9]*)')
+ if (ssize) then
+ tlpobj.srcsize = ssize
+ else
+ if #rest > 0 then
+ io.stderr:write('Unknown tag in line\n>>'..line.."<<\n")
+ os.exit(1)
+ end
+ end
+ elseif first == "binfiles" then
+ arch = ""
+ local barch
+ local bsize
+ for aaa in string.gmatch(rest,'%S+') do
+ if string.match(aaa,'^arch=(%S*)$') then
+ barch = string.match(aaa,'^arch=(%S*)$')
+ elseif string.match(aaa,'^size=(%S*)$') then
+ bsize = string.match(aaa,'^size=(%S*)$')
+ else
+ io.stderr:write('Unknown tag in line\n>>'..line.."<<\n")
+ os.exit(1)
+ end
+ end
+ if barch and bsize then
+ if not(tlpobj.binsize) then
+ tlpobj.binsize = {}
+ end
+ tlpobj.binsize[barch] = bsize
+ arch = barch
+ else
+ io.stderr:write('Incomplete binfile tags in line\n>>'..line.."<<\n")
+ os.exit(1)
+ end
+ elseif first == "runfilescontinued" then
+ if not(tlpobj.runfiles) then
+ tlpobj.runfiles = {}
+ end
+ table.insert(tlpobj.runfiles,rest)
+ lastcmd = "runfiles"
+ elseif first == "docfilescontinued" then
+ if not(tlpobj.docfiles) then
+ tlpobj.docfiles = {}
+ end
+ -- TODO doc files can have tags!!!!
+ table.insert(tlpobj.docfiles,rest)
+ lastcmd = "docfiles"
+ elseif first == "srcfilescontinued" then
+ if not(tlpobj.srcfiles) then
+ tlpobj.srcfiles = {}
+ end
+ table.insert(tlpobj.srcfiles,rest)
+ lastcmd = "srcfiles"
+ elseif first == "binfilescontinued" then
+ if not(tlpobj.binfiles) then
+ tlpobj.binfiles = {}
+ end
+ if not(tlpobj.binfiles[arch]) then
+ tlpobj.binfiles[arch] = {}
+ end
+ table.insert(tlpobj.binfiles[arch],rest)
+ lastcmd = "binfiles"
+ elseif first == "depend" then
+ if not(tlpobj.depend) then
+ tlpobj.depend = {}
+ end
+ table.insert(tlpobj.depend,rest)
+ elseif first == "longdesc" then
+ if tlpobj.longdesc then
+ tlpobj.longdesc = tlpobj.longdesc.." "..rest
+ else
+ tlpobj.longdesc = rest
+ end
+ elseif first == "execute" then
+ if not(tlpobj.execute) then
+ tlpobj.execute = {}
+ end
+ table.insert(tlpobj.execute,rest)
+ else
+ print("first = "..first)
+ io.stderr:write('Error reading tlpdb: unknown directive in line\n>>'..line.."<<\n")
+ os.exit(1)
+ end
+ if not(first) then
+ io.stderr:write('Error reading tlpdb: missing directive in line\n>>'..line.."<<\n")
+ os.exit(1)
+ end
+ end
+ end
+ return tlpdb
+ else
+ print (fn..' not found.')
+ end
+end
+
+
+-- Local Variables:
+-- lua-indent-level: 2
+-- tab-width: 2
+-- indent-tabs-mode: nil
+-- End:
+-- vim:set tabstop=2 expandtab: #
diff --git a/Master/texmf/scripts/texlive/test-tlpdb.tlu b/Master/texmf/scripts/texlive/test-tlpdb.tlu
new file mode 100755
index 00000000000..c147120740e
--- /dev/null
+++ b/Master/texmf/scripts/texlive/test-tlpdb.tlu
@@ -0,0 +1,45 @@
+#! /usr/bin/env texlua
+--*- Lua -*-
+
+-- Copyright (C) 2008 Norbert Preining.
+-- You may freely use, modify and/or distribute this file.
+
+-- test the functionality of tlpdb.tlu
+
+kpse.set_program_name( "mktexlsr" )
+texmfmain = kpse.var_value('TEXMFMAIN')
+package.path = texmfmain.."/scripts/texlive/lua/?.tlu"
+require("texlive.tlpdb")
+master=kpse.var_value('SELFAUTOPARENT')
+io.stderr:write('reading tlpdb ... ')
+tlpdb = read_tlpdb(master)
+io.stderr:write('done\n')
+
+--os.exit(0)
+
+for a,b in pairs(tlpdb) do
+ print ("package = "..a)
+ for c,d in pairs(b) do
+ if (type(d) == "table") then
+ print (" "..c..":")
+ for cdata,cvalue in pairs(d) do
+ if (type(cvalue) == "table") then
+ print (" "..cdata..":")
+ for aaa,bbb in pairs(cvalue) do
+ print (" "..aaa.." = "..bbb)
+ end
+ else
+ print (" "..cdata.." = "..cvalue)
+ end
+ end
+ else
+ print (" "..c.." = "..d)
+ end
+ end
+end
+-- Local Variables:
+-- lua-indent-level: 2
+-- tab-width: 2
+-- indent-tabs-mode: nil
+-- End:
+-- vim:set tabstop=2 expandtab: #