Guest User

Untitled

a guest
Nov 20th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. require 'json'
  4.  
  5. # Position of the mounted drive
  6. $SOURCE = "/Volumes/GoogleDrive/Il mio Drive"
  7. # Destination of the json file
  8. $DEST = "/tmp/result.json"
  9. # Size for "too big" files
  10. $XGB = 2
  11. # Regular expression for drive files
  12. $REGEXPDRIVE = /^(.*)\.(gdoc|gsheet|gslides|gform|gscript)$/i
  13.  
  14. #######
  15.  
  16. $FILE_COUNT = 0
  17. $DIR_COUNT = 0
  18.  
  19. $DATA = {
  20. "export" => {
  21. "gdoc" => [],
  22. "gsheet" => [],
  23. "gslides" => [],
  24. "gform" => [],
  25. "gscript" => []
  26. },
  27. "big" => [],
  28. "big_n" => 0,
  29. "copy" => [],
  30. "copy_n" => 0
  31. }
  32.  
  33. def handle_dir(input, cwd)
  34. $DIR_COUNT += 1
  35. Dir.foreach(input) do |entry|
  36. next if entry == '..' or entry == '.'
  37.  
  38. if File.file? entry
  39. $FILE_COUNT += 1
  40.  
  41. if match = entry.match($REGEXPDRIVE)
  42. $DATA["export"][match[2]] << "#{cwd}/#{match[1]}"
  43. next
  44. end
  45.  
  46. if (File.open(entry).size * 1e-9) > $XGB
  47. $DATA["big"] << "#{cwd}/#{entry}"
  48. $DATA["big_n"] += 1
  49. next
  50. end
  51.  
  52. $DATA["copy"] << "#{cwd}/#{entry}"
  53. $DATA["copy_n"] += 1
  54. elsif File.directory? entry
  55. Dir.chdir(entry) do
  56. handle_dir(".", "#{cwd}/#{entry}")
  57. end
  58. else
  59. puts "ENTRY UNKNOWN :: #{cwd}/#{entry}"
  60. end
  61. end
  62. end
  63.  
  64. Dir.chdir($SOURCE) do
  65. handle_dir(".", ".")
  66. end
  67.  
  68. File.open($DEST, "w") do |f|
  69. f.puts JSON.generate($DATA, indent: ' ', max_nesting: false)
  70. end
  71.  
  72. puts "STATISTICS:"
  73. puts " - total dirs: #{$DIR_COUNT}"
  74. puts " - total files: #{$FILE_COUNT}"
  75. puts " - drive docs: #{$DATA["export"]["gdoc"].size}"
  76. puts " - drive sheet: #{$DATA["export"]["gsheet"].size}"
  77. puts " - drive form: #{$DATA["export"]["gform"].size}"
  78. puts " - drive slides: #{$DATA["export"]["gslides"].size}"
  79. puts " - drive scripts: #{$DATA["export"]["gscript"].size}"
  80. puts " - direct copy: #{$DATA["copy_n"]}"
  81. puts " - big files: #{$DATA["big_n"]}"
Add Comment
Please, Sign In to add comment