Advertisement
Guest User

Untitled

a guest
Mar 24th, 2015
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.33 KB | None | 0 0
  1.  
  2. local function parseFolders(pack, repo, info)
  3.  
  4.   local function getFolderTable(repo, namePath, branch)
  5.     local success, filestring = pcall(getContent,"https://api.github.com/repos/"..repo.."/contents/"..namePath.."?ref="..branch)
  6.     if not success or filestring:find("\"message\": \"Not Found\"") then
  7.       io.stderr:write("Error while trying to parse folder names in declaration of package "..pack..".\n")
  8.       io.stderr:write("Please contact the author of that package.\n")
  9.       return nil
  10.     end
  11.     return serial.unserialize(filestring:gsub("%[", "{"):gsub("%]", "}"):gsub("(\"%S-\")%s?:", "[%1] =")))
  12.   end
  13.  
  14.   local function unserializeFiles(files, repo, namePath, branch, relPath)
  15.     if not files then return nil end
  16.     local tFiles = {}
  17.     for _,v in pairs(files) do
  18.       if v["type"] == "file" then
  19.         local newPath = v["download_url"]:gsub("https?://raw.githubusercontent.com/"..repo.."(.+)$", "%1"):gsub("/?$",""):gsub("^/?","")
  20.         tFiles[newPath] = fs.concat(relPath, newPath:gsub(branch.."/(.+)$","%1"), nil)
  21.       elseif v["type"] == "dir" then
  22.         local newFiles = unserializeFiles(getFolderTable(repo, namePath.."/"..v["path"], branch), repo, branch, fs.concat(relPath, v["path"])
  23.         for p,q in pairs(newFiles) do
  24.           tFiles[p] = q
  25.         end
  26.       end
  27.     end
  28.     return tFiles
  29.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement