Skip to content

Commit

Permalink
Lots of style changes and switch to https://rubygems.org
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelkadolph committed Apr 7, 2013
1 parent 8125f1e commit 62e7e7e
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 87 deletions.
33 changes: 33 additions & 0 deletions .gemspec.rb
@@ -0,0 +1,33 @@
class Readme < String
attr_reader :path

def initialize(path)
@path = path
super(File.read(self.path))
end

def summary
if self =~ /^# (?:\S+)\s+(.+?)\s{2,}/m
scrub $1
else
raise "could not find summary in #{path}"
end
end

def description
if self =~ /^## Description\s+(.+?)\s{2,}/m
scrub $1
else
raise "could not find description in #{path}"
end
end

private
def scrub(string)
string.delete("\\`").gsub(/\[([^\]]+)\]\([^)]*\)/, "\\1").tr("\n", " ").to_s
end
end

def readme(path = File.expand_path("./README.md"))
(@readmes ||= {})[path] ||= Readme.new(path)
end
6 changes: 2 additions & 4 deletions .gitignore
@@ -1,4 +1,2 @@
*.gem
.bundle
Gemfile.lock
pkg/*
/Gemfile.lock
/pkg
2 changes: 1 addition & 1 deletion Gemfile
@@ -1,3 +1,3 @@
source "http://rubygems.org"
source "https://rubygems.org"

gemspec
35 changes: 19 additions & 16 deletions LICENSE
@@ -1,19 +1,22 @@
Copyright (C) 2011 by Samuel Kadolph
Copyright (c) 2011 Samuel Kadolph

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
MIT License

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 changes: 17 additions & 12 deletions README.md
@@ -1,23 +1,28 @@
[![Gem Version](https://badge.fury.io/rb/s3cmd.png)](http://badge.fury.io/rb/s3cmd)
[![Dependency Status](https://gemnasium.com/samuelkadolph/s3cmd.png)](https://gemnasium.com/samuelkadolph/s3cmd)
[![Code Climate](https://codeclimate.com/github/samuelkadolph/s3cmd.png)](https://codeclimate.com/github/samuelkadolph/s3cmd)

# s3cmd

## Installing
`s3cmd` is simple cli tool for interacting with S3.

### Recommended
## Description

```
gem install s3cmd
```
Provides a `s3cmd` executable that allows you to create and list buckets as well as list the keys of a bucket and get and upload files to S3.

### Edge
## Installation

```
git clone https://github.com/samuelkadolph/s3cmd
cd s3cmd && rake install
```
Install with:

$ gem install s3cmd

## Usage

```
s3cmd create-bucket foo
s3cmd put foo abc/def somefile
s3cmd create-bucket $(USER)-foo
s3cmd put $(USER)-foo file.rb file.rb
```

## Contributing

Fork, branch & pull request.
2 changes: 2 additions & 0 deletions Rakefile
@@ -1 +1,3 @@
#!/usr/bin/env rake

require "bundler/gem_tasks"
3 changes: 2 additions & 1 deletion bin/s3cmd 100644 → 100755
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby

require "s3cmd"
S3Cmd::Main.start

S3Cmd::CLI.start
77 changes: 45 additions & 32 deletions lib/s3cmd.rb
@@ -1,13 +1,18 @@
require "rubygems"
require "aws"
require "logger"
require "mime/types"
require "proxifier/env"
require "rubygems"
require "thor"

module S3Cmd
require "s3cmd/version"

class Main < Thor
class CLI < Thor
class_option :access_key, :aliases => :a, :desc => "AWS access key to use"
class_option :credentials_file, :aliases => :c, :desc => "AWS credentials file containing the access and secret key", :default => File.expand_path("~/.aws-credentials")
class_option :secret_key, :aliases => :s, :desc => "AWS secret key to use"

desc "list-buckets", "lists all of your buckets"
def list_buckets
puts s3.buckets
Expand All @@ -16,7 +21,7 @@ def list_buckets
desc "create-bucket name", "creates a bucket"
method_option :region, :default => "US"
def create_bucket(name)
bucket = s3.bucket(name, true)
s3.bucket(name, true)
end

desc "list-keys bucket", "list the keys of a bucket"
Expand All @@ -26,49 +31,57 @@ def list_keys(bucket)

desc "get bucket key", "get the file for the key from the bucket"
def get(bucket, key)
bucket = s3.bucket(bucket)
$stdout << bucket.get(key)
puts s3.bucket(bucket).get(key)
end

desc "put bucket key file", "puts a file for the key in the bucket"
method_option :type, :desc => "override the content type of the file", :type => :string
option :type, :desc => "override the content type of the file"
def put(bucket, key, file)
bucket = s3.bucket(bucket)
type = options[:type] || MIME::Types.of(file).first.to_s
File.open(file, "r") { |f| bucket.put(key, f, {}, nil, { "content-type" => type }) }
end

private
def s3
@s3 ||= begin
access_key, secret_key = nil, nil

if ENV["AWS_CREDENTIAL_FILE"]
File.open(ENV["AWS_CREDENTIAL_FILE"]) do |file|
file.lines.each do |line|
access_key = $1 if line =~ /^AWSAccessKeyId=(.*)$/
secret_key = $1 if line =~ /^AWSSecretKey=(.*)$/
end
end
elsif ENV["AWS_ACCESS_KEY"] || ENV["AWS_SECRET_KEY"]
access_key = ENV["AWS_ACCESS_KEY"]
secret_key = ENV["AWS_SECRET_KEY"]
end
def credentials
return @credentials if defined?(@credentials)

unless access_key
$stderr.puts "AWS_CREDENTIAL_FILE must containt AWSAccessKeyId or AWS_ACCESS_KEY must be set"
exit 1
end
unless secret_key
$stderr.puts "AWS_CREDENTIAL_FILE must containt AWSSecretKey or AWS_SECRET_KEY must be set"
exit 1
access_key = secret_key = nil

if options[:access_key] || options[:secret_key]
access_key = options[:access_key]
secret_key = options[:secret_key]
else
File.open(options[:credentials_file]) do |file|
file.lines.each do |line|
access_key = $1 if line =~ /^AWSAccessKeyId=(.*)$/
secret_key = $1 if line =~ /^AWSSecretKey=(.*)$/
end
end
end

logger = Logger.new(STDERR)
logger.level = Logger::FATAL
@credentials = [access_key, secret_key]
end

Aws::S3.new(access_key, secret_key, :logger => logger)
end
def s3
return @s3 if defined?(@s3)

access_key, secret_key = credentials

unless access_key
$stderr.puts("No access key provided")
exit 1
end

unless secret_key
$stderr.puts("No secret key provided")
exit 1
end

logger = Logger.new(STDERR)
logger.level = Logger::FATAL

@s3 = Aws::S3.new(access_key, secret_key, :logger => logger)
end
end
end
2 changes: 1 addition & 1 deletion lib/s3cmd/version.rb
@@ -1,3 +1,3 @@
module S3Cmd
VERSION = "1.0.1"
VERSION = "1.1.0"
end
39 changes: 19 additions & 20 deletions s3cmd.gemspec
@@ -1,25 +1,24 @@
$:.push File.expand_path("../lib", __FILE__)
require "s3cmd/version"
require File.expand_path("../.gemspec", __FILE__)
require File.expand_path("../lib/s3cmd/version", __FILE__)

Gem::Specification.new do |s|
s.name = "s3cmd"
s.version = S3Cmd::VERSION
s.authors = ["Samuel Kadolph"]
s.email = ["samuel@kadolph.com"]
s.homepage = "https://github.com/samuelkadolph/s3cmd"
s.summary = %q{Simple cli tool for interacting with S3.}
s.description = <<-DESC
Provides a s3cmd binary that allows you to create and list buckets as well as list the keys of a bucket and get and upload files
to s3.
DESC
Gem::Specification.new do |gem|
gem.name = "s3cmd"
gem.authors = ["Samuel Kadolph"]
gem.email = ["samuel@kadolph.com"]
gem.description = readme.description
gem.summary = readme.summary
gem.homepage = "https://github.com/samuelkadolph/s3cmd"
gem.version = S3Cmd::VERSION

s.required_ruby_version = ">= 1.8.7"
gem.files = Dir["bin/*", "lib/**/*"]
gem.executables = Dir["bin/*"].map(&File.method(:basename))

s.files = Dir["bin/*", "lib/**/*"] + ["LICENSE", "README.md"]
s.executables = ["s3cmd"]
gem.required_ruby_version = ">= 1.8.7"

s.add_dependency "aws", "~> 2.5.6"
s.add_dependency "mime-types", "~> 1.16"
s.add_dependency "proxifier", "~> 1.0.2"
s.add_dependency "thor", "~> 0.14.6"
gem.add_dependency "aws", "~> 2.8.0"
gem.add_dependency "mime-types", "~> 1.22"
gem.add_dependency "proxifier", "~> 1.0.3"
gem.add_dependency "thor", "~> 0.18.1"

gem.add_development_dependency "rake", "~> 10.0.4"
end

0 comments on commit 62e7e7e

Please sign in to comment.