Module: DHO

Included in:
PRM::Repo
Defined in:
lib/prm/repo.rb

Instance Method Summary collapse

Instance Method Details

#sync_to_dho(path, accesskey, secretkey, pcomponent, prelease) ⇒ Object



413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# File 'lib/prm/repo.rb', line 413

def sync_to_dho(path, accesskey, secretkey,pcomponent,prelease)
  component = pcomponent.join
  release = prelease.join
  AWS::S3::Base.establish_connection!(
    :server             => 'objects.dreamhost.com',
    :use_ssl            => true,
    :access_key_id      => accesskey,
    :secret_access_key  => secretkey
  )

  AWS::S3::Service.buckets.each do |bucket|
    unless bucket == path
      AWS::S3::Bucket.create(path)
    end
  end

  new_content = Array.new
  Find.find(path + "/") do |object|
    object.slice!(path + "/")
    if (object =~ /deb$/) || (object =~ /Release$/) || (object =~ /Packages.gz$/) || (object =~ /Packages$/) || (object =~ /gpg$/)
      f = path + "/" + object
      new_content << object
      AWS::S3::S3Object.store(
        object,
        open(f),
        path
      )

      policy = AWS::S3::S3Object.acl(object, path)
      policy.grants = [ AWS::S3::ACL::Grant.grant(:public_read) ]
      AWS::S3::S3Object.acl(object,path,policy)
    end
  end

  bucket_info = AWS::S3::Bucket.find(path)
  bucket_info.each do |obj|
    o = obj.key
    if (o =~ /deb$/) || (o =~ /Release$/) || (o =~ /Packages.gz$/) || (o =~ /Packages$/) || (o =~ /gpg$/)
      unless new_content.include?(o)
        AWS::S3::S3Object.delete(o,path)
      end
    end
  end
  puts "Your apt repository is located at http://objects.dreamhost.com/#{path}/"
  puts "Add the following to your apt sources.list"
  puts "deb http://objects.dreamhost.com/#{path}/ #{release} #{component}"
end