Skip to content

Commit

Permalink
Merge pull request #81 from saltball/master
Browse files Browse the repository at this point in the history
  • Loading branch information
njzjz committed Jul 4, 2021
2 parents e323e76 + b47172c commit 60f5c90
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions dpdispatcher/ssh_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from glob import glob
from dpdispatcher import dlog
from dargs.dargs import Argument
import pathlib
# from dpdispatcher.submission import Machine

class SSHSession (object):
Expand Down Expand Up @@ -242,9 +243,9 @@ def get_job_root(self) :

def bind_submission(self, submission):
self.submission = submission
self.local_root = os.path.join(self.temp_local_root, submission.work_base)
self.local_root = pathlib.PurePath(os.path.join(self.temp_local_root, submission.work_base)).as_posix()
# self.remote_root = os.path.join(self.temp_remote_root, self.submission.submission_hash, self.submission.work_base )
self.remote_root = os.path.join(self.temp_remote_root, self.submission.submission_hash)
self.remote_root = pathlib.PurePath(os.path.join(self.temp_remote_root, self.submission.submission_hash)).as_posix()

# self.job_uuid = submission.submission_hash
# dlog.debug("debug:SSHContext.bind_submission"
Expand Down Expand Up @@ -359,19 +360,19 @@ def clean(self) :

def write_file(self, fname, write_str):
self.ssh_session.ensure_alive()
with self.sftp.open(os.path.join(self.remote_root, fname), 'w') as fp :
with self.sftp.open(pathlib.PurePath(os.path.join(self.remote_root, fname)).as_posix(), 'w') as fp :
fp.write(write_str)

def read_file(self, fname):
self.ssh_session.ensure_alive()
with self.sftp.open(os.path.join(self.remote_root, fname), 'r') as fp:
with self.sftp.open(pathlib.PurePath(os.path.join(self.remote_root, fname)).as_posix(), 'r') as fp:
ret = fp.read().decode('utf-8')
return ret

def check_file_exists(self, fname):
self.ssh_session.ensure_alive()
try:
self.sftp.stat(os.path.join(self.remote_root, fname))
self.sftp.stat(pathlib.PurePath(os.path.join(self.remote_root, fname)).as_posix())
ret = True
except IOError:
ret = False
Expand Down Expand Up @@ -452,8 +453,8 @@ def _put_files(self,
except OSError:
pass
# trans
from_f = os.path.join(self.local_root, of)
to_f = os.path.join(self.remote_root, of)
from_f = pathlib.PurePath(os.path.join(self.local_root, of)).as_posix()
to_f = pathlib.PurePath(os.path.join(self.remote_root, of)).as_posix()
try:
self.sftp.put(from_f, to_f)
except FileNotFoundError:
Expand Down Expand Up @@ -491,8 +492,8 @@ def _get_files(self,
# -f, --force force overwrite of output file and compress links
self.block_checkcall('gzip -f %s' % of_tar)
# trans
from_f = os.path.join(self.remote_root, of)
to_f = os.path.join(self.local_root, of)
from_f = pathlib.PurePath(os.path.join(self.remote_root, of)).as_posix()
to_f = pathlib.PurePath(os.path.join(self.local_root, of)).as_posix()
if os.path.isfile(to_f) :
os.remove(to_f)
self.sftp.get(from_f, to_f)
Expand Down

0 comments on commit 60f5c90

Please sign in to comment.