pyinfra 0.11.dev3__py3-none-any.whl → 3.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyinfra/__init__.py +9 -12
- pyinfra/__main__.py +4 -0
- pyinfra/api/__init__.py +19 -3
- pyinfra/api/arguments.py +413 -0
- pyinfra/api/arguments_typed.py +79 -0
- pyinfra/api/command.py +274 -0
- pyinfra/api/config.py +222 -28
- pyinfra/api/connect.py +33 -13
- pyinfra/api/connectors.py +27 -0
- pyinfra/api/deploy.py +65 -66
- pyinfra/api/exceptions.py +73 -18
- pyinfra/api/facts.py +267 -200
- pyinfra/api/host.py +416 -50
- pyinfra/api/inventory.py +121 -160
- pyinfra/api/metadata.py +69 -0
- pyinfra/api/operation.py +432 -262
- pyinfra/api/operations.py +273 -260
- pyinfra/api/state.py +302 -248
- pyinfra/api/util.py +309 -369
- pyinfra/connectors/base.py +173 -0
- pyinfra/connectors/chroot.py +212 -0
- pyinfra/connectors/docker.py +405 -0
- pyinfra/connectors/dockerssh.py +297 -0
- pyinfra/connectors/local.py +238 -0
- pyinfra/connectors/scp/__init__.py +1 -0
- pyinfra/connectors/scp/client.py +204 -0
- pyinfra/connectors/ssh.py +727 -0
- pyinfra/connectors/ssh_util.py +114 -0
- pyinfra/connectors/sshuserclient/client.py +309 -0
- pyinfra/connectors/sshuserclient/config.py +102 -0
- pyinfra/connectors/terraform.py +135 -0
- pyinfra/connectors/util.py +417 -0
- pyinfra/connectors/vagrant.py +183 -0
- pyinfra/context.py +145 -0
- pyinfra/facts/__init__.py +7 -6
- pyinfra/facts/apk.py +22 -7
- pyinfra/facts/apt.py +117 -60
- pyinfra/facts/brew.py +100 -15
- pyinfra/facts/bsdinit.py +23 -0
- pyinfra/facts/cargo.py +37 -0
- pyinfra/facts/choco.py +47 -0
- pyinfra/facts/crontab.py +195 -0
- pyinfra/facts/deb.py +94 -0
- pyinfra/facts/dnf.py +48 -0
- pyinfra/facts/docker.py +96 -23
- pyinfra/facts/efibootmgr.py +113 -0
- pyinfra/facts/files.py +629 -58
- pyinfra/facts/flatpak.py +77 -0
- pyinfra/facts/freebsd.py +70 -0
- pyinfra/facts/gem.py +19 -6
- pyinfra/facts/git.py +59 -14
- pyinfra/facts/gpg.py +150 -0
- pyinfra/facts/hardware.py +313 -167
- pyinfra/facts/iptables.py +72 -62
- pyinfra/facts/launchd.py +44 -0
- pyinfra/facts/lxd.py +17 -4
- pyinfra/facts/mysql.py +122 -86
- pyinfra/facts/npm.py +17 -9
- pyinfra/facts/openrc.py +71 -0
- pyinfra/facts/opkg.py +246 -0
- pyinfra/facts/pacman.py +50 -7
- pyinfra/facts/pip.py +24 -7
- pyinfra/facts/pipx.py +82 -0
- pyinfra/facts/pkg.py +15 -6
- pyinfra/facts/pkgin.py +35 -0
- pyinfra/facts/podman.py +54 -0
- pyinfra/facts/postgres.py +178 -0
- pyinfra/facts/postgresql.py +6 -147
- pyinfra/facts/rpm.py +105 -0
- pyinfra/facts/runit.py +77 -0
- pyinfra/facts/selinux.py +161 -0
- pyinfra/facts/server.py +762 -285
- pyinfra/facts/snap.py +88 -0
- pyinfra/facts/systemd.py +139 -0
- pyinfra/facts/sysvinit.py +59 -0
- pyinfra/facts/upstart.py +35 -0
- pyinfra/facts/util/__init__.py +17 -0
- pyinfra/facts/util/databases.py +4 -6
- pyinfra/facts/util/packaging.py +37 -6
- pyinfra/facts/util/units.py +30 -0
- pyinfra/facts/util/win_files.py +99 -0
- pyinfra/facts/vzctl.py +20 -13
- pyinfra/facts/xbps.py +35 -0
- pyinfra/facts/yum.py +34 -40
- pyinfra/facts/zfs.py +77 -0
- pyinfra/facts/zypper.py +42 -0
- pyinfra/local.py +45 -83
- pyinfra/operations/__init__.py +12 -0
- pyinfra/operations/apk.py +99 -0
- pyinfra/operations/apt.py +496 -0
- pyinfra/operations/brew.py +232 -0
- pyinfra/operations/bsdinit.py +59 -0
- pyinfra/operations/cargo.py +45 -0
- pyinfra/operations/choco.py +61 -0
- pyinfra/operations/crontab.py +194 -0
- pyinfra/operations/dnf.py +213 -0
- pyinfra/operations/docker.py +492 -0
- pyinfra/operations/files.py +2014 -0
- pyinfra/operations/flatpak.py +95 -0
- pyinfra/operations/freebsd/__init__.py +12 -0
- pyinfra/operations/freebsd/freebsd_update.py +70 -0
- pyinfra/operations/freebsd/pkg.py +219 -0
- pyinfra/operations/freebsd/service.py +116 -0
- pyinfra/operations/freebsd/sysrc.py +92 -0
- pyinfra/operations/gem.py +48 -0
- pyinfra/operations/git.py +420 -0
- pyinfra/operations/iptables.py +312 -0
- pyinfra/operations/launchd.py +45 -0
- pyinfra/operations/lxd.py +69 -0
- pyinfra/operations/mysql.py +610 -0
- pyinfra/operations/npm.py +57 -0
- pyinfra/operations/openrc.py +63 -0
- pyinfra/operations/opkg.py +89 -0
- pyinfra/operations/pacman.py +82 -0
- pyinfra/operations/pip.py +206 -0
- pyinfra/operations/pipx.py +103 -0
- pyinfra/operations/pkg.py +71 -0
- pyinfra/operations/pkgin.py +92 -0
- pyinfra/operations/postgres.py +437 -0
- pyinfra/operations/postgresql.py +30 -0
- pyinfra/operations/puppet.py +41 -0
- pyinfra/operations/python.py +73 -0
- pyinfra/operations/runit.py +184 -0
- pyinfra/operations/selinux.py +190 -0
- pyinfra/operations/server.py +1100 -0
- pyinfra/operations/snap.py +118 -0
- pyinfra/operations/ssh.py +217 -0
- pyinfra/operations/systemd.py +150 -0
- pyinfra/operations/sysvinit.py +142 -0
- pyinfra/operations/upstart.py +68 -0
- pyinfra/operations/util/__init__.py +12 -0
- pyinfra/operations/util/docker.py +407 -0
- pyinfra/operations/util/files.py +247 -0
- pyinfra/operations/util/packaging.py +338 -0
- pyinfra/operations/util/service.py +46 -0
- pyinfra/operations/vzctl.py +137 -0
- pyinfra/operations/xbps.py +78 -0
- pyinfra/operations/yum.py +213 -0
- pyinfra/operations/zfs.py +176 -0
- pyinfra/operations/zypper.py +193 -0
- pyinfra/progress.py +44 -32
- pyinfra/py.typed +0 -0
- pyinfra/version.py +9 -1
- pyinfra-3.6.dist-info/METADATA +142 -0
- pyinfra-3.6.dist-info/RECORD +160 -0
- {pyinfra-0.11.dev3.dist-info → pyinfra-3.6.dist-info}/WHEEL +1 -2
- pyinfra-3.6.dist-info/entry_points.txt +12 -0
- {pyinfra-0.11.dev3.dist-info → pyinfra-3.6.dist-info/licenses}/LICENSE.md +1 -1
- pyinfra_cli/__init__.py +1 -0
- pyinfra_cli/cli.py +793 -0
- pyinfra_cli/commands.py +66 -0
- pyinfra_cli/exceptions.py +155 -65
- pyinfra_cli/inventory.py +233 -89
- pyinfra_cli/log.py +39 -43
- pyinfra_cli/main.py +26 -495
- pyinfra_cli/prints.py +215 -156
- pyinfra_cli/util.py +172 -105
- pyinfra_cli/virtualenv.py +25 -20
- pyinfra/api/connectors/__init__.py +0 -21
- pyinfra/api/connectors/ansible.py +0 -99
- pyinfra/api/connectors/docker.py +0 -178
- pyinfra/api/connectors/local.py +0 -169
- pyinfra/api/connectors/ssh.py +0 -402
- pyinfra/api/connectors/sshuserclient/client.py +0 -105
- pyinfra/api/connectors/sshuserclient/config.py +0 -90
- pyinfra/api/connectors/util.py +0 -63
- pyinfra/api/connectors/vagrant.py +0 -155
- pyinfra/facts/init.py +0 -176
- pyinfra/facts/util/files.py +0 -102
- pyinfra/hook.py +0 -41
- pyinfra/modules/__init__.py +0 -11
- pyinfra/modules/apk.py +0 -64
- pyinfra/modules/apt.py +0 -272
- pyinfra/modules/brew.py +0 -122
- pyinfra/modules/files.py +0 -711
- pyinfra/modules/gem.py +0 -30
- pyinfra/modules/git.py +0 -115
- pyinfra/modules/init.py +0 -344
- pyinfra/modules/iptables.py +0 -271
- pyinfra/modules/lxd.py +0 -45
- pyinfra/modules/mysql.py +0 -347
- pyinfra/modules/npm.py +0 -47
- pyinfra/modules/pacman.py +0 -60
- pyinfra/modules/pip.py +0 -99
- pyinfra/modules/pkg.py +0 -43
- pyinfra/modules/postgresql.py +0 -245
- pyinfra/modules/puppet.py +0 -20
- pyinfra/modules/python.py +0 -37
- pyinfra/modules/server.py +0 -524
- pyinfra/modules/ssh.py +0 -150
- pyinfra/modules/util/files.py +0 -52
- pyinfra/modules/util/packaging.py +0 -118
- pyinfra/modules/vzctl.py +0 -133
- pyinfra/modules/yum.py +0 -171
- pyinfra/pseudo_modules.py +0 -64
- pyinfra-0.11.dev3.dist-info/.DS_Store +0 -0
- pyinfra-0.11.dev3.dist-info/METADATA +0 -135
- pyinfra-0.11.dev3.dist-info/RECORD +0 -95
- pyinfra-0.11.dev3.dist-info/entry_points.txt +0 -3
- pyinfra-0.11.dev3.dist-info/top_level.txt +0 -2
- pyinfra_cli/__main__.py +0 -40
- pyinfra_cli/config.py +0 -92
- /pyinfra/{modules/util → connectors}/__init__.py +0 -0
- /pyinfra/{api/connectors → connectors}/sshuserclient/__init__.py +0 -0
pyinfra/api/connectors/docker.py
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
|
|
3
|
-
from tempfile import mkstemp
|
|
4
|
-
|
|
5
|
-
import click
|
|
6
|
-
|
|
7
|
-
import pyinfra
|
|
8
|
-
|
|
9
|
-
from pyinfra import local, logger
|
|
10
|
-
from pyinfra.api.exceptions import InventoryError
|
|
11
|
-
from pyinfra.api.util import get_file_io, memoize
|
|
12
|
-
from pyinfra.progress import progress_spinner
|
|
13
|
-
|
|
14
|
-
from .local import run_shell_command as run_local_shell_command
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
@memoize
|
|
18
|
-
def show_warning():
|
|
19
|
-
logger.warning('The @docker connector is in Alpha!')
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def make_names_data(image=None):
|
|
23
|
-
if not image:
|
|
24
|
-
raise InventoryError('No docker base image provided!')
|
|
25
|
-
|
|
26
|
-
show_warning()
|
|
27
|
-
|
|
28
|
-
# Save the image as the hostname, no data, @docker group
|
|
29
|
-
yield image, {}, ['@docker']
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def connect(state, host, for_fact=None):
|
|
33
|
-
if 'docker_container_id' in host.host_data: # user can provide a docker_container_id
|
|
34
|
-
return True
|
|
35
|
-
|
|
36
|
-
with progress_spinner({'docker run'}):
|
|
37
|
-
container_id = local.shell(
|
|
38
|
-
'docker run -d {0} sleep 10000'.format(host.name),
|
|
39
|
-
splitlines=True,
|
|
40
|
-
)[-1] # last line is the container ID
|
|
41
|
-
|
|
42
|
-
host.host_data['docker_container_id'] = container_id
|
|
43
|
-
return True
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
def disconnect(state, host):
|
|
47
|
-
if not pyinfra.is_cli:
|
|
48
|
-
return
|
|
49
|
-
|
|
50
|
-
container_id = host.host_data['docker_container_id'][:12]
|
|
51
|
-
|
|
52
|
-
with progress_spinner({'docker commit'}):
|
|
53
|
-
image_id = local.shell(
|
|
54
|
-
'docker commit {0}'.format(container_id),
|
|
55
|
-
splitlines=True,
|
|
56
|
-
)[-1][7:19] # last line is the image ID, get sha256:[XXXXXXXXXX]...
|
|
57
|
-
|
|
58
|
-
with progress_spinner({'docker rm'}):
|
|
59
|
-
local.shell(
|
|
60
|
-
'docker rm -f {0}'.format(container_id),
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
logger.info('{0}docker build complete, image ID: {1}'.format(
|
|
64
|
-
host.print_prefix, click.style(image_id, bold=True),
|
|
65
|
-
))
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def run_shell_command(
|
|
69
|
-
state, host, command,
|
|
70
|
-
timeout=None, print_output=False,
|
|
71
|
-
return_combined_output=False,
|
|
72
|
-
**kwargs # ignored (sudo/etc)
|
|
73
|
-
):
|
|
74
|
-
container_id = host.host_data['docker_container_id']
|
|
75
|
-
docker_command = 'docker exec {0} sh -c "{1}"'.format(container_id, command)
|
|
76
|
-
|
|
77
|
-
return run_local_shell_command(
|
|
78
|
-
state, host, docker_command,
|
|
79
|
-
timeout=timeout,
|
|
80
|
-
print_output=print_output,
|
|
81
|
-
return_combined_output=return_combined_output,
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
def put_file(
|
|
86
|
-
state, host, filename_or_io, remote_filename,
|
|
87
|
-
print_output=False,
|
|
88
|
-
**kwargs # ignored (sudo/etc)
|
|
89
|
-
):
|
|
90
|
-
'''
|
|
91
|
-
Upload a file/IO object to the target Docker container by copying it to a
|
|
92
|
-
temporary location and then uploading it into the container using ``docker cp``.
|
|
93
|
-
'''
|
|
94
|
-
|
|
95
|
-
_, temp_filename = mkstemp()
|
|
96
|
-
|
|
97
|
-
try:
|
|
98
|
-
# Load our file or IO object and write it to the temporary file
|
|
99
|
-
with get_file_io(filename_or_io) as file_io:
|
|
100
|
-
with open(temp_filename, 'wb') as temp_f:
|
|
101
|
-
data = file_io.read()
|
|
102
|
-
|
|
103
|
-
if isinstance(data, str):
|
|
104
|
-
data = data.encode()
|
|
105
|
-
|
|
106
|
-
temp_f.write(data)
|
|
107
|
-
|
|
108
|
-
docker_id = host.host_data['docker_container_id']
|
|
109
|
-
docker_command = 'docker cp {0} {1}:{2}'.format(
|
|
110
|
-
temp_filename,
|
|
111
|
-
docker_id,
|
|
112
|
-
remote_filename,
|
|
113
|
-
)
|
|
114
|
-
|
|
115
|
-
status, _, stderr = run_local_shell_command(
|
|
116
|
-
state, host, docker_command,
|
|
117
|
-
print_output=print_output,
|
|
118
|
-
)
|
|
119
|
-
finally:
|
|
120
|
-
os.remove(temp_filename)
|
|
121
|
-
|
|
122
|
-
if not status:
|
|
123
|
-
raise IOError('\n'.join(stderr))
|
|
124
|
-
|
|
125
|
-
if print_output:
|
|
126
|
-
print('{0}file uploaded to container: {1}'.format(
|
|
127
|
-
host.print_prefix, remote_filename,
|
|
128
|
-
))
|
|
129
|
-
|
|
130
|
-
return status
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
def get_file(
|
|
134
|
-
state, host, remote_filename, filename_or_io,
|
|
135
|
-
print_output=False,
|
|
136
|
-
**kwargs # ignored (sudo/etc)
|
|
137
|
-
):
|
|
138
|
-
'''
|
|
139
|
-
Download a file from the target Docker container by copying it to a temporary
|
|
140
|
-
location and then reading that into our final file/IO object.
|
|
141
|
-
'''
|
|
142
|
-
|
|
143
|
-
_, temp_filename = mkstemp()
|
|
144
|
-
|
|
145
|
-
try:
|
|
146
|
-
docker_id = host.host_data['docker_container_id']
|
|
147
|
-
docker_command = 'docker cp {0}:{1} {2}'.format(
|
|
148
|
-
docker_id,
|
|
149
|
-
remote_filename,
|
|
150
|
-
temp_filename,
|
|
151
|
-
)
|
|
152
|
-
|
|
153
|
-
status, _, stderr = run_local_shell_command(
|
|
154
|
-
state, host, docker_command,
|
|
155
|
-
print_output=print_output,
|
|
156
|
-
)
|
|
157
|
-
|
|
158
|
-
# Load the temporary file and write it to our file or IO object
|
|
159
|
-
with open(temp_filename) as temp_f:
|
|
160
|
-
with get_file_io(filename_or_io, 'wb') as file_io:
|
|
161
|
-
data = temp_f.read()
|
|
162
|
-
|
|
163
|
-
if isinstance(data, str):
|
|
164
|
-
data = data.encode()
|
|
165
|
-
|
|
166
|
-
file_io.write(data)
|
|
167
|
-
finally:
|
|
168
|
-
os.remove(temp_filename)
|
|
169
|
-
|
|
170
|
-
if not status:
|
|
171
|
-
raise IOError('\n'.join(stderr))
|
|
172
|
-
|
|
173
|
-
if print_output:
|
|
174
|
-
print('{0}file downloaded from container: {1}'.format(
|
|
175
|
-
host.print_prefix, remote_filename,
|
|
176
|
-
))
|
|
177
|
-
|
|
178
|
-
return status
|
pyinfra/api/connectors/local.py
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
|
|
3
|
-
from subprocess import PIPE, Popen
|
|
4
|
-
from tempfile import mkstemp
|
|
5
|
-
|
|
6
|
-
import click
|
|
7
|
-
|
|
8
|
-
from pyinfra import logger
|
|
9
|
-
from pyinfra.api.util import get_file_io, make_command
|
|
10
|
-
|
|
11
|
-
from .util import read_buffers_into_queue, split_combined_output
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def connect(state, host, for_fact=None):
|
|
15
|
-
# Log
|
|
16
|
-
log_message = '{0}{1}'.format(
|
|
17
|
-
host.print_prefix,
|
|
18
|
-
click.style('Connected', 'green'),
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
if for_fact:
|
|
22
|
-
log_message = '{0}{1}'.format(
|
|
23
|
-
log_message,
|
|
24
|
-
' (for {0} fact)'.format(for_fact),
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
logger.info(log_message)
|
|
28
|
-
|
|
29
|
-
return True
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def run_shell_command(
|
|
33
|
-
state, host, command,
|
|
34
|
-
get_pty=False, timeout=None, print_output=False,
|
|
35
|
-
return_combined_output=False,
|
|
36
|
-
**command_kwargs
|
|
37
|
-
):
|
|
38
|
-
'''
|
|
39
|
-
Execute a command on the local machine.
|
|
40
|
-
|
|
41
|
-
Args:
|
|
42
|
-
state (``pyinfra.api.State`` obj): state object for this command
|
|
43
|
-
hostname (string): hostname of the target
|
|
44
|
-
command (string): actual command to execute
|
|
45
|
-
sudo (boolean): whether to wrap the command with sudo
|
|
46
|
-
sudo_user (string): user to sudo to
|
|
47
|
-
get_pty (boolean): whether to get a PTY before executing the command
|
|
48
|
-
env (dict): envrionment variables to set
|
|
49
|
-
timeout (int): timeout for this command to complete before erroring
|
|
50
|
-
|
|
51
|
-
Returns:
|
|
52
|
-
tuple: (exit_code, stdout, stderr)
|
|
53
|
-
stdout and stderr are both lists of strings from each buffer.
|
|
54
|
-
'''
|
|
55
|
-
|
|
56
|
-
command = make_command(command, **command_kwargs)
|
|
57
|
-
|
|
58
|
-
logger.debug('--> Running command on localhost: {0}'.format(command))
|
|
59
|
-
|
|
60
|
-
if print_output:
|
|
61
|
-
print('{0}>>> {1}'.format(host.print_prefix, command))
|
|
62
|
-
|
|
63
|
-
process = Popen(command, shell=True, stdout=PIPE, stderr=PIPE)
|
|
64
|
-
|
|
65
|
-
combined_output = read_buffers_into_queue(
|
|
66
|
-
host,
|
|
67
|
-
process.stdout,
|
|
68
|
-
process.stderr,
|
|
69
|
-
timeout=timeout,
|
|
70
|
-
print_output=print_output,
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
logger.debug('--> Waiting for exit status...')
|
|
74
|
-
process.wait()
|
|
75
|
-
logger.debug('--> Command exit status: {0}'.format(process.returncode))
|
|
76
|
-
|
|
77
|
-
# Close any open file descriptors
|
|
78
|
-
process.stdout.close()
|
|
79
|
-
process.stderr.close()
|
|
80
|
-
|
|
81
|
-
status = process.returncode == 0
|
|
82
|
-
|
|
83
|
-
if return_combined_output:
|
|
84
|
-
return status, combined_output
|
|
85
|
-
|
|
86
|
-
stdout, stderr = split_combined_output(combined_output)
|
|
87
|
-
return status, stdout, stderr
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
def put_file(
|
|
91
|
-
state, host, filename_or_io, remote_filename,
|
|
92
|
-
print_output=False,
|
|
93
|
-
**command_kwargs
|
|
94
|
-
):
|
|
95
|
-
'''
|
|
96
|
-
Upload a local file or IO object by copying it to a temporary directory
|
|
97
|
-
and then writing it to the upload location.
|
|
98
|
-
'''
|
|
99
|
-
|
|
100
|
-
_, temp_filename = mkstemp()
|
|
101
|
-
|
|
102
|
-
try:
|
|
103
|
-
# Load our file or IO object and write it to the temporary file
|
|
104
|
-
with get_file_io(filename_or_io) as file_io:
|
|
105
|
-
with open(temp_filename, 'wb') as temp_f:
|
|
106
|
-
data = file_io.read()
|
|
107
|
-
|
|
108
|
-
if isinstance(data, str):
|
|
109
|
-
data = data.encode()
|
|
110
|
-
|
|
111
|
-
temp_f.write(data)
|
|
112
|
-
|
|
113
|
-
# Copy the file using `cp` such that we support sudo/su
|
|
114
|
-
status, _, stderr = run_shell_command(
|
|
115
|
-
state, host, 'cp {0} {1}'.format(temp_filename, remote_filename),
|
|
116
|
-
print_output=print_output,
|
|
117
|
-
**command_kwargs
|
|
118
|
-
)
|
|
119
|
-
|
|
120
|
-
if not status:
|
|
121
|
-
raise IOError('\n'.join(stderr))
|
|
122
|
-
finally:
|
|
123
|
-
os.remove(temp_filename)
|
|
124
|
-
|
|
125
|
-
if print_output:
|
|
126
|
-
print('{0}file copied: {1}'.format(host.print_prefix, remote_filename))
|
|
127
|
-
|
|
128
|
-
return status
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
def get_file(
|
|
132
|
-
state, host, remote_filename, filename_or_io,
|
|
133
|
-
print_output=False,
|
|
134
|
-
**command_kwargs
|
|
135
|
-
):
|
|
136
|
-
'''
|
|
137
|
-
Download a local file by copying it to a temporary location and then writing
|
|
138
|
-
it to our filename or IO object.
|
|
139
|
-
'''
|
|
140
|
-
|
|
141
|
-
_, temp_filename = mkstemp()
|
|
142
|
-
|
|
143
|
-
try:
|
|
144
|
-
# Copy the file using `cp` such that we support sudo/su
|
|
145
|
-
status, _, stderr = run_shell_command(
|
|
146
|
-
state, host, 'cp {0} {1}'.format(remote_filename, temp_filename),
|
|
147
|
-
print_output=print_output,
|
|
148
|
-
**command_kwargs
|
|
149
|
-
)
|
|
150
|
-
|
|
151
|
-
if not status:
|
|
152
|
-
raise IOError('\n'.join(stderr))
|
|
153
|
-
|
|
154
|
-
# Load our file or IO object and write it to the temporary file
|
|
155
|
-
with open(temp_filename) as temp_f:
|
|
156
|
-
with get_file_io(filename_or_io, 'wb') as file_io:
|
|
157
|
-
data = temp_f.read()
|
|
158
|
-
|
|
159
|
-
if isinstance(data, str):
|
|
160
|
-
data = data.encode()
|
|
161
|
-
|
|
162
|
-
file_io.write(data)
|
|
163
|
-
finally:
|
|
164
|
-
os.remove(temp_filename)
|
|
165
|
-
|
|
166
|
-
if print_output:
|
|
167
|
-
print('{0}file copied: {1}'.format(host.print_prefix, remote_filename))
|
|
168
|
-
|
|
169
|
-
return True
|