2 -- --- T2-COPYRIGHT-NOTE-BEGIN ---
3 -- T2 SDE: scripts/config-functions.lua
4 -- Copyright (C) 2006 - 2023 The T2 SDE Project
5 -- Copyright (C) 2006 - 2015 Rene Rebe <rene@exactcode.de>
7 -- This Copyright note is generated by scripts/Create-CopyPatch,
8 -- more information can be found in the files COPYING and README.
10 -- This program is free software; you can redistribute it and/or modify
11 -- it under the terms of the GNU General Public License version 2.
12 -- --- T2-COPYRIGHT-NOTE-END ---
14 packages
= {} -- our internal package array of tables
16 function pkglistread(filename
)
17 local f
= io
.open(filename
, "r")
21 for line
in f
:lines() do
22 -- use captures to yank out the various parts:
23 -- X -----5---9 149.800 develop lua 5.1.1 / extra/development DIETLIBC 0
24 -- X -----5---- 112.400 xorg bigreqsproto 1.0.2 / base/x11 0
26 -- hm - maybe strtok as one would do in C?
29 pkg
.status
, pkg
.stages
, pkg
.priority
, pkg
.repository
,
30 pkg
.name
, pkg
.ver
, pkg
.extraver
, pkg
.categories
, pkg
.flags
=
31 string.match(line
, "([XO]) *([0123456789?-]+) *([0123456789.]+) *(%S+) *(%S+) *(%S+) *(%S*) */ ([abcdefghijklmnopqrstuvwxyz0123456789/ ]+) *([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ._-]*) 0")
33 -- shortcoming of above regex
34 if pkg
.categories
then
35 pkg
.categories
= string.match(pkg
.categories
, "(.*%S) *");
37 print("Error: no Cateory tag - parsing:", line
)
41 pkg
.default_status
= pkg
.status
46 if pkg.categories == nil then
47 pkg.categories = "nil" end
49 if pkg.flags == nil then
51 io.write("'", pkg.categories, "'", pkg.flags, "'\n")
54 if pkg
.alias
== nil then
55 print("Error parsing: ", line
)
57 packages
[#packages
+1] = pkg
64 function pkglistwrite(filename
)
65 local f
= io
.open(filename
, "w")
67 for i
, pkg
in ipairs(packages
) do
68 -- only write not fully disabled packages
69 if pkg
.status
~= "-" then
71 f
:write(pkg
.status
, " ", pkg
.stages
, " ", pkg
.priority
, " ",
72 pkg
.repository
, " ", pkg
.alias
, " ", pkg
.ver
)
74 if string.len(pkg
.extraver
) > 0 then
75 f
:write(" ", pkg
.extraver
)
78 f
:write(" / ", pkg
.categories
)
80 if string.len(pkg
.flags
) > 0 then
81 f
:write(" ", pkg
.flags
)
90 -- tracks the state and also expands patterns
91 -- either called with just packages or repository/package
92 -- allowing wildcards such as perl/*
93 local function pkgswitch(mode
, ...)
94 --local matched = false
95 local tr
= { ["+"] = "%+",
99 for i
, arg
in ipairs
{...} do
100 -- split repo from the package and expand wildcard to regex
101 local rep
, pkg
= string.match(arg
, "(.*)/(.*)");
107 rep
= "^" .. string.gsub(rep
, "([+*-])", tr
) .. "$"
108 pkg
= "^" .. string.gsub(pkg
, "([+*-])", tr
) .. "$"
110 --optimization, to skip the package traversal early
111 local pkg_match
= false
112 if string.find(pkg
, "*") == nil then
116 --print("regex> rep: " .. rep .. ", pkg: '" .. pkg .. "'")
118 for j
, p
in ipairs(packages
) do
121 if (pkg == "linux-header") then
122 print("pkg> p.rep: " .. p.repository ..
123 ", p.alias: '" .. p.alias .. "'")
124 local s1 = string.match(p.alias, pkg)
125 local s2 = string.match(p.repository, rep)
126 if s1 == nil then s1 = "nil" end
127 if s2 == nil then s2 = "nil" end
128 print("match pkg: " .. s1)
129 print("match rep: " .. s2)
132 if (string.match(p
.alias
, pkg
) and
133 string.match(p
.repository
, rep
)) then
135 -- if not already disabled completely
136 --print("matched rep: " .. rep .. ", pkg: " .. pkg)
137 --print("with rep: " .. p.repository ..", pkg: " .. p.alias)
138 if p
.status
~= "-" then
139 --print("set to: " .. mode)
141 p
.status
= p
.default_status
153 --if matched == false then
154 -- print("Warning: pkgsel - no match for: " .. mode .. " " .. ...)
158 function pkgenable(...)
162 function pkgdisable(...)
166 function pkgremove(...)
170 function pkgcheck(pattern
, mode
)
171 -- split the pattern seperated by "|"
173 for x
in string.gmatch(pattern
, "[^|]+") do
177 for i
, pkg
in ipairs(packages
) do
178 for j
, x
in ipairs(p
) do
179 if pkg
.alias
== x
then
181 if pkg
.status
== "X" then return true end
182 elseif mode
== "O" then
183 if pkg
.status
== "O" then return true end
184 elseif mode
== "." then
187 print("Syntax error near pkgcheck: " .. pattern
.. " " .. mode
)
197 -- Parse pkg selection rules
200 -- X python - selects just the python package
201 -- O perl/* - deselects all perl repository packages
202 -- = glibc - sets package glibc to it's default state
203 -- include file - recursively parse file specified
206 function pkgsel_parse(filename
)
207 local f
= io
.open(filename
, "r")
209 print("Error opening file: '" .. filename
.."'")
213 for line
in f
:lines() do
214 line
= string.gsub(line
, "#.*","")
218 action
, pattern
= string.match(line
, "(%S+) +(%S+)")
220 if action
== "x" or action
== "X" then
221 pkgswitch("X", pattern
)
222 elseif action
== "o" or action
== "O" then
223 pkgswitch("O", pattern
)
224 elseif action
== "-" then
225 pkgswitch("-", pattern
)
226 elseif action
== "=" then
227 pkgswitch("=", pattern
)
228 elseif action
== "include" then
229 pkgsel_parse(pattern
)
231 if not line
== "" then
232 print("Syntax error in: " .. line
)
241 print "Lua Bash accel. (C) 2006-2021 by V. Ziegler, R. Rebe, ExactCODE GmbH"
243 -- register shortcuts for the functions above
244 bash
.register("pkglistread")
245 bash
.register("pkglistwrite")
246 bash
.register("pkgcheck")
247 bash
.register("pkgremove")
248 bash
.register("pkgenable")
249 bash
.register("pkgdisable")
250 bash
.register("pkgsel_parse")