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
|
#!/usr/bin/env python
#
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
# Copyright (c) 1997-2016 California Institute of Technology.
# Copyright (c) 2016-2026 The Uncertainty Quantification Foundation.
# License: 3-clause BSD. The full license text is available at:
# - https://github.com/uqfoundation/pathos/blob/master/LICENSE
"""
example of using the secure copy interface
To run: python secure_copy.py
"""
from pathos.secure import Copier, Pipe
if __name__=='__main__':
source0 = 'test.txt'
source1 = '~/test.txt'
source2 = '~/result.txt'
dest0 = source1
dest1 = source2
dest2 = '.'
cpu1 = 'localhost'
cpu2 = 'localhost'
#cpu1 = 'computer.cacr.caltech.edu'
#cpu2 = 'foobar.danse.us'
del1 = 'rm '+source1
del2 = 'rm '+source2
copier = Copier('LauncherSCP')
print('creating %s' % source0)
f = open(source0,'w')
f.write('Test Successful!\n')
f.close()
from time import sleep
sleep(1) #FIXME: needs time to work...
print('executing {scp %s %s:%s}' % (source0,cpu1,dest0))
copier(source=source0, destination=cpu1+':'+dest0)
copier.launch()
sleep(1) #FIXME: needs time to work...
print('executing {scp %s:%s %s:%s}' % (cpu1,source1,cpu2,dest1))
copier(source=cpu1+':'+source1, destination=cpu2+':'+dest1)
copier.launch()
sleep(1) #FIXME: needs time to work...
print('executing {scp %s:%s %s}' % (cpu2,source2,dest2))
copier(source=cpu2+':'+source2, destination=dest2)
copier.launch()
sleep(1) #FIXME: needs time to work...
print('cleanup temporary files...')
import os
os.remove(source0)
launcher = Pipe('cleanup')
launcher(command=del1, host=cpu1, background=True)
launcher.launch()
launcher(command=del2, host=cpu2, background=True)
launcher.launch()
# print('cleanup result file...')
# os.remove("."+os.sep+os.path.basename(source2))
# End of file
|