Class: Rack2Aws::FileManager

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ FileManager

Returns a new instance of FileManager.



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rack2aws.rb', line 16

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[:container])
  @aws_directory = aws.directories.get(options[:bucket])
  @nproc = options[:nproc]
  @allow_public = options[:public]
  @verbose_mode = options[:verbose]
  @files = []
  @total = 0
end

Instance Attribute Details

#allow_publicObject (readonly)

Returns the value of attribute allow_public.



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

def allow_public
  @allow_public
end

#awsObject (readonly)

Returns the value of attribute aws.



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

def aws
  @aws
end

#aws_directoryObject (readonly)

Returns the value of attribute aws_directory.



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

def aws_directory
  @aws_directory
end

#filesObject (readonly)

Returns the value of attribute files.



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

def files
  @files
end

#nprocObject (readonly)

Returns the value of attribute nproc.



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

def nproc
  @nproc
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



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

def per_page
  @per_page
end

#rackspaceObject (readonly)

Returns the value of attribute rackspace.



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

def rackspace
  @rackspace
end

#rackspace_directoryObject (readonly)

Returns the value of attribute rackspace_directory.



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

def rackspace_directory
  @rackspace_directory
end

#totalObject (readonly)

Returns the value of attribute total.



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

def total
  @total
end

#verbose_modeObject (readonly)

Returns the value of attribute verbose_mode.



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

def verbose_mode
  @verbose_mode
end

Instance Method Details

#copyObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rack2aws.rb', line 34

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



30
31
32
# File 'lib/rack2aws.rb', line 30

def default_options
  { :per_page => 10000, :public => false, :verbose => false }
end