cloud_files_transfer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/cloud_files_transfer.gemspec +22 -0
- data/lib/cloud_files_transfer/client.rb +30 -0
- data/lib/cloud_files_transfer/container.rb +38 -0
- data/lib/cloud_files_transfer/version.rb +3 -0
- data/lib/cloud_files_transfer.rb +14 -0
- data/lib/tasks/cloud_files_assets.rake +42 -0
- metadata +71 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f1dd7e4804418aee548e48684b4f6bb09b6cb896
|
4
|
+
data.tar.gz: 949e6e8c140085a942bb9e12b154e7dc0c4594a3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c63d7d3c1a8bb5568ecc0d291008c54fe491e0e834d986c1a5b03d94b08ff90470908e64663b630a25d4411977dc55f22597152a34af200263f9b9c922193a8a
|
7
|
+
data.tar.gz: c5b96729fea2a0a1fb99bf4d6a283edb9f45d185458c3c76c156b6e84ac9df196ee6d41ac26dc7e86f48c9dbda6e74dd92c2723a8683db6c2932cc16eea98544
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Mathieu Gagné
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# CloudFilesTransfer
|
2
|
+
|
3
|
+
Transfer Rackspace Cloud Files assets from one container to another or from account to another.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'cloud_files_transfer'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install cloud_files_transfer
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Have Rackspace username, api key and container name ready for both origin and destination folders.
|
22
|
+
|
23
|
+
$ rake cloud_files_assets:transfer
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cloud_files_transfer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cloud_files_transfer"
|
8
|
+
spec.version = CloudFilesTransfer::VERSION
|
9
|
+
spec.authors = ["Mathieu Gagné"]
|
10
|
+
spec.email = ["gagne.mathieu@hotmail.com"]
|
11
|
+
spec.description = %q{Transfer Rackspace Cloud Files assets from one container to another or from account to another.}
|
12
|
+
spec.summary = %q{Transfer Rackspace Cloud Files assets from one container to another or from account to another.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "cloudfiles"
|
22
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module CloudFilesTransfer
|
2
|
+
class Client
|
3
|
+
|
4
|
+
attr_accessor :username, :api_key, :fog_directory, :connection
|
5
|
+
|
6
|
+
def initialize(args={})
|
7
|
+
@username = args.fetch(:username, credentials[:rackspace_username])
|
8
|
+
@api_key = args.fetch(:api_key, credentials[:rackspace_api_key])
|
9
|
+
@fog_directory = args.fetch(:fog_directory, CarrierWave::Uploader::Base.fog_directory)
|
10
|
+
@connection = args.fetch(:connection, create_connection)
|
11
|
+
end
|
12
|
+
|
13
|
+
def container(container_name=fog_directory)
|
14
|
+
@container ||= connection.container(container_name)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def create_connection
|
20
|
+
c = CloudFiles::Connection.new(username: username, api_key: api_key)
|
21
|
+
puts "Connection established."
|
22
|
+
c
|
23
|
+
end
|
24
|
+
|
25
|
+
def credentials
|
26
|
+
@credentials ||= CarrierWave::Uploader::Base.fog_credentials
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module CloudFilesTransfer
|
2
|
+
class Container
|
3
|
+
|
4
|
+
attr_accessor :container, :skip_existing_object
|
5
|
+
|
6
|
+
delegate :object_exists?, :create_object, to: :container
|
7
|
+
|
8
|
+
def initialize(container, args={})
|
9
|
+
@container = container
|
10
|
+
@skip_existing_object = args.fetch(:skip_existing_object, true)
|
11
|
+
end
|
12
|
+
|
13
|
+
def transfer(object)
|
14
|
+
return skip_message(object.name) if skip_existing_object and object_exists?(object.name)
|
15
|
+
retries = 0
|
16
|
+
puts "Saving #{object.name}"
|
17
|
+
begin
|
18
|
+
copy = create_object(object.name)
|
19
|
+
copy.write(object.data)
|
20
|
+
rescue Exception
|
21
|
+
retries = retries + 1
|
22
|
+
unless retries > 5
|
23
|
+
puts "#{object.name} failed. Retry"
|
24
|
+
retry
|
25
|
+
else
|
26
|
+
puts "#{object.name} failed."
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def skip_message(object_name)
|
34
|
+
puts "#{object_name} skipped."
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'cloudfiles'
|
2
|
+
require "cloud_files_transfer/version"
|
3
|
+
require 'cloud_files_transfer/client'
|
4
|
+
require 'cloud_files_transfer/container'
|
5
|
+
|
6
|
+
module CloudFilesTransfer
|
7
|
+
class Railtie < Rails::Railtie
|
8
|
+
|
9
|
+
rake_tasks do
|
10
|
+
Dir[File.join(File.dirname(__FILE__),'tasks/*.rake')].each { |f| load f }
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
namespace :cloud_files_assets do
|
2
|
+
|
3
|
+
desc "Copy assets from one container to another container"
|
4
|
+
task transfer: :environment do
|
5
|
+
|
6
|
+
username = ask("Origin username:")
|
7
|
+
api_key = ask("Origin API key:")
|
8
|
+
fog_directory = ask("Origin container name:")
|
9
|
+
@client_from = CloudFilesTransfer::Client.new(
|
10
|
+
username: username,
|
11
|
+
api_key: api_key,
|
12
|
+
fog_directory: fog_directory
|
13
|
+
)
|
14
|
+
|
15
|
+
username = ask("Destination username:")
|
16
|
+
api_key = ask("Destination API key:")
|
17
|
+
fog_directory = ask("Destination container name:")
|
18
|
+
@client_to = CloudFilesTransfer::Client.new(
|
19
|
+
username: username,
|
20
|
+
api_key: api_key,
|
21
|
+
fog_directory: fog_directory
|
22
|
+
)
|
23
|
+
|
24
|
+
@container_from = @client_from.container
|
25
|
+
@container_to = CloudFilesTransfer::Container.new(@client_to.container)
|
26
|
+
|
27
|
+
@container_from.objects.each do |path|
|
28
|
+
object = @container_from.object(path)
|
29
|
+
@container_to.transfer(object)
|
30
|
+
end
|
31
|
+
|
32
|
+
puts "Done."
|
33
|
+
|
34
|
+
@client_to.container.refresh
|
35
|
+
end
|
36
|
+
|
37
|
+
def ask question
|
38
|
+
STDOUT.puts question
|
39
|
+
STDIN.gets.chomp
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cloud_files_transfer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mathieu Gagné
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: cloudfiles
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Transfer Rackspace Cloud Files assets from one container to another or
|
28
|
+
from account to another.
|
29
|
+
email:
|
30
|
+
- gagne.mathieu@hotmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- .gitignore
|
36
|
+
- Gemfile
|
37
|
+
- LICENSE.txt
|
38
|
+
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- cloud_files_transfer.gemspec
|
41
|
+
- lib/cloud_files_transfer.rb
|
42
|
+
- lib/cloud_files_transfer/client.rb
|
43
|
+
- lib/cloud_files_transfer/container.rb
|
44
|
+
- lib/cloud_files_transfer/version.rb
|
45
|
+
- lib/tasks/cloud_files_assets.rake
|
46
|
+
homepage: ''
|
47
|
+
licenses:
|
48
|
+
- MIT
|
49
|
+
metadata: {}
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 2.1.11
|
67
|
+
signing_key:
|
68
|
+
specification_version: 4
|
69
|
+
summary: Transfer Rackspace Cloud Files assets from one container to another or from
|
70
|
+
account to another.
|
71
|
+
test_files: []
|