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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f1dd7e4804418aee548e48684b4f6bb09b6cb896
4
- data.tar.gz: 949e6e8c140085a942bb9e12b154e7dc0c4594a3
3
+ metadata.gz: 6dabcc887bc5df0a719dbabb7d7a93c0bf1c9695
4
+ data.tar.gz: 64df41679c66aec92b13afe93a00584ff4b141ff
5
5
  SHA512:
6
- metadata.gz: c63d7d3c1a8bb5568ecc0d291008c54fe491e0e834d986c1a5b03d94b08ff90470908e64663b630a25d4411977dc55f22597152a34af200263f9b9c922193a8a
7
- data.tar.gz: c5b96729fea2a0a1fb99bf4d6a283edb9f45d185458c3c76c156b6e84ac9df196ee6d41ac26dc7e86f48c9dbda6e74dd92c2723a8683db6c2932cc16eea98544
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, :fog_directory, :connection
4
+ attr_accessor :username, :api_key, :container_name, :connection
5
5
 
6
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)
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=fog_directory)
14
- @container ||= connection.container(container_name)
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
@@ -1,3 +1,3 @@
1
1
  module CloudFilesTransfer
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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
- username = ask("Origin username:")
7
- api_key = ask("Origin API key:")
8
- fog_directory = ask("Origin container name:")
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
- fog_directory: fog_directory
14
+ container: container
13
15
  )
14
16
 
15
- username = ask("Destination username:")
16
- api_key = ask("Destination API key:")
17
- fog_directory = ask("Destination container name:")
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
- fog_directory: fog_directory
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
- object = @container_from.object(path)
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.1
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-19 00:00:00.000000000 Z
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: ''