_dinsdale icon

parse-rock-version.lua

_dinsdale | PRO | 04/18/18 05:27:58 AM UTC | 0 ⭐ | 547 👁️ | Never ⏰ | []
Lua |

2.15 KB

|

None

|

0 👍

/

0 👎

--~ package.path = package.path .. '.\\lua\\?\\init.lua'
--Added the scripts for PenLight and LuaRocks under my project path
package.path = '.\\?\\init.lua;' .. '.\\LuaRocks\\lua\\?.lua;' ..package.path
 
require('pl')
--Steve!
utils.printf("%s\n","That feels better")
 
local d = data.read('lfw_modules.tab')
local lrs = require('luarocks.search')
 
local full_ver = sip.compile('$i{major}.$i{minor}.$i{patch}-$i{revision}')
local no_patch_ver = sip.compile('$i{major}.$i{minor}-$i{revision}')
local no_minor_ver = sip.compile('$i{major}-$i{revision}')
 
local function get_highest_ver(rock_name, search_res)
    local highest = nil
    if search_res.binaries then
        local rock = search_res.binaries[rock_name:lower()]
        if rock then
            for i,v in pairs(rock) do
                res = {}
                local ok  = full_ver(i,res)
                if not ok then 
                    ok = no_patch_ver(i,res)
                    if not ok then 
                        ok = no_minor_ver(i,res)
                        if not ok then 
                            print('wtf: ' .. i) 
                            assert(nil, 'no matching pattern')
                        end
                    end
                end
                if not highest then 
                    highest = res 
                else
                    print(pretty.write(res))
                    print(pretty.write(highest))
                    if res.major > highest.major then
                        highest = res                   
                    elseif res.major == highest.major then
                        if res.minor > highest.minor then
                            highest = res
                        elseif res.minor == highest.minor then
                            if res.patch > highest.patch then
                                highest = res
                            elseif res.patch == highest.patch then
                                if res.revision > highest.revision then
                                    highest = res
                                elseif res.revision == highest.revision then
                                    --MATCH
                                    print('MATCH')
                                end
                            end
                        end
                    end
                end
            end
        end
    end
    return highest
end
 
local function get_rock_result(name)
    local res = lrs.return_search('',name,nil)
    if res then
        local v = get_highest_ver(name, res, sc)
        --~ print(pretty.write(r))
        if v then
            print('And the winner is... \n' .. pretty.write(v))
        else
            print('no results... bummer')
        end
    else
        print ('no results')
    end
end
 
local q = d:select('NAME,VERSION')
for x,y in q do
    print(x,y)
    get_rock_result(x)
end

Comments