Advertisement
nitrogenfingers

compress

Jan 3rd, 2013
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.12 KB | None | 0 0
  1. function createRepository(projDir, destPath)
  2.     print("Compressing project...")
  3.    
  4.     local destFile = io.open(destPath, "w")
  5.     addDir(projDir, destFile)
  6.     destFile:close()
  7.     print("Repository created.")
  8. end
  9.  
  10. function addDir(locPath, destFile)
  11.     local globPath = shell.resolve(".").."/"..locPath
  12.    
  13.     print("Constructing dir "..locPath)
  14.     destFile:write("MKDIR "..locPath.."\n")
  15.     local dir = fs.list(globPath)
  16.     for _,v in pairs(dir) do
  17.         if fs.isDir(globPath.."/"..v) then
  18.             addDir(locPath.."/"..v, destFile)
  19.         else
  20.             local file = io.open(globPath.."/"..v)
  21.             local lineCount = 0
  22.             for line in file:lines() do
  23.                 lineCount=lineCount+1
  24.             end
  25.             print("Constructing "..lineCount.." line file: "..v)
  26.             destFile:write("MKFIL "..locPath.."/"..v.."\n")
  27.             destFile:write("WRITE "..lineCount.."\n")
  28.             file:close()
  29.             file = io.open(globPath.."/"..v)
  30.             for line in file:lines() do
  31.                 destFile:write(line.."\n")
  32.             end
  33.             file:close()
  34.         end
  35.     end
  36. end
  37.  
  38. local tArgs = {...}
  39. if #tArgs < 2 then
  40.     print("Usage: compress <filepath> <reponame>")
  41.     return
  42. end
  43.  
  44. createRepository(shell.resolve(tArgs[1]), shell.resolve(tArgs[2]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement