Skip to content

Commit

Permalink
Download files using sudo base64
Browse files Browse the repository at this point in the history
Closes #39
  • Loading branch information
vain committed Nov 9, 2013
1 parent 16a0024 commit 24b137d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
1 change: 1 addition & 0 deletions doc/requirements.rst
Expand Up @@ -6,6 +6,7 @@ Requirements for managed systems
While the following list might appear long, even very minimal systems should provide everything that's needed.

* ``apt-get`` (only used with :doc:`pkg_apt <item_pkg_apt>` items)
* ``base64``
* ``bash``
* ``cat``
* ``chmod``
Expand Down
30 changes: 21 additions & 9 deletions src/blockwart/operations.py
@@ -1,3 +1,5 @@
from base64 import b64decode
from pipes import quote
from stat import S_IRUSR, S_IWUSR

from fabric.api import prefix
Expand Down Expand Up @@ -34,20 +36,30 @@ def download(hostname, remote_path, local_path, ignore_failure=False):
"""
Download a file.
"""

# See issue #39.
# XXX: Revise this once we're using Fabric 2.0.

LOG.debug(_("downloading {}:{} -> {}").format(
hostname, remote_path, local_path))
env.host_string = hostname
fabric_result = _fabric_get(
remote_path=remote_path,
local_path=local_path,
fabric_result = _fabric_sudo(
"base64 {}".format(quote(remote_path)),
shell=True,
pty=False,
combine_stderr=False,
)
if not ignore_failure and fabric_result.failed:
raise RemoteException(_(
"download from {} failed for: {}").format(
hostname,
", ".join(fabric_result.failed),
if fabric_result.succeeded:
with open(local_path, "w") as f:
f.write(b64decode(fabric_result.stdout))
elif not ignore_failure:
raise RemoteException(_(
"reading file '{}' on {} failed: {}").format(
remote_path,
hostname,
fabric_result.stderr,
)
)
)


class RunResult(object):
Expand Down

0 comments on commit 24b137d

Please sign in to comment.