Class: Rack2Aws::FileCopy

Inherits:
Object
  • Object
show all
Includes:
Configuration
Defined in:
lib/rack2aws.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options={})
  options = default_options.merge(options)
  @per_page = options[:per_page]
  @rackspace = Fog::Storage.new(RackspaceConfig.load())
  @aws = Fog::Storage.new(AWSConfig.load())

  @rackspace_directory = rackspace.directories.get(options[:rackspace_container])
  @aws_directory = aws.directories.get(options[:aws_bucket])
  @verbose_mode = options[:verbose]
  @files = []
  @total = 0
end

Instance Attribute Details

#awsObject (readonly)

Returns the value of attribute aws.



11
12
13
# File 'lib/rack2aws.rb', line 11

def aws
  @aws
end

#aws_directoryObject (readonly)

Returns the value of attribute aws_directory.



11
12
13
# File 'lib/rack2aws.rb', line 11

def aws_directory
  @aws_directory
end

#filesObject (readonly)

Returns the value of attribute files.



11
12
13
# File 'lib/rack2aws.rb', line 11

def files
  @files
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



11
12
13
# File 'lib/rack2aws.rb', line 11

def per_page
  @per_page
end

#rackspaceObject (readonly)

Returns the value of attribute rackspace.



11
12
13
# File 'lib/rack2aws.rb', line 11

def rackspace
  @rackspace
end

#rackspace_directoryObject (readonly)

Returns the value of attribute rackspace_directory.



11
12
13
# File 'lib/rack2aws.rb', line 11

def rackspace_directory
  @rackspace_directory
end

#totalObject (readonly)

Returns the value of attribute total.



11
12
13
# File 'lib/rack2aws.rb', line 11

def total
  @total
end

#verbose_modeObject (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

#copyObject



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_optionsObject



26
27
28
# File 'lib/rack2aws.rb', line 26

def default_options
  { :per_page => 10000 }
end