* updated pimcommon (21.12.1 -> 21.12.2), untested
[t2-trunk.git] / scripts / config-functions.lua
blobd8eb5e7a2f1090bfdf68fbade777091fe684d623
1 #!/usr/bin/lua
2 -- --- T2-COPYRIGHT-NOTE-BEGIN ---
3 -- This copyright note is auto-generated by scripts/Create-CopyPatch.
4 --
5 -- T2 SDE: scripts/config-functions.lua
6 -- Copyright (C) 2006 - 2021 The T2 SDE Project
7 -- Copyright (C) 2006 - 2015 Rene Rebe <rene@exactcode.de>
8 --
9 -- More information can be found in the files COPYING and README.
10 --
11 -- This program is free software; you can redistribute it and/or modify
12 -- it under the terms of the GNU General Public License as published by
13 -- the Free Software Foundation; version 2 of the License. A copy of the
14 -- GNU General Public License can be found in the file COPYING.
15 -- --- T2-COPYRIGHT-NOTE-END ---
17 packages = {} -- our internal package array of tables
19 function pkglistread (filename)
20 local f = io.open (filename, "r")
22 packages = {}
24 for line in f:lines() do
25 -- use captures to yank out the various parts:
26 -- X -----5---9 149.800 develop lua 5.1.1 / extra/development DIETLIBC 0
27 -- X -----5---- 112.400 xorg bigreqsproto 1.0.2 / base/x11 0
29 -- hm - maybe strtok as one would do in C?
31 local pkg = {}
32 pkg.status, pkg.stages, pkg.priority, pkg.repository,
33 pkg.name, pkg.ver, pkg.extraver, pkg.categories, pkg.flags =
34 string.match (line, "([XO]) *([0123456789?-]+) *([0123456789.]+) *(%S+) *(%S+) *(%S+) *(%S*) */ ([abcdefghijklmnopqrstuvwxyz0123456789/ ]+) *([ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 _-]*) 0")
36 -- shortcoming of above regex
37 if pkg.categories then
38 pkg.categories = string.match (pkg.categories, "(.*%S) *");
39 else
40 print ("error no Cateory tag - parsing: ", line)
41 end
43 pkg.alias = pkg.name
44 pkg.default_status = pkg.status
46 --[[
47 print (line);
49 if pkg.categories == nil then
50 pkg.categories = "nil" end
52 if pkg.flags == nil then
53 pkg.flags = "nil" end
54 io.write ("'",pkg.categories,"'",pkg.flags,"'\n")
55 ]]--
57 if pkg.alias == nil then
58 print ("error parsing: ", line)
59 else
60 packages[#packages+1] = pkg
61 end
63 end
64 f:close()
65 end
67 function pkglistwrite (filename)
68 local f = io.open (filename, "w")
70 for i,pkg in ipairs(packages) do
71 -- only write not fully disabled packages
72 if pkg.status ~= "-" then
74 f:write (pkg.status, " ", pkg.stages, " ", pkg.priority, " ",
75 pkg.repository, " ", pkg.alias, " ", pkg.ver)
77 if string.len(pkg.extraver) > 0 then
78 f:write (" ", pkg.extraver)
79 end
81 f:write (" / ", pkg.categories)
83 if string.len(pkg.flags) > 0 then
84 f:write (" ", pkg.flags)
85 end
87 f:write (" 0\n")
88 end
89 end
90 f:close()
91 end
93 -- tracks the state and also expands patterns
94 -- either called with just packages or repository/package
95 -- allowing wildcards such as perl/*
96 local function pkgswitch (mode, ...)
97 --local matched = false
98 local tr = { ["+"] = "%+",
99 ["-"] = "%-",
100 ["*"] = ".*" }
102 for i,arg in ipairs {...} do
103 -- split repo from the package and expand wildcard to regex
104 local rep, pkg = string.match (arg, "(.*)/(.*)");
105 if rep == nil then
106 rep = "*"
107 pkg = arg
110 rep = "^" .. string.gsub (rep, "([+*-])", tr) .. "$"
111 pkg = "^" .. string.gsub (pkg, "([+*-])", tr) .. "$"
113 --optimization, to skip the package traversal early
114 local pkg_match = false
115 if string.find (pkg, "*") == nil then
116 pkg_match = true
119 --print ("regex> rep: " .. rep .. ", pkg: '" .. pkg .. "'")
121 for j,p in ipairs(packages) do
122 -- match
123 --[[
124 if (pkg == "linux-header") then
125 print ("pkg> p.rep: " .. p.repository ..
126 ", p.alias: '" .. p.alias .. "'")
127 local s1 = string.match(p.alias, pkg)
128 local s2 = string.match(p.repository, rep)
129 if s1 == nil then s1 = "nil" end
130 if s2 == nil then s2 = "nil" end
131 print ("match pkg: " .. s1)
132 print ("match rep: " .. s2)
134 ]]--
135 if (string.match(p.alias, pkg) and
136 string.match(p.repository, rep)) then
137 --matched = true
138 -- if not already disabled completely
139 --print ("matched rep: " .. rep .. ", pkg: " .. pkg)
140 --print ("with rep: " .. p.repository ..", pkg: " .. p.alias)
141 if p.status ~= "-" then
142 --print ("set to: " .. mode)
143 if mode == "=" then
144 p.status = p.default_status
145 else
146 p.status = mode
149 -- just optimization
150 if pkg_match then
151 break
156 --if matched == false then
157 -- print ("Warning: pkgsel - no match for: " .. mode .. " " .. ...)
158 --end
161 function pkgenable (...)
162 pkgswitch ("X", ...)
165 function pkgdisable (...)
166 pkgswitch ("O", ...)
169 function pkgremove (...)
170 pkgswitch ("-", ...)
173 function pkgcheck (pattern, mode)
174 -- split the pattern seperated by "|"
175 p = {}
176 for x in string.gmatch(pattern, "[^|]+") do
177 p[#p+1] = x
180 for i,pkg in ipairs(packages) do
181 for j,x in ipairs (p) do
182 if pkg.alias == x then
183 if mode == "X" then
184 if pkg.status == "X" then return true end
185 elseif mode == "O" then
186 if pkg.status == "O" then return true end
187 elseif mode == "." then
188 return 0
189 else
190 print ("Syntax error near pkgcheck: "..pattern.." "..mode)
195 return false
200 -- Parse pkg selection rules
202 -- Example:
203 -- X python - selects just the python package
204 -- O perl/* - deselects all perl repository packages
205 -- = glibc - sets package glibc to it's default state
206 -- include file - recursively parse file specified
209 function pkgsel_parse (filename)
210 local f = io.open (filename, "r")
211 if f == nil then
212 print ("Error opening file: '" .. filename .."'")
213 return
216 for line in f:lines() do
217 line = string.gsub (line, "#.*","")
219 local action
220 local pattern
221 action, pattern = string.match (line, "(%S+) +(%S+)")
223 if action == "x" or action == "X" then
224 pkgswitch ("X", pattern)
225 elseif action == "o" or action == "O" then
226 pkgswitch ("O", pattern)
227 elseif action == "-" then
228 pkgswitch ("-", pattern)
229 elseif action == "=" then
230 pkgswitch ("=", pattern)
231 elseif action == "include" then
232 pkgsel_parse (pattern)
233 else
234 if not line == "" then
235 print ("Syntax error in: "..line)
239 f:close()
244 print "Lua Bash accel. (C) 2006-2021 by V. Ziegler, R. Rebe, ExactCODE GmbH"
246 -- register shortcuts for the functions above
247 bash.register("pkglistread")
248 bash.register("pkglistwrite")
249 bash.register("pkgcheck")
250 bash.register("pkgremove")
251 bash.register("pkgenable")
252 bash.register("pkgdisable")
253 bash.register("pkgsel_parse")