Created
February 18, 2010 03:29
-
-
Save pezra/307303 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.#!/usr/bin/env ruby | |
$KCODE='UTF8' | |
require 'rubygems' | |
require 'aws/s3' | |
require 'main' | |
main do | |
argument('directory') { | |
required | |
validate{|dir| File.directory?(dir)} | |
attr | |
} | |
argument('bucket') { | |
required | |
attr | |
} | |
def run | |
AWS::S3::Base.establish_connection!( | |
:access_key_id => File.read('aws-access-key-id'), | |
:secret_access_key => File.read('aws-secret-access-key') | |
) | |
STDOUT << "Pushing find in #{directory} to S3 bucket #{bucket}\n" | |
Dir.chdir(directory) do | |
Dir.glob('**/*') do |f| | |
next if File.directory?(f) | |
if AWS::S3::S3Object.exists?(f, bucket) | |
indicate_skipping | |
next | |
end | |
indicate_pushing(f) | |
AWS::S3::S3Object.store(f, open(f), bucket) | |
end | |
end | |
end | |
def indicate_skipping | |
STDOUT << '.' | |
STDOUT.flush | |
end | |
def indicate_pushing(file_name) | |
STDOUT << "\npushing #{file_name}" | |
STDOUT.flush | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment