cloud_files_transfer 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +11 -0
- data/lib/cloud_files_transfer/client.rb +7 -7
- data/lib/cloud_files_transfer/transfer.rb +36 -0
- data/lib/cloud_files_transfer/version.rb +1 -1
- data/lib/cloud_files_transfer.rb +2 -0
- data/lib/tasks/cloud_files_assets.rake +11 -10
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6dabcc887bc5df0a719dbabb7d7a93c0bf1c9695
|
4
|
+
data.tar.gz: 64df41679c66aec92b13afe93a00584ff4b141ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d721ead167abba4749178b9264352cf8bef0863c900482ba6e13be7bb14882155fd199fac20836cf785221f09bb32df528fcf1e0188b6c50172088327402ddf6
|
7
|
+
data.tar.gz: 1b8d64255dcf5e9714827a512064b97b4a8d7955e8b6e12a084b6d646c31df03eb359154f4b6c29bfa0e12212f33135fbf3f9e85fdbb1475c0ed0374af52cb62
|
data/README.md
CHANGED
@@ -19,6 +19,17 @@ Or install it yourself as:
|
|
19
19
|
## Usage
|
20
20
|
|
21
21
|
Have Rackspace username, api key and container name ready for both origin and destination folders.
|
22
|
+
Or add a config yaml file to automatically pick the info from:
|
23
|
+
|
24
|
+
origin:
|
25
|
+
username: rackspace_username
|
26
|
+
api_key: 1234567890abcdefghijklmnopqrstuv
|
27
|
+
container: container_name
|
28
|
+
|
29
|
+
destination:
|
30
|
+
username: rackspace_username
|
31
|
+
api_key: 1234567890abcdefghijklmnopqrstuv
|
32
|
+
container: container_name
|
22
33
|
|
23
34
|
$ rake cloud_files_assets:transfer
|
24
35
|
|
@@ -1,17 +1,17 @@
|
|
1
1
|
module CloudFilesTransfer
|
2
2
|
class Client
|
3
3
|
|
4
|
-
attr_accessor :username, :api_key, :
|
4
|
+
attr_accessor :username, :api_key, :container_name, :connection
|
5
5
|
|
6
6
|
def initialize(args={})
|
7
|
-
@username
|
8
|
-
@api_key
|
9
|
-
@
|
10
|
-
@connection
|
7
|
+
@username = args.fetch(:username, credentials[:rackspace_username])
|
8
|
+
@api_key = args.fetch(:api_key, credentials[:rackspace_api_key])
|
9
|
+
@container_name = args.fetch(:container, CarrierWave::Uploader::Base.fog_directory)
|
10
|
+
@connection = args.fetch(:connection, create_connection)
|
11
11
|
end
|
12
12
|
|
13
|
-
def container(container_name
|
14
|
-
@container ||= connection.container(
|
13
|
+
def container(name=container_name)
|
14
|
+
@container ||= connection.container(name)
|
15
15
|
end
|
16
16
|
|
17
17
|
private
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module CloudFilesTransfer
|
2
|
+
class Transfer
|
3
|
+
|
4
|
+
attr_accessor :origin, :destination, :path
|
5
|
+
|
6
|
+
def initialize(origin, destination, path, args={})
|
7
|
+
@origin = origin
|
8
|
+
@destination = destination
|
9
|
+
@path = path
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.copy!(origin, destination, path, args={})
|
13
|
+
return if destination.object_exists?(path)
|
14
|
+
new(origin, destination, path, args).copy
|
15
|
+
end
|
16
|
+
|
17
|
+
def copy
|
18
|
+
retries = 0
|
19
|
+
puts "Saving #{path}"
|
20
|
+
begin
|
21
|
+
origin_object = origin.object(path)
|
22
|
+
desintation_object = destination.create_object(path)
|
23
|
+
desintation_object.write(origin_object.data)
|
24
|
+
rescue Exception
|
25
|
+
retries = retries + 1
|
26
|
+
unless retries > 5
|
27
|
+
puts "#{path} failed. Retry"
|
28
|
+
retry
|
29
|
+
else
|
30
|
+
puts "#{path} failed."
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/lib/cloud_files_transfer.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'cloudfiles'
|
2
|
+
require 'yaml'
|
2
3
|
require "cloud_files_transfer/version"
|
3
4
|
require 'cloud_files_transfer/client'
|
4
5
|
require 'cloud_files_transfer/container'
|
6
|
+
require 'cloud_files_transfer/transfer'
|
5
7
|
|
6
8
|
module CloudFilesTransfer
|
7
9
|
class Railtie < Rails::Railtie
|
@@ -3,30 +3,31 @@ namespace :cloud_files_assets do
|
|
3
3
|
desc "Copy assets from one container to another container"
|
4
4
|
task transfer: :environment do
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
config = YAML.load_file("config/cloudfiles.yml")
|
7
|
+
|
8
|
+
username = config["origin"]["username"] rescue ask("Origin username:")
|
9
|
+
api_key = config["origin"]["api_key"] rescue ask("Origin API key:")
|
10
|
+
container = config["origin"]["container"] rescue ask("Origin container name:")
|
9
11
|
@client_from = CloudFilesTransfer::Client.new(
|
10
12
|
username: username,
|
11
13
|
api_key: api_key,
|
12
|
-
|
14
|
+
container: container
|
13
15
|
)
|
14
16
|
|
15
|
-
username = ask("Destination username:")
|
16
|
-
api_key = ask("Destination API key:")
|
17
|
-
|
17
|
+
username = config["destination"]["username"] rescue ask("Destination username:")
|
18
|
+
api_key = config["destination"]["api_key"] rescue ask("Destination API key:")
|
19
|
+
container = config["destination"]["container"] rescue ask("Destination container name:")
|
18
20
|
@client_to = CloudFilesTransfer::Client.new(
|
19
21
|
username: username,
|
20
22
|
api_key: api_key,
|
21
|
-
|
23
|
+
container: container
|
22
24
|
)
|
23
25
|
|
24
26
|
@container_from = @client_from.container
|
25
27
|
@container_to = CloudFilesTransfer::Container.new(@client_to.container)
|
26
28
|
|
27
29
|
@container_from.objects.each do |path|
|
28
|
-
|
29
|
-
@container_to.transfer(object)
|
30
|
+
CloudFilesTransfer::Transfer.copy!(@container_from, @container_to, path)
|
30
31
|
end
|
31
32
|
|
32
33
|
puts "Done."
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloud_files_transfer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mathieu Gagné
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cloudfiles
|
@@ -41,6 +41,7 @@ files:
|
|
41
41
|
- lib/cloud_files_transfer.rb
|
42
42
|
- lib/cloud_files_transfer/client.rb
|
43
43
|
- lib/cloud_files_transfer/container.rb
|
44
|
+
- lib/cloud_files_transfer/transfer.rb
|
44
45
|
- lib/cloud_files_transfer/version.rb
|
45
46
|
- lib/tasks/cloud_files_assets.rake
|
46
47
|
homepage: ''
|