2 -- --- T2-COPYRIGHT-NOTE-BEGIN ---
3 -- This copyright note is auto-generated by scripts/Create-CopyPatch.
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>
9 -- More information can be found in the files COPYING and README.
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")
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?
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) *");
40 print ("error no Cateory tag - parsing: ", line
)
44 pkg
.default_status
= pkg
.status
49 if pkg.categories == nil then
50 pkg.categories = "nil" end
52 if pkg.flags == nil then
54 io.write ("'",pkg.categories,"'",pkg.flags,"'\n")
57 if pkg
.alias
== nil then
58 print ("error parsing: ", line
)
60 packages
[#packages
+1] = pkg
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
)
81 f
:write (" / ", pkg
.categories
)
83 if string.len(pkg
.flags
) > 0 then
84 f
:write (" ", pkg
.flags
)
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
= { ["+"] = "%+",
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
, "(.*)/(.*)");
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
119 --print ("regex> rep: " .. rep .. ", pkg: '" .. pkg .. "'")
121 for j
,p
in ipairs(packages
) do
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)
135 if (string.match(p
.alias
, pkg
) and
136 string.match(p
.repository
, rep
)) then
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)
144 p
.status
= p
.default_status
156 --if matched == false then
157 -- print ("Warning: pkgsel - no match for: " .. mode .. " " .. ...)
161 function pkgenable (...)
165 function pkgdisable (...)
169 function pkgremove (...)
173 function pkgcheck (pattern
, mode
)
174 -- split the pattern seperated by "|"
176 for x
in string.gmatch(pattern
, "[^|]+") do
180 for i
,pkg
in ipairs(packages
) do
181 for j
,x
in ipairs (p
) do
182 if pkg
.alias
== 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
190 print ("Syntax error near pkgcheck: "..pattern
.." "..mode
)
200 -- Parse pkg selection rules
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")
212 print ("Error opening file: '" .. filename
.."'")
216 for line
in f
:lines() do
217 line
= string.gsub (line
, "#.*","")
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
)
234 if not line
== "" then
235 print ("Syntax error in: "..line
)
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")