pyinfra 0.11.dev3__py3-none-any.whl → 3.5.1__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.
Files changed (203) hide show
  1. pyinfra/__init__.py +9 -12
  2. pyinfra/__main__.py +4 -0
  3. pyinfra/api/__init__.py +18 -3
  4. pyinfra/api/arguments.py +406 -0
  5. pyinfra/api/arguments_typed.py +79 -0
  6. pyinfra/api/command.py +274 -0
  7. pyinfra/api/config.py +222 -28
  8. pyinfra/api/connect.py +33 -13
  9. pyinfra/api/connectors.py +27 -0
  10. pyinfra/api/deploy.py +65 -66
  11. pyinfra/api/exceptions.py +67 -18
  12. pyinfra/api/facts.py +253 -202
  13. pyinfra/api/host.py +413 -50
  14. pyinfra/api/inventory.py +121 -160
  15. pyinfra/api/operation.py +432 -262
  16. pyinfra/api/operations.py +273 -260
  17. pyinfra/api/state.py +302 -248
  18. pyinfra/api/util.py +291 -368
  19. pyinfra/connectors/base.py +173 -0
  20. pyinfra/connectors/chroot.py +212 -0
  21. pyinfra/connectors/docker.py +381 -0
  22. pyinfra/connectors/dockerssh.py +297 -0
  23. pyinfra/connectors/local.py +238 -0
  24. pyinfra/connectors/scp/__init__.py +1 -0
  25. pyinfra/connectors/scp/client.py +204 -0
  26. pyinfra/connectors/ssh.py +670 -0
  27. pyinfra/connectors/ssh_util.py +114 -0
  28. pyinfra/connectors/sshuserclient/client.py +309 -0
  29. pyinfra/connectors/sshuserclient/config.py +102 -0
  30. pyinfra/connectors/terraform.py +135 -0
  31. pyinfra/connectors/util.py +410 -0
  32. pyinfra/connectors/vagrant.py +183 -0
  33. pyinfra/context.py +145 -0
  34. pyinfra/facts/__init__.py +7 -6
  35. pyinfra/facts/apk.py +22 -7
  36. pyinfra/facts/apt.py +117 -60
  37. pyinfra/facts/brew.py +100 -15
  38. pyinfra/facts/bsdinit.py +23 -0
  39. pyinfra/facts/cargo.py +37 -0
  40. pyinfra/facts/choco.py +47 -0
  41. pyinfra/facts/crontab.py +195 -0
  42. pyinfra/facts/deb.py +94 -0
  43. pyinfra/facts/dnf.py +48 -0
  44. pyinfra/facts/docker.py +96 -23
  45. pyinfra/facts/efibootmgr.py +113 -0
  46. pyinfra/facts/files.py +630 -58
  47. pyinfra/facts/flatpak.py +77 -0
  48. pyinfra/facts/freebsd.py +70 -0
  49. pyinfra/facts/gem.py +19 -6
  50. pyinfra/facts/git.py +59 -14
  51. pyinfra/facts/gpg.py +150 -0
  52. pyinfra/facts/hardware.py +313 -167
  53. pyinfra/facts/iptables.py +72 -62
  54. pyinfra/facts/launchd.py +44 -0
  55. pyinfra/facts/lxd.py +17 -4
  56. pyinfra/facts/mysql.py +122 -86
  57. pyinfra/facts/npm.py +17 -9
  58. pyinfra/facts/openrc.py +71 -0
  59. pyinfra/facts/opkg.py +246 -0
  60. pyinfra/facts/pacman.py +50 -7
  61. pyinfra/facts/pip.py +24 -7
  62. pyinfra/facts/pipx.py +82 -0
  63. pyinfra/facts/pkg.py +15 -6
  64. pyinfra/facts/pkgin.py +35 -0
  65. pyinfra/facts/podman.py +54 -0
  66. pyinfra/facts/postgres.py +178 -0
  67. pyinfra/facts/postgresql.py +6 -147
  68. pyinfra/facts/rpm.py +105 -0
  69. pyinfra/facts/runit.py +77 -0
  70. pyinfra/facts/selinux.py +161 -0
  71. pyinfra/facts/server.py +746 -285
  72. pyinfra/facts/snap.py +88 -0
  73. pyinfra/facts/systemd.py +139 -0
  74. pyinfra/facts/sysvinit.py +59 -0
  75. pyinfra/facts/upstart.py +35 -0
  76. pyinfra/facts/util/__init__.py +17 -0
  77. pyinfra/facts/util/databases.py +4 -6
  78. pyinfra/facts/util/packaging.py +37 -6
  79. pyinfra/facts/util/units.py +30 -0
  80. pyinfra/facts/util/win_files.py +99 -0
  81. pyinfra/facts/vzctl.py +20 -13
  82. pyinfra/facts/xbps.py +35 -0
  83. pyinfra/facts/yum.py +34 -40
  84. pyinfra/facts/zfs.py +77 -0
  85. pyinfra/facts/zypper.py +42 -0
  86. pyinfra/local.py +45 -83
  87. pyinfra/operations/__init__.py +12 -0
  88. pyinfra/operations/apk.py +98 -0
  89. pyinfra/operations/apt.py +488 -0
  90. pyinfra/operations/brew.py +231 -0
  91. pyinfra/operations/bsdinit.py +59 -0
  92. pyinfra/operations/cargo.py +45 -0
  93. pyinfra/operations/choco.py +61 -0
  94. pyinfra/operations/crontab.py +191 -0
  95. pyinfra/operations/dnf.py +210 -0
  96. pyinfra/operations/docker.py +446 -0
  97. pyinfra/operations/files.py +1939 -0
  98. pyinfra/operations/flatpak.py +94 -0
  99. pyinfra/operations/freebsd/__init__.py +12 -0
  100. pyinfra/operations/freebsd/freebsd_update.py +70 -0
  101. pyinfra/operations/freebsd/pkg.py +219 -0
  102. pyinfra/operations/freebsd/service.py +116 -0
  103. pyinfra/operations/freebsd/sysrc.py +92 -0
  104. pyinfra/operations/gem.py +47 -0
  105. pyinfra/operations/git.py +419 -0
  106. pyinfra/operations/iptables.py +311 -0
  107. pyinfra/operations/launchd.py +45 -0
  108. pyinfra/operations/lxd.py +68 -0
  109. pyinfra/operations/mysql.py +609 -0
  110. pyinfra/operations/npm.py +57 -0
  111. pyinfra/operations/openrc.py +63 -0
  112. pyinfra/operations/opkg.py +88 -0
  113. pyinfra/operations/pacman.py +81 -0
  114. pyinfra/operations/pip.py +205 -0
  115. pyinfra/operations/pipx.py +102 -0
  116. pyinfra/operations/pkg.py +70 -0
  117. pyinfra/operations/pkgin.py +91 -0
  118. pyinfra/operations/postgres.py +436 -0
  119. pyinfra/operations/postgresql.py +30 -0
  120. pyinfra/operations/puppet.py +40 -0
  121. pyinfra/operations/python.py +72 -0
  122. pyinfra/operations/runit.py +184 -0
  123. pyinfra/operations/selinux.py +189 -0
  124. pyinfra/operations/server.py +1099 -0
  125. pyinfra/operations/snap.py +117 -0
  126. pyinfra/operations/ssh.py +216 -0
  127. pyinfra/operations/systemd.py +149 -0
  128. pyinfra/operations/sysvinit.py +141 -0
  129. pyinfra/operations/upstart.py +68 -0
  130. pyinfra/operations/util/__init__.py +12 -0
  131. pyinfra/operations/util/docker.py +251 -0
  132. pyinfra/operations/util/files.py +247 -0
  133. pyinfra/operations/util/packaging.py +336 -0
  134. pyinfra/operations/util/service.py +46 -0
  135. pyinfra/operations/vzctl.py +137 -0
  136. pyinfra/operations/xbps.py +77 -0
  137. pyinfra/operations/yum.py +210 -0
  138. pyinfra/operations/zfs.py +175 -0
  139. pyinfra/operations/zypper.py +192 -0
  140. pyinfra/progress.py +44 -32
  141. pyinfra/py.typed +0 -0
  142. pyinfra/version.py +9 -1
  143. pyinfra-3.5.1.dist-info/METADATA +141 -0
  144. pyinfra-3.5.1.dist-info/RECORD +159 -0
  145. {pyinfra-0.11.dev3.dist-info → pyinfra-3.5.1.dist-info}/WHEEL +1 -2
  146. pyinfra-3.5.1.dist-info/entry_points.txt +12 -0
  147. {pyinfra-0.11.dev3.dist-info → pyinfra-3.5.1.dist-info/licenses}/LICENSE.md +1 -1
  148. pyinfra_cli/__init__.py +1 -0
  149. pyinfra_cli/cli.py +780 -0
  150. pyinfra_cli/commands.py +66 -0
  151. pyinfra_cli/exceptions.py +155 -65
  152. pyinfra_cli/inventory.py +233 -89
  153. pyinfra_cli/log.py +39 -43
  154. pyinfra_cli/main.py +26 -495
  155. pyinfra_cli/prints.py +215 -156
  156. pyinfra_cli/util.py +172 -105
  157. pyinfra_cli/virtualenv.py +25 -20
  158. pyinfra/api/connectors/__init__.py +0 -21
  159. pyinfra/api/connectors/ansible.py +0 -99
  160. pyinfra/api/connectors/docker.py +0 -178
  161. pyinfra/api/connectors/local.py +0 -169
  162. pyinfra/api/connectors/ssh.py +0 -402
  163. pyinfra/api/connectors/sshuserclient/client.py +0 -105
  164. pyinfra/api/connectors/sshuserclient/config.py +0 -90
  165. pyinfra/api/connectors/util.py +0 -63
  166. pyinfra/api/connectors/vagrant.py +0 -155
  167. pyinfra/facts/init.py +0 -176
  168. pyinfra/facts/util/files.py +0 -102
  169. pyinfra/hook.py +0 -41
  170. pyinfra/modules/__init__.py +0 -11
  171. pyinfra/modules/apk.py +0 -64
  172. pyinfra/modules/apt.py +0 -272
  173. pyinfra/modules/brew.py +0 -122
  174. pyinfra/modules/files.py +0 -711
  175. pyinfra/modules/gem.py +0 -30
  176. pyinfra/modules/git.py +0 -115
  177. pyinfra/modules/init.py +0 -344
  178. pyinfra/modules/iptables.py +0 -271
  179. pyinfra/modules/lxd.py +0 -45
  180. pyinfra/modules/mysql.py +0 -347
  181. pyinfra/modules/npm.py +0 -47
  182. pyinfra/modules/pacman.py +0 -60
  183. pyinfra/modules/pip.py +0 -99
  184. pyinfra/modules/pkg.py +0 -43
  185. pyinfra/modules/postgresql.py +0 -245
  186. pyinfra/modules/puppet.py +0 -20
  187. pyinfra/modules/python.py +0 -37
  188. pyinfra/modules/server.py +0 -524
  189. pyinfra/modules/ssh.py +0 -150
  190. pyinfra/modules/util/files.py +0 -52
  191. pyinfra/modules/util/packaging.py +0 -118
  192. pyinfra/modules/vzctl.py +0 -133
  193. pyinfra/modules/yum.py +0 -171
  194. pyinfra/pseudo_modules.py +0 -64
  195. pyinfra-0.11.dev3.dist-info/.DS_Store +0 -0
  196. pyinfra-0.11.dev3.dist-info/METADATA +0 -135
  197. pyinfra-0.11.dev3.dist-info/RECORD +0 -95
  198. pyinfra-0.11.dev3.dist-info/entry_points.txt +0 -3
  199. pyinfra-0.11.dev3.dist-info/top_level.txt +0 -2
  200. pyinfra_cli/__main__.py +0 -40
  201. pyinfra_cli/config.py +0 -92
  202. /pyinfra/{modules/util → connectors}/__init__.py +0 -0
  203. /pyinfra/{api/connectors → connectors}/sshuserclient/__init__.py +0 -0
@@ -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
@@ -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