Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 52 lines (41 sloc) 1.08 KB
#!/usr/bin/env ruby
## To background this process start it by typing:
#### ruby sync.rb
## Then type:
#### ctrl-z
#### bg
require 'rubygems'
require 'bundler'
Bundler.require
class Sync
def file(path)
File.dirname(__FILE__) + path.gsub(/^./,'')
end
def run
dw = DirectoryWatcher.new '.',
:glob => 'temp/*',
:scanner => :rev,
:interval => 1.0,
:stable => 2,
:pre_load => true
cf = CloudFiles::Connection.new(:username => "YOUR_USERNAME", :api_key => "YOUR_APIKEY")
container = cf.create_container('a_container_somewhere')
dw.add_observer do |*args|
args.each do |event|
if event.type == :added
puts "Created #{event.path}..."
container.create_object(File.basename(event.path))
elsif event.type == :stable
puts "Uploading #{event.path}..."
object = container.create_object(File.basename(event.path))
object.write(open(file(event.path)))
puts "Done.\n\n"
end
end
end
dw.start
gets
end
end
sync = Sync.new
sync.run
Something went wrong with that request. Please try again.