Class: Rack2Aws::FileCopy
- Inherits:
-
Object
- Object
- Rack2Aws::FileCopy
- Includes:
- Configuration
- Defined in:
- lib/rack2aws.rb
Instance Attribute Summary collapse
-
#aws ⇒ Object
readonly
Returns the value of attribute aws.
-
#aws_directory ⇒ Object
readonly
Returns the value of attribute aws_directory.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#rackspace ⇒ Object
readonly
Returns the value of attribute rackspace.
-
#rackspace_directory ⇒ Object
readonly
Returns the value of attribute rackspace_directory.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
-
#verbose_mode ⇒ Object
readonly
Returns the value of attribute verbose_mode.
Instance Method Summary collapse
- #copy ⇒ Object
- #default_options ⇒ Object
-
#initialize(options = {}) ⇒ FileCopy
constructor
A new instance of FileCopy.
Constructor Details
#initialize(options = {}) ⇒ FileCopy
Returns a new instance of FileCopy.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rack2aws.rb', line 13 def initialize(={}) = .merge() @per_page = [:per_page] @rackspace = Fog::Storage.new(RackspaceConfig.load()) @aws = Fog::Storage.new(AWSConfig.load()) @rackspace_directory = rackspace.directories.get([:rackspace_container]) @aws_directory = aws.directories.get([:aws_bucket]) @verbose_mode = [:verbose] @files = [] @total = 0 end |
Instance Attribute Details
#aws ⇒ Object (readonly)
Returns the value of attribute aws.
11 12 13 |
# File 'lib/rack2aws.rb', line 11 def aws @aws end |
#aws_directory ⇒ Object (readonly)
Returns the value of attribute aws_directory.
11 12 13 |
# File 'lib/rack2aws.rb', line 11 def aws_directory @aws_directory end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
11 12 13 |
# File 'lib/rack2aws.rb', line 11 def files @files end |
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page.
11 12 13 |
# File 'lib/rack2aws.rb', line 11 def per_page @per_page end |
#rackspace ⇒ Object (readonly)
Returns the value of attribute rackspace.
11 12 13 |
# File 'lib/rack2aws.rb', line 11 def rackspace @rackspace end |
#rackspace_directory ⇒ Object (readonly)
Returns the value of attribute rackspace_directory.
11 12 13 |
# File 'lib/rack2aws.rb', line 11 def rackspace_directory @rackspace_directory end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
11 12 13 |
# File 'lib/rack2aws.rb', line 11 def total @total end |
#verbose_mode ⇒ Object (readonly)
Returns the value of attribute verbose_mode.
11 12 13 |
# File 'lib/rack2aws.rb', line 11 def verbose_mode @verbose_mode end |
Instance Method Details
#copy ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rack2aws.rb', line 30 def copy time = Time.now pages = rackspace_directory.count / per_page + 1 marker = '' # get Rackspace files pages.times do |i| puts "! Getting page #{i+1}..." files = rackspace_directory.files.all(:limit => per_page, :marker => marker).to_a puts "! #{files.size} files in page #{i+1}, forking..." if verbose_mode pid = fork do copy_files(i, files) end puts "! Process #{pid} forked to copy files" if verbose_mode marker = files.last.key @total += files.size end pages.times do Process.wait end puts "--------------------------------------------------" puts "! #{total} files copied in #{Time.now - time}secs." puts "--------------------------------------------------\n\n" end |
#default_options ⇒ Object
26 27 28 |
# File 'lib/rack2aws.rb', line 26 def { :per_page => 10000 } end |