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

Added functionality to not redirect output #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
17 changes: 11 additions & 6 deletions rclone.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, cfg):
self.cfg = cfg.replace("\\n", "\n")
self.log = logging.getLogger("RClone")

def _execute(self, command_with_args):
def _execute(self, command_with_args, redirect_stdout=True, redirect_stderr=True):
"""
Execute the given `command_with_args` using Popen

Expand All @@ -45,10 +45,12 @@ def _execute(self, command_with_args):
"""
self.log.debug("Invoking : %s", " ".join(command_with_args))
try:
stdout = subprocess.PIPE if redirect_stdout else None
stderr = subprocess.PIPE if redirect_stderr else None
with subprocess.Popen(
command_with_args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE) as proc:
stdout=stdout,
stderr=stderr) as proc:
(out, err) = proc.communicate()

#out = proc.stdout.read()
Expand All @@ -75,8 +77,9 @@ def _execute(self, command_with_args):
"code": -30,
"error": generic_e
}

def run_cmd(self, command, extra_args=[]):


def run_cmd(self, command, extra_args=[], redirect_stdout=True, redirect_stderr=True):
"""
Execute rclone command

Expand All @@ -93,7 +96,9 @@ def run_cmd(self, command, extra_args=[]):

command_with_args = ["rclone", command, "--config", cfg_file.name]
command_with_args += extra_args
command_result = self._execute(command_with_args)

command_result = self._execute(command_with_args, redirect_stdout=redirect_stdout, redirect_stderr=redirect_stderr)

cfg_file.close()
return command_result

Expand Down
4 changes: 4 additions & 0 deletions rclone_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,7 @@ def test_copy_lsjson_and_delete(self):
self.assertEqual(result.get('code'), 0)
result_json = json.loads(result.get('out').decode("utf-8"))
self.assertEqual(len(result_json), 0)


if __name__ == '__main__':
unittest.main()