-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy
executable file
·62 lines (48 loc) · 1.49 KB
/
deploy
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
#!/usr/bin/env python
from optparse import OptionParser
import os, subprocess
from config import target_host
usage = "usage: %prog [options] folder_name\n\nExample:\n %prog -c my_site bootstrap"
parser = OptionParser(usage=usage)
parser.add_option("-c", "--client", dest="client", default=False,
help="eg: nonfiction")
parser.add_option("-t", "--target-host",
action="store", dest="target", default=target_host,
help="default: %s" % target_host,
metavar="HOSTNAME")
parser.add_option("-u", "--user",
action="store", dest="user",
metavar="USERNAME")
(options, args) = parser.parse_args()
if not options.target or not options.client:
print 'hostname and client name must be supplied'
parser.print_usage()
exit()
if len(args) != 1:
print 'No folder name supplied'
parser.print_usage()
exit()
folder_name = args[0]
folder_name = os.path.abspath(folder_name) + '/'
if not os.path.isdir(folder_name):
print 'Not a folder: ' + folder_name
parser.print_usage()
exit()
if options.user:
user = options.user
else:
user = os.popen('whoami').read().strip()
target = '%s@%s:/var/www/clients/%s/' % (user, options.target, options.client)
command = [
'rsync',
'-avz',
'--exclude', 'README*',
'--chmod=ugo+rwx,o-w',
folder_name,
target
]
if subprocess.call(command):
print 'Rsync had a problem, this is what it was trying: '
print ' '.join(command)
exit()
print 'All done!'