Skip to content

Commit

Permalink
Reorder scp parameters (juju#259) (juju#260)
Browse files Browse the repository at this point in the history
* Reorder scp parameters (juju#259)

Fixes juju#259

* Move scp_opts after default scp options

* Move scp_opts after the default scp options
* scp_opts can be a list or a str: `['-p', '-r']` or '-p -r'
  • Loading branch information
n-pochet authored and johnsca committed Aug 16, 2018
1 parent 26c86c8 commit ec2c493
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ dist/
dev/
.pytest_cache
pytestdebug.log
.vscode/
12 changes: 7 additions & 5 deletions juju/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ async def scp_to(self, source, destination, user='ubuntu', proxy=False,
:param str destination: Remote destination of transferred files
:param str user: Remote username
:param bool proxy: Proxy through the Juju API server
:param str scp_opts: Additional options to the `scp` command
:param scp_opts: Additional options to the `scp` command
:type scp_opts: str or list
"""
if proxy:
raise NotImplementedError('proxy option is not implemented')
Expand All @@ -163,7 +164,8 @@ async def scp_from(self, source, destination, user='ubuntu', proxy=False,
:param str destination: Local destination of transferred files
:param str user: Remote username
:param bool proxy: Proxy through the Juju API server
:param str scp_opts: Additional options to the `scp` command
:param scp_opts: Additional options to the `scp` command
:type scp_opts: str or list
"""
if proxy:
raise NotImplementedError('proxy option is not implemented')
Expand All @@ -181,10 +183,10 @@ async def _scp(self, source, destination, scp_opts):
'-i', os.path.expanduser('~/.local/share/juju/ssh/juju_id_rsa'),
'-o', 'StrictHostKeyChecking=no',
'-q',
'-B',
source, destination
'-B'
]
cmd += scp_opts.split()
cmd.extend(scp_opts.split() if isinstance(scp_opts, str) else scp_opts)
cmd.extend([source, destination])
loop = self.model.loop
process = await asyncio.create_subprocess_exec(*cmd, loop=loop)
await process.wait()
Expand Down
6 changes: 4 additions & 2 deletions juju/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ async def scp_to(self, source, destination, user='ubuntu', proxy=False,
:param str destination: Remote destination of transferred files
:param str user: Remote username
:param bool proxy: Proxy through the Juju API server
:param str scp_opts: Additional options to the `scp` command
:param scp_opts: Additional options to the `scp` command
:type scp_opts: str or list
"""
await self.machine.scp_to(source, destination, user=user, proxy=proxy,
scp_opts=scp_opts)
Expand All @@ -199,7 +200,8 @@ async def scp_from(self, source, destination, user='ubuntu', proxy=False,
:param str destination: Local destination of transferred files
:param str user: Remote username
:param bool proxy: Proxy through the Juju API server
:param str scp_opts: Additional options to the `scp` command
:param scp_opts: Additional options to the `scp` command
:type scp_opts: str or list
"""
await self.machine.scp_from(source, destination, user=user,
proxy=proxy, scp_opts=scp_opts)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ async def test_scp(event_loop):
with NamedTemporaryFile() as f:
f.write(b'testcontents')
f.flush()
await machine.scp_to(f.name, 'testfile')
await machine.scp_to(f.name, 'testfile', scp_opts='-p')

with NamedTemporaryFile() as f:
await machine.scp_from('testfile', f.name)
await machine.scp_from('testfile', f.name, scp_opts='-p')
assert f.read() == b'testcontents'

0 comments on commit ec2c493

Please sign in to comment.