class Pave::Files

Public Class Methods

backup_files(location="local", remote) click to toggle source
# File lib/pave/files.rb, line 66
def self.backup_files(location="local", remote)
  if location == "local"
    zip_files('local')
  else
    server = Pave::Remote.server(remote)
    directory = Pave::Remote.directory(remote)
    sh "ssh #{server} \"cd #{directory}; zip -9 -r tmp_files_zip_remote.zip ./files\""
  end
end
clear_cache() click to toggle source
# File lib/pave/files.rb, line 13
def self.clear_cache
  say "Clearing Cache"
  sh "sudo rm -rf ./files/tmp; sudo rm -rf ./files/cache;"
end
exclusions() click to toggle source
# File lib/pave/files.rb, line 5
def self.exclusions
  " --exclude 'files/tmp' --exclude 'files/cache' "
end
flags() click to toggle source
# File lib/pave/files.rb, line 9
def self.flags
  " -uazh -e ssh --progress "
end
pull(remote="live", method="zip") click to toggle source
# File lib/pave/files.rb, line 37
def self.pull(remote="live", method="zip")
  server = Pave::Remote.server(remote)
  directory = Pave::Remote.directory(remote)
  clear_cache
  if method == "rsync"
    sh "rsync #{flags} #{exclusions} #{server}:#{directory}/files/* ./files/*"
  else
    if backup_files('local')
      if backup_files('remote', remote)
        say "Downloading zip from remote server"
        sh "scp #{remote_url}/tmp_files_zip_remote.zip ./"
        if unzip_files('local')
          remove_zipped_files
        end
      end
    end
  end
end
push(remote="live", method="zip") click to toggle source
# File lib/pave/files.rb, line 18
def self.push(remote="live", method="zip")
  server = Pave::Remote.server(remote)
  directory = Pave::Remote.directory(remote)
  clear_cache
  if method == "rsync"
    sh "rsync #{flags} #{exclusions} ./files/* #{server}:#{directory}/files/*"
  else
    zip_files('local')
    say "Pushing zip to remote server"
    sh "scp ./tmp_files_zip_local.zip #{remote_url}"
    if backup_files('remote', remote)
      if unzip_files('remote', remote)
        remove_zipped_files
      end
    end
    say "Done"
  end
end
remote_url(remote="live") click to toggle source
# File lib/pave/files.rb, line 91
def self.remote_url(remote="live")
  "#{Pave::Remote.server(remote)}:#{Pave::Remote.directory(remote)}"
end
remove_zipped_files() click to toggle source
# File lib/pave/files.rb, line 86
def self.remove_zipped_files
  say "Cleaning up"
  sh "rm -rf tmp_files_zip_local.zip; rm -rf tmp_files_zip_remote.zip"
end
sync(remote="live") click to toggle source
# File lib/pave/files.rb, line 56
def self.sync(remote="live")
  pull(remote)
  push(remote)
end
unzip_files(location="local", remote) click to toggle source
# File lib/pave/files.rb, line 76
def self.unzip_files(location="local", remote)
  if location == "local"
    sh "rm -rf ./files; unzip tmp_files_zip_remote.zip"
  else
    server = Pave::Remote.server(remote)
    directory = Pave::Remote.directory(remote)
    sh "ssh #{server} \"cd #{directory}; rm -rf files/; unzip tmp_files_zip_local.zip\""
  end
end
zip_files(location="local") click to toggle source
# File lib/pave/files.rb, line 61
def self.zip_files(location="local")
  say "Zipping local files"
  sh "zip -9 -r tmp_files_zip_#{location}.zip ./files"
end