-
Notifications
You must be signed in to change notification settings - Fork 0
/
rsync_from_cluster.py
executable file
·58 lines (48 loc) · 1.52 KB
/
rsync_from_cluster.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
#!/usr/bin/env python3
from sys import argv,exit
import string,subprocess
from os import system
from os.path import basename,dirname,abspath,exists,expanduser
from cluster_info import *
def Help():
print ()
print ( argv[0]+' <cluster> <any extra rsync flags>' )
print()
if ( subprocess.call( ['/bin/bash','-i','-c','alias rfc']) == 1 ):
print ("You may want to alias this command to rfc, by putting the following in your .bashrc: ")
print (' alias rfc="rsync_from_cluster.py"')
exit()
if len(argv)<2:
Help()
cluster_in = argv[1]
(cluster,remotedir) = cluster_check( cluster_in )
if cluster == 'unknown':
Help()
# handle flags like '--exclude' and '--delete' correctly
args = argv[2:]
filenames = []
extra_args = []
for m in args:
if len( m ) > 2 and m.find( '--' ) > -1:
extra_args.append( m )
else:
filenames.append( m )
if len(filenames) == 0: filenames = ['.']
dir = '.'
# strip off directory name based on local path.
clusterdir = remotedir+strip_home_dirname( abspath(dir) )
cluster_prefix = cluster+':'
if len(cluster) == 0: cluster_prefix = ''
commands = []
for filename in filenames:
remote_filename = ' ' + cluster_prefix+clusterdir + '/' + filename
#command = 'rsync -avzL '+ remote_filename + ' . '+' '.join(extra_args)
command = 'rsync -avL '+ remote_filename + ' . '+' '.join(extra_args)
print(command)
system(command)
commands.append( command )
print
print ('Ran the following commands: ')
for command in commands:
print
print(command)