Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions rclone.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import logging
import subprocess
import tempfile
import os


class RClone:
Expand Down Expand Up @@ -85,17 +86,15 @@ def run_cmd(self, command, extra_args=[]):
- extra_args (list): extra arguments to be passed to the rclone command
"""
# save the configuration in a temporary file
with tempfile.NamedTemporaryFile(mode='wt', delete=True) as cfg_file:
# cfg_file is automatically cleaned up by python
self.log.debug("rclone config: ~%s~", self.cfg)
cfg_file.write(self.cfg)
cfg_file.flush()

command_with_args = ["rclone", command, "--config", cfg_file.name]
command_with_args += extra_args
command_result = self._execute(command_with_args)
cfg_file.close()
return command_result
cfg_fd, cfg_name = tempfile.mkstemp()
with open(cfg_fd, 'w') as conf_file:
conf_file.write(self.cfg)

command_with_args = ["rclone", command, "--config", cfg_name]
command_with_args += extra_args
command_result = self._execute(command_with_args)
os.remove(cfg_name)
return command_result

def copy(self, source, dest, flags=[]):
"""
Expand Down