Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slurm provider will not create directories recursively #86

Open
markgdawson opened this issue Nov 22, 2018 · 1 comment
Open

Slurm provider will not create directories recursively #86

markgdawson opened this issue Nov 22, 2018 · 1 comment

Comments

@markgdawson
Copy link

At the start of the push_file method of the Slurm class, the sftp_client.mkdir paramiko method is called. This method will only create a single directory level which does not exit.

Recursively creating directories would allow the channel to be used to easily push files to nested directories.

@markgdawson
Copy link
Author

Here is some code, using self.sftp_client, which would recursively create directories given either a remote file or remote directory path. Happy to submit a pull request if you want.

 def create_directory(self, remote_path, is_directory=False):
        """
        recursively create directories if they don't exist
        remote_path - remote path to create.
        is_directory - specifies if remote path is a directory
        """

        dirs_ = []

        if is_directory:
            dir_ = remote_path
        else:
            dir_, basename = os.path.split(remote_path)

        while len(dir_) > 1:
            dirs_.append(dir_)
            dir_, _ = os.path.split(dir_)

        if len(dir_) == 1 and not dir_.startswith("/"):
            dirs_.append(dir_)  # For a remote_path path like y/x.txt

        while len(dirs_):
            dir_ = dirs_.pop()
            try:
                self.sftp_client.stat(dir_)
            except:
                self.log(f'creating directory {dir_}')
                self.sftp_client.mkdir(dir_)

@rantahar rantahar mentioned this issue Nov 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant