cloud_files_transfer 0.0.2 → 0.0.3

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: 6dabcc887bc5df0a719dbabb7d7a93c0bf1c9695
4
- data.tar.gz: 64df41679c66aec92b13afe93a00584ff4b141ff
3
+ metadata.gz: 356cd5bc6fd194469f9562ddd87c3d5b36064f3e
4
+ data.tar.gz: e25d1224aa740f0d72b90ab9c53713ada43f3f30
5
5
  SHA512:
6
- metadata.gz: d721ead167abba4749178b9264352cf8bef0863c900482ba6e13be7bb14882155fd199fac20836cf785221f09bb32df528fcf1e0188b6c50172088327402ddf6
7
- data.tar.gz: 1b8d64255dcf5e9714827a512064b97b4a8d7955e8b6e12a084b6d646c31df03eb359154f4b6c29bfa0e12212f33135fbf3f9e85fdbb1475c0ed0374af52cb62
6
+ metadata.gz: 6151c334ea081670d8d2afc55cf8a3c5641f9632ffa2021d47edb63479693e05a9f1fb354d2340a59cb110e3a4c87031338c6baa864f0eae0016185de500fbe1
7
+ data.tar.gz: c9284dd36d6e6d502a5ab5ee238e792af2477c384bb509a9d4141137c466ffc03f43b469d9cc481551b9d3a6a6dd32837a41e72e26338105940cb5a4a9e51d0e
data/README.md CHANGED
@@ -21,15 +21,20 @@ Or install it yourself as:
21
21
  Have Rackspace username, api key and container name ready for both origin and destination folders.
22
22
  Or add a config yaml file to automatically pick the info from:
23
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
24
+ ```yaml
25
+ # config/cloudfiles.yml
26
+ origin:
27
+ username: rackspace_username
28
+ api_key: 1234567890abcdefghijklmnopqrstuv
29
+ container: container_name
30
+
31
+ destination:
32
+ username: rackspace_username
33
+ api_key: 1234567890abcdefghijklmnopqrstuv
34
+ container: container_name
35
+ ```
36
+
37
+ Then launch the rake task to start the transfer. It doesn't matter where you do it from. It could be faster though if done from a Rackspace instance using service net (snet).
33
38
 
34
39
  $ rake cloud_files_assets:transfer
35
40
 
@@ -1,12 +1,13 @@
1
1
  module CloudFilesTransfer
2
2
  class Client
3
3
 
4
- attr_accessor :username, :api_key, :container_name, :connection
4
+ attr_accessor :username, :api_key, :container_name, :snet, :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
- @container_name = args.fetch(:container, CarrierWave::Uploader::Base.fog_directory)
7
+ @username = args.fetch(:username) { raise 'Missing username'}
8
+ @api_key = args.fetch(:api_key) { raise 'Missing api_key'}
9
+ @container_name = args.fetch(:container) { raise 'Missing container'}
10
+ @snet = args.fetch(:snet, false)
10
11
  @connection = args.fetch(:connection, create_connection)
11
12
  end
12
13
 
@@ -17,14 +18,10 @@ module CloudFilesTransfer
17
18
  private
18
19
 
19
20
  def create_connection
20
- c = CloudFiles::Connection.new(username: username, api_key: api_key)
21
+ c = CloudFiles::Connection.new(username: username, api_key: api_key, snet: snet)
21
22
  puts "Connection established."
22
23
  c
23
24
  end
24
25
 
25
- def credentials
26
- @credentials ||= CarrierWave::Uploader::Base.fog_credentials
27
- end
28
-
29
26
  end
30
27
  end
@@ -10,7 +10,7 @@ module CloudFilesTransfer
10
10
  end
11
11
 
12
12
  def self.copy!(origin, destination, path, args={})
13
- return if destination.object_exists?(path)
13
+ return skip_message(path) if destination.object_exists?(path)
14
14
  new(origin, destination, path, args).copy
15
15
  end
16
16
 
@@ -32,5 +32,11 @@ module CloudFilesTransfer
32
32
  end
33
33
  end
34
34
 
35
+ private
36
+
37
+ def skip_message path
38
+ puts "#{path} skipped."
39
+ end
40
+
35
41
  end
36
42
  end
@@ -1,3 +1,3 @@
1
1
  module CloudFilesTransfer
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -3,30 +3,38 @@ 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
- config = YAML.load_file("config/cloudfiles.yml")
6
+ config = YAML.load_file("config/cloudfiles.yml")
7
+ config = HashWithIndifferentAccess.new(config)
7
8
 
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
+ username = config[:origin][:username] rescue ask("Origin username:")
10
+ api_key = config[:origin][:api_key] rescue ask("Origin API key:")
11
+ container = config[:origin][:container] rescue ask("Origin container name:")
12
+ snet = config[:origin][:snet] rescue false
11
13
  @client_from = CloudFilesTransfer::Client.new(
12
14
  username: username,
13
15
  api_key: api_key,
14
- container: container
16
+ container: container,
17
+ snet: snet
15
18
  )
16
19
 
17
20
  username = config["destination"]["username"] rescue ask("Destination username:")
18
21
  api_key = config["destination"]["api_key"] rescue ask("Destination API key:")
19
22
  container = config["destination"]["container"] rescue ask("Destination container name:")
23
+ snet = config["destination"]["snet"] rescue false
20
24
  @client_to = CloudFilesTransfer::Client.new(
21
25
  username: username,
22
26
  api_key: api_key,
23
- container: container
27
+ container: container,
28
+ snet: snet
24
29
  )
25
30
 
26
31
  @container_from = @client_from.container
27
32
  @container_to = CloudFilesTransfer::Container.new(@client_to.container)
33
+ @assets = @container_from.objects
28
34
 
29
- @container_from.objects.each do |path|
35
+ puts "Starting transfer. #{@assets.size} files to copy."
36
+
37
+ @assets.each do |path|
30
38
  CloudFilesTransfer::Transfer.copy!(@container_from, @container_to, path)
31
39
  end
32
40
 
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.2
4
+ version: 0.0.3
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-20 00:00:00.000000000 Z
11
+ date: 2014-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cloudfiles