|
|
51cf4a |
-- Convenience Lua functions that can be used within Python srpm/rpm macros
|
|
|
51cf4a |
|
|
|
51cf4a |
-- Determine alternate names provided from the given name.
|
|
|
51cf4a |
-- Used in pythonname provides generator, python_provide and py_provides.
|
|
|
51cf4a |
-- There are 2 rules:
|
|
|
51cf4a |
-- python3-foo -> python-foo, python3.X-foo
|
|
|
51cf4a |
-- python3.X-foo -> python-foo, python3-foo
|
|
|
51cf4a |
-- There is no python-foo -> rule, python-foo packages are version agnostic.
|
|
|
51cf4a |
-- Returns a table/array with strings. Empty when no rule matched.
|
|
|
51cf4a |
local function python_altnames(name)
|
|
|
51cf4a |
local xy = rpm.expand('%{__default_python3_pkgversion}')
|
|
|
51cf4a |
local altnames = {}
|
|
|
51cf4a |
local replaced
|
|
|
51cf4a |
-- NB: dash needs to be escaped!
|
|
|
51cf4a |
if name:match('^python3%-') then
|
|
|
51cf4a |
for i, prefix in ipairs({'python-', 'python' .. xy .. '-'}) do
|
|
|
51cf4a |
replaced = name:gsub('^python3%-', prefix)
|
|
|
51cf4a |
table.insert(altnames, replaced)
|
|
|
51cf4a |
end
|
|
|
51cf4a |
elseif name:match('^python' .. xy .. '%-') then
|
|
|
51cf4a |
for i, prefix in ipairs({'python-', 'python3-'}) do
|
|
|
51cf4a |
replaced = name:gsub('^python' .. xy .. '%-', prefix)
|
|
|
51cf4a |
table.insert(altnames, replaced)
|
|
|
51cf4a |
end
|
|
|
51cf4a |
end
|
|
|
51cf4a |
return altnames
|
|
|
51cf4a |
end
|
|
|
51cf4a |
|
|
|
51cf4a |
|
|
|
51cf4a |
-- For any given name and epoch-version-release, return provides except self.
|
|
|
51cf4a |
-- Uses python_altnames under the hood
|
|
|
51cf4a |
-- Returns a table/array with strings.
|
|
|
51cf4a |
local function python_altprovides(name, evr)
|
|
|
51cf4a |
-- global cache that tells what provides were already processed
|
|
|
51cf4a |
if __python_altnames_provides_beenthere == nil then
|
|
|
51cf4a |
__python_altnames_provides_beenthere = {}
|
|
|
51cf4a |
end
|
|
|
51cf4a |
__python_altnames_provides_beenthere[name .. ' ' .. evr] = true
|
|
|
51cf4a |
local altprovides = {}
|
|
|
51cf4a |
for i, altname in ipairs(python_altnames(name)) do
|
|
|
51cf4a |
table.insert(altprovides, altname .. ' = ' .. evr)
|
|
|
51cf4a |
end
|
|
|
51cf4a |
return altprovides
|
|
|
51cf4a |
end
|
|
|
51cf4a |
|
|
|
51cf4a |
|
|
|
51cf4a |
-- Like python_altprovides but only return something once.
|
|
|
51cf4a |
-- For each argument can only be used once, returns nil otherwise.
|
|
|
51cf4a |
-- Previous usage of python_altprovides counts as well.
|
|
|
51cf4a |
local function python_altprovides_once(name, evr)
|
|
|
51cf4a |
-- global cache that tells what provides were already processed
|
|
|
51cf4a |
if __python_altnames_provides_beenthere == nil then
|
|
|
51cf4a |
__python_altnames_provides_beenthere = {}
|
|
|
51cf4a |
end
|
|
|
51cf4a |
if __python_altnames_provides_beenthere[name .. ' ' .. evr] == nil then
|
|
|
51cf4a |
__python_altnames_provides_beenthere[name .. ' ' .. evr] = true
|
|
|
51cf4a |
return python_altprovides(name, evr)
|
|
|
51cf4a |
else
|
|
|
51cf4a |
return nil
|
|
|
51cf4a |
end
|
|
|
51cf4a |
end
|
|
|
51cf4a |
|
|
|
51cf4a |
|
|
|
51cf4a |
return {
|
|
|
51cf4a |
python_altnames = python_altnames,
|
|
|
51cf4a |
python_altprovides = python_altprovides,
|
|
|
51cf4a |
python_altprovides_once = python_altprovides_once,
|
|
|
51cf4a |
}
|