-
Notifications
You must be signed in to change notification settings - Fork 1
/
fabfile.py
165 lines (138 loc) · 5.05 KB
/
fabfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
from fabric.api import *
from fabric.contrib.files import exists
from fabric.context_managers import cd, lcd
import os
env.user = 'connor'
env.hosts = ['connorgoldberg.com']
domain = 'connorgoldberg.com'
subdom = 'www'
def push():
backup()
push_site()
push_static()
def push_site():
local('if [ -e _site ]; then rm -rf _site; fi')
local('if [ -e _static/Resume.pdf ]; then cp _static/Resume.pdf .; fi')
local('if [ -e static ]; then rm static; fi')
local('jekyll build')
local('if [ -e _static ]; then ln -s _static static; fi')
local('if [ -e Resume.pdf ]; then rm Resume.pdf; fi')
local('if [ -e _site.zip ]; then rm _site.zip; fi')
local('zip -r _site _site')
run('rm -f /var/www/%s/_site.zip' % (domain))
run('rm -rf /var/www/%s/_site' % (domain))
put('_site.zip', '/var/www/%s/_site.zip' % (domain))
run('unzip /var/www/%s/_site.zip -d /var/www/%s' % (domain, domain))
run('rm -rf /var/www/%s/%s' % (domain, subdom))
run('mv /var/www/%s/_site /var/www/%s/%s' % (domain, domain, subdom))
def push_static():
"""
Pushes the entire _static folder to the static directory on the server
"""
if os.path.isdir("_static"):
local('if [ -e _static.zip ]; then rm _static.zip; fi')
local('zip -r _static _static')
run('rm -rf /var/www/%s/_static.zip /var/www/%s/static' % (domain,domain))
put('_static.zip', '/var/www/%s/_static.zip' % (domain))
run('unzip /var/www/%s/_static.zip -d /var/www/%s' % (domain, domain))
run('mv /var/www/%s/_static /var/www/%s/static' % (domain, domain))
local('rm -rf _static.zip')
def backup_dir(name):
if exists('%s.zip.bak' % name):
run('rm %s.zip.bak' % name)
run('zip -r %s.zip.bak %s' % (name, name))
def backup():
with cd('/var/www/%s/' % domain):
backup_dir('static')
backup_dir('www')
def restore_dir(name):
if exists('%s.zip.bak' % name):
run('rm -rf %s' % name)
run('unzip %s.zip.bak' % name)
run('rm %s.zip.bak' % name)
else:
print "Could not find: %s.zip.bak" % name
def restore():
with cd('/var/www/%s/' % domain):
restore_dir('static')
restore_dir('www')
def push_file(fileName):
"""
Pushes a single file from the _static folder to the static directory on the server.
Syntax in command line:
$ fab push_file:<filename>
"""
# sets working directories to the static directories
with lcd('_static'), cd('/var/www/%s/static/' % domain):
if exists('%s' % (fileName)):
#Then the file already exists in the static directory on the server
confirm = prompt('Warning: File: %s already exists. Do you wish to proceed? [y/n]: ' % fileName)
if (confirm == 'y'):
run('rm %s' % fileName)
else:
print("Aborted by user.")
local('rm -rf temp temp.zip')
return 0
local('mkdir temp')
local('cp %s temp' % fileName)
local('zip -r temp temp')
put('temp.zip', '/var/www/%s/static/temp.zip' % domain)
run('unzip -j temp.zip')
#clean up local temp stuff
run('rm temp.zip')
local('rm -rf temp temp.zip')
def remove_file(fileName):
# sets working directories to the static directories
with cd('/var/www/%s/static/' % domain):
if exists('%s' % (fileName)):
#Then the file already exists in the static directory on the server
confirm = prompt('Warning: About to remove: %s. Do you wish to proceed? [y/n]: ' % fileName)
if (confirm == 'y'):
run('rm %s' % fileName)
else:
print("Aborted by user.")
else:
print("File does not exist.")
def push_resume():
with lcd('_static'):
run('rm /var/www/%s/www/Resume.pdf' % domain)
run('rm /var/www/%s/static/Resume.pdf' % domain)
put('Resume.pdf', '/var/www/%s/static/Resume.pdf' % domain)
run('cp /var/www/%s/static/Resume.pdf /var/www/%s/www/Resume.pdf' % (domain,domain))
def push_private():
"""
Pushes the entire _private folder to the private directory on the server
"""
local('zip -r _private _private')
run('rm -rf /var/www/%s/private' % domain)
put('_private.zip', '/var/www/%s/_private.zip' % (domain))
run('unzip /var/www/%s/_private.zip -d /var/www/%s' % (domain, domain))
run('mv /var/www/%s/_private /var/www/%s/private' % (domain, domain))
run('rm -rf /var/www/%s/_private.zip' % domain)
local('rm -rf _private.zip')
def push_file_private(fileName):
# sets working directories to the static directories
with lcd('_private'), cd('/var/www/%s/private/' % domain):
local('mkdir temp')
local('cp %s temp' % fileName)
local('zip -r temp temp')
if exists('%s' % (fileName)):
#Then the file already exists in the static directory on the server
run('rm %s' % fileName)
put('temp.zip', '/var/www/%s/private/temp.zip' % domain)
run('unzip -j temp.zip')
#clean up local temp stuff
run('rm temp.zip')
local('rm -rf temp temp.zip')
def remove_file_private(fileName):
# sets working directories to the static directories
with cd('/var/www/%s/private/' % domain):
if exists('%s' % (fileName)):
#Then the file already exists in the static directory on the server
confirm = prompt('Warning: About to remove: %s. Do you wish to proceed? [y/n]: ' % fileName)
if (confirm == 'y'):
run('rm %s' % fileName)
else:
print("Aborted by user.")
else:
print("File does not exist.")