-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsend2luke.py
More file actions
50 lines (41 loc) · 1.69 KB
/
send2luke.py
File metadata and controls
50 lines (41 loc) · 1.69 KB
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
#Package up webapp dir and send to server (Luke)
#Uses bash, so probably better to use on some Unix-based OS. Otherwise it should work with Cygwin on Windows??
import os, sys
narg = len(sys.argv)
if __name__ == "__main__" and narg>1:
user = sys.argv[1]
else:
raise Exception('User not provided. Please enter valid username as first argument.')
users = {'xian':{'username':'xian',
'keylocation':'~/Dropbox/.ssh/luke'},
'blake':{'username':'blake',
'keylocation':'~/.ssh/id_rsa.pub'},
'jeff':{'username':'jeff',
'keylocation':'~/.ssh/id_rsa'},
'kesong':{'username':'kesong',
'keylocation':'~/.ssh/id_rsa'}
}
if user in users:
username = users[user]['username']
keylocation = users[user]['keylocation']
else:
raise Exception('User \'%s\' not recognized.' % user)
localdir = '_site'
tarname = 'webtar'
serverdirbase = '/var/services/web/'
#tarzip local
os.system('tar -cvzf {}.tar.gz {}'.format(tarname,localdir))
#scp it over
os.system('scp -i {} -P 1202 {}.tar.gz {}@alab.psych.wisc.edu:{}'.format(keylocation,tarname,username,serverdirbase))
#mk new dir on host and untar the tar
cdcmd = 'cd {}'.format(serverdirbase)
untarcmd = 'sudo tar -xvzf {}.tar.gz -C ./'.format(tarname)
renamecmd = 'sudo rsync -r {}/* ./'.format(localdir)
#rm the tar on host
removecmd = 'sudo rm {}.tar.gz'.format(tarname)
#Also remove the _site folder
rmsite = 'sudo rm -r {}'.format(localdir)
#run it all
os.system('ssh -i {} -p 1202 -t {}@alab.psych.wisc.edu \'{};{};{};{};{}\' '.format(keylocation,username,cdcmd,untarcmd,renamecmd,removecmd,rmsite))
#rm the tar locally
os.system('rm {}.tar.gz'.format(tarname))