1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3 4"""Test the relocation of an export. 5usage: test_relocate.py filename.export 6 7To set the environment : 8. $ASTER_ROOT/etc/codeaster/profile.sh 9export PYTHONPATH=$PYTHONPATH:$ASTER_ROOT/share/codeaster/asrun/unittest 10 11""" 12 13import sys 14import os.path as osp 15 16from asrun.run import AsRunFactory 17from asrun.core import magic 18from asrun.profil import AsterProfil 19from asrun.core.server import build_server_from_profile, TYPES 20from asrun.common.sysutils import local_full_host 21from asrun.common.utils import unique_basename 22 23#unique_basename = None 24 25 26def main(fname, verbose=False): 27 """Run""" 28 # initialize objects 29 magic.init_logger(debug=False) 30 run = AsRunFactory() 31 prof = AsterProfil(fname) 32 studyid = '01234' 33 34 # very similar to asrun.plugins.default.copy_datafiles_on_server 35 sexec = build_server_from_profile(prof, TYPES.EXEC) 36 scopy = build_server_from_profile(prof, TYPES.COPY_TO, jobid=studyid) 37 forig = prof.get_filename() 38 39 run_on_localhost = sexec.is_localhost() 40 if verbose: 41 print('run on localhost ?', run_on_localhost) 42 remote_prof = prof.copy() 43 if not run_on_localhost: 44 remote_prof.relocate(local_full_host, scopy.get_proxy_dir(), 45 convert=unique_basename) 46 remote_prof.relocate(sexec.host, convert=unique_basename) 47 #remote_prof['studyid'] = studyid 48 #remote_prof.set_filename(fprof) 49 #remote_prof.WriteExportTo(fprof) 50 if verbose: 51 print(remote_prof) 52 print(remote_prof.get_on_serv(local_full_host).get_data().topath()) 53 54 local_resu = prof.get_result().get_on_serv(local_full_host) 55 local_nom, local_other = local_resu.get_type('nom', with_completion=True) 56 if verbose: 57 for dst in local_other.topath(): 58 bname = unique_basename(dst) 59 src = osp.join("/proxy_dir", bname) 60 fsrc = "user" + "@" + "host" + ":" + src 61 print("copy %s to %s" % (fsrc, dst)) 62 for dst in local_nom.topath(): 63 bname = osp.basename(dst) 64 src = osp.join("/proxy_dir", bname) 65 fsrc = "user" + "@" + "host" + ":" + src 66 print("copy %s to %s" % (fsrc, dst)) 67 #scopy.copyfrom(convert=unique_basename, *[e.path for e in local_resu]) 68 return 0, remote_prof 69 70 71if __name__ == '__main__': 72 iret, prof = main(*sys.argv[1:]) 73