Stary2001

update

Feb 9th, 2013
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. local files={}
  2.  
  3. if not http then
  4. print("HTTP API is required to update!")
  5. return
  6. end
  7.  
  8. local args= {...}
  9. local repo = args[1] or "stary2001/carbon"
  10. local branch = args[2] or "master"
  11. local url = "https://raw.github.com/"..repo
  12.  
  13. function get(url)
  14. local page = http.get(url)
  15. if page then
  16. local cont = page.readAll()
  17. page.close()
  18. return cont
  19. else
  20. error("Failed downloading "..url)
  21. end
  22. end
  23.  
  24. function list(path)
  25. local api = "https://api.github.com/" .. "/repos/"..repo.."/contents/"..path.."?ref="..branch
  26. local t=json.decode(get(url))
  27.  
  28. for k,v in pairs(t.files) do
  29. files[#files+1] = v.path
  30. end
  31. for k,v in pairs(t.directories) do
  32. list(v)
  33. end
  34. end
  35.  
  36. function skeleton(path)
  37. local tmp_path=""
  38. for comp in string.gmatch(path,"(.-)/") do
  39. tmp_path=tmp_path.."/"..comp
  40. if not fs.exists(tmp_path) then fs.makeDir(tmp_path) end
  41. end
  42. end
  43.  
  44. if not json then
  45. local json_api = get("https://raw.github.com/Stary2001/StaryOS/master/lib/json")
  46. local f = fs.open("json","w")
  47. if f then
  48. f.write(json_api)
  49. f.close()
  50. os.loadAPI("json")
  51. else
  52. print("Failed opening 'json'")
  53. return
  54. end
  55. end
  56.  
  57. list("")
  58.  
  59. for k,v in pairs(files) do
  60. print(v)
  61. skeleton(v)
  62. local url = repo.."/"..v
  63. local content=get(url)
  64. local f=fs.open(v,"w")
  65. f.write(content)
  66. f.close()
  67. end
Advertisement
Add Comment
Please, Sign In to add comment