Class: Rack2Aws::FileManager
- Inherits:
-
Object
- Object
- Rack2Aws::FileManager
- Includes:
- Configuration
- Defined in:
- lib/rack2aws.rb
Instance Attribute Summary collapse
-
#allow_public ⇒ Object
readonly
Returns the value of attribute allow_public.
-
#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.
-
#nproc ⇒ Object
readonly
Returns the value of attribute nproc.
-
#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 = {}) ⇒ FileManager
constructor
A new instance of FileManager.
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(={}) = .merge() @per_page = [:per_page] @rackspace = Fog::Storage.new(RackspaceConfig.load()) @aws = Fog::Storage.new(AWSConfig.load()) @rackspace_directory = rackspace.directories.get([:container]) @aws_directory = aws.directories.get([:bucket]) @nproc = [:nproc] @allow_public = [:public] @verbose_mode = [:verbose] @files = [] @total = 0 end |
Instance Attribute Details
#allow_public ⇒ Object (readonly)
Returns the value of attribute allow_public.
12 13 14 |
# File 'lib/rack2aws.rb', line 12 def allow_public @allow_public end |
#aws ⇒ Object (readonly)
Returns the value of attribute aws.
12 13 14 |
# File 'lib/rack2aws.rb', line 12 def aws @aws end |
#aws_directory ⇒ Object (readonly)
Returns the value of attribute aws_directory.
12 13 14 |
# File 'lib/rack2aws.rb', line 12 def aws_directory @aws_directory end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
12 13 14 |
# File 'lib/rack2aws.rb', line 12 def files @files end |
#nproc ⇒ Object (readonly)
Returns the value of attribute nproc.
12 13 14 |
# File 'lib/rack2aws.rb', line 12 def nproc @nproc end |
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page.
12 13 14 |
# File 'lib/rack2aws.rb', line 12 def per_page @per_page end |
#rackspace ⇒ Object (readonly)
Returns the value of attribute rackspace.
12 13 14 |
# File 'lib/rack2aws.rb', line 12 def rackspace @rackspace end |
#rackspace_directory ⇒ Object (readonly)
Returns the value of attribute rackspace_directory.
12 13 14 |
# File 'lib/rack2aws.rb', line 12 def rackspace_directory @rackspace_directory end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
12 13 14 |
# File 'lib/rack2aws.rb', line 12 def total @total end |
#verbose_mode ⇒ Object (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
#copy ⇒ Object
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_options ⇒ Object
30 31 32 |
# File 'lib/rack2aws.rb', line 30 def { :per_page => 10000, :public => false, :verbose => false } end |