Guest User

Untitled

a guest
Apr 16th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. require 'open3'
  2. require 'rubygems'
  3. require 'zip/zipfilesystem'
  4. require 'fileutils'
  5.  
  6. module Tempdir
  7. def self.path(&block)
  8. result = path = nil
  9. begin
  10. path = File.join((ENV['TMPDIR'] || ENV['TMP'] || ENV['TEMP'] || '/tmp'), "temp.#{$$}.#{Time.now.to_f}")
  11. end while(File.exist?(path))
  12. FileUtils.mkdir_p path
  13. if block
  14. result = block.call(path)
  15. FileUtils.rm_rf(path)
  16. end
  17. result || path
  18. end
  19. end
  20.  
  21. module GAE; end
  22. class GAE::SDK
  23. attr_reader :status
  24.  
  25. def upload(email, password, path="./")
  26. `cd "#{path}"; appcfg.rb update ./`
  27. Open3.popen3('cd "%s"; appcfg.sh --email="%s" --passin update "."' % [path, email]) do |stdin, stdout, stderr|
  28. stdin.puts password
  29. stdin.close
  30.  
  31. @status, @lines = nil, []
  32. stdout.each do |line|
  33. line.chomp!
  34. @lines << line
  35. if "Update completed successfully." == line
  36. @status = "successfully"
  37. elsif /^Unable to upload app: Email .* and password do not match/.match(line)
  38. @status = "authentication error"
  39. elsif /^409 Conflict/.match(line)
  40. @status = "Conflict"
  41. end
  42. end
  43. end
  44. end # def initialize
  45.  
  46. def upload_zip(email, password, zip)
  47. Tempdir.path do |dir|
  48. Zip::ZipInputStream.open(zip) do |stream|
  49. while (entry = stream.get_next_entry)
  50. next if /\.\./.match(entry.name)
  51. file_path = File.join(dir, entry.name)
  52. if file_path[-1..-1] == '/'
  53. FileUtils.makedirs(file_path)
  54. else
  55. FileUtils.makedirs(File.dirname(file_path))
  56. File.open(file_path,'w') { |f| f.write stream.read }
  57. end
  58. end
  59. end # Zip::ZipInputStream.open(zip) do |stream|
  60.  
  61. upload(email, password, dir)
  62. # p @lines
  63. end
  64. end
  65. end
  66.  
  67. sdk = GAE::SDK.new
  68. sdk.upload_zip("XXXXX@gmail.com", "XXXXX", "app.zip")
  69. p sdk.status
Add Comment
Please, Sign In to add comment