Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'open3'
- require 'rubygems'
- require 'zip/zipfilesystem'
- require 'fileutils'
- module Tempdir
- def self.path(&block)
- result = path = nil
- begin
- path = File.join((ENV['TMPDIR'] || ENV['TMP'] || ENV['TEMP'] || '/tmp'), "temp.#{$$}.#{Time.now.to_f}")
- end while(File.exist?(path))
- FileUtils.mkdir_p path
- if block
- result = block.call(path)
- FileUtils.rm_rf(path)
- end
- result || path
- end
- end
- module GAE; end
- class GAE::SDK
- attr_reader :status
- def upload(email, password, path="./")
- `cd "#{path}"; appcfg.rb update ./`
- Open3.popen3('cd "%s"; appcfg.sh --email="%s" --passin update "."' % [path, email]) do |stdin, stdout, stderr|
- stdin.puts password
- stdin.close
- @status, @lines = nil, []
- stdout.each do |line|
- line.chomp!
- @lines << line
- if "Update completed successfully." == line
- @status = "successfully"
- elsif /^Unable to upload app: Email .* and password do not match/.match(line)
- @status = "authentication error"
- elsif /^409 Conflict/.match(line)
- @status = "Conflict"
- end
- end
- end
- end # def initialize
- def upload_zip(email, password, zip)
- Tempdir.path do |dir|
- Zip::ZipInputStream.open(zip) do |stream|
- while (entry = stream.get_next_entry)
- next if /\.\./.match(entry.name)
- file_path = File.join(dir, entry.name)
- if file_path[-1..-1] == '/'
- FileUtils.makedirs(file_path)
- else
- FileUtils.makedirs(File.dirname(file_path))
- File.open(file_path,'w') { |f| f.write stream.read }
- end
- end
- end # Zip::ZipInputStream.open(zip) do |stream|
- upload(email, password, dir)
- # p @lines
- end
- end
- end
- sdk = GAE::SDK.new
- sdk.upload_zip("XXXXX@gmail.com", "XXXXX", "app.zip")
- p sdk.status
Add Comment
Please, Sign In to add comment