Advertisement
_dinsdale

parse-rock-version.lua

Apr 18th, 2018
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.15 KB | None | 0 0
  1. --~ package.path = package.path .. '.\\lua\\?\\init.lua'
  2. --Added the scripts for PenLight and LuaRocks under my project path
  3. package.path = '.\\?\\init.lua;' .. '.\\LuaRocks\\lua\\?.lua;' ..package.path
  4.  
  5. require('pl')
  6. --Steve!
  7. utils.printf("%s\n","That feels better")
  8.  
  9. local d = data.read('lfw_modules.tab')
  10. local lrs = require('luarocks.search')
  11.  
  12. local full_ver = sip.compile('$i{major}.$i{minor}.$i{patch}-$i{revision}')
  13. local no_patch_ver = sip.compile('$i{major}.$i{minor}-$i{revision}')
  14. local no_minor_ver = sip.compile('$i{major}-$i{revision}')
  15.  
  16. local function get_highest_ver(rock_name, search_res)
  17.     local highest = nil
  18.     if search_res.binaries then
  19.         local rock = search_res.binaries[rock_name:lower()]
  20.         if rock then
  21.             for i,v in pairs(rock) do
  22.                 res = {}
  23.                 local ok  = full_ver(i,res)
  24.                 if not ok then
  25.                     ok = no_patch_ver(i,res)
  26.                     if not ok then
  27.                         ok = no_minor_ver(i,res)
  28.                         if not ok then
  29.                             print('wtf: ' .. i)
  30.                             assert(nil, 'no matching pattern')
  31.                         end
  32.                     end
  33.                 end
  34.                 if not highest then
  35.                     highest = res
  36.                 else
  37.                     print(pretty.write(res))
  38.                     print(pretty.write(highest))
  39.                     if res.major > highest.major then
  40.                         highest = res                  
  41.                     elseif res.major == highest.major then
  42.                         if res.minor > highest.minor then
  43.                             highest = res
  44.                         elseif res.minor == highest.minor then
  45.                             if res.patch > highest.patch then
  46.                                 highest = res
  47.                             elseif res.patch == highest.patch then
  48.                                 if res.revision > highest.revision then
  49.                                     highest = res
  50.                                 elseif res.revision == highest.revision then
  51.                                     --MATCH
  52.                                     print('MATCH')
  53.                                 end
  54.                             end
  55.                         end
  56.                     end
  57.                 end
  58.             end
  59.         end
  60.     end
  61.     return highest
  62. end
  63.  
  64. local function get_rock_result(name)
  65.     local res = lrs.return_search('',name,nil)
  66.     if res then
  67.         local v = get_highest_ver(name, res, sc)
  68.         --~ print(pretty.write(r))
  69.         if v then
  70.             print('And the winner is... \n' .. pretty.write(v))
  71.         else
  72.             print('no results... bummer')
  73.         end
  74.     else
  75.         print ('no results')
  76.     end
  77. end
  78.  
  79. local q = d:select('NAME,VERSION')
  80. for x,y in q do
  81.     print(x,y)
  82.     get_rock_result(x)
  83. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement