Class: Pave::Files
- Inherits:
-
Object
show all
- Includes:
- Shell
- Defined in:
- lib/pave/files.rb
Class Method Summary
collapse
Methods included from Shell
#file_insert, included, #sh, #shell
Class Method Details
.backup_files(location = "local", remote) ⇒ Object
66
67
68
69
70
71
72
73
74
|
# 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 ⇒ Object
13
14
15
16
|
# 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 ⇒ Object
5
6
7
|
# File 'lib/pave/files.rb', line 5
def self.exclusions
" --exclude 'files/tmp' --exclude 'files/cache' "
end
|
.flags ⇒ Object
9
10
11
|
# File 'lib/pave/files.rb', line 9
def self.flags
" -uazh -e ssh --progress "
end
|
.pull(remote = "live", method = "zip") ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# 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") ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# 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") ⇒ Object
.remove_zipped_files ⇒ Object
86
87
88
89
|
# 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") ⇒ Object
56
57
58
59
|
# File 'lib/pave/files.rb', line 56
def self.sync(remote="live")
pull(remote)
push(remote)
end
|
.unzip_files(location = "local", remote) ⇒ Object
76
77
78
79
80
81
82
83
84
|
# 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") ⇒ Object
61
62
63
64
|
# 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
|