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.
Files changed (204) hide show
  1. pyinfra/__init__.py +9 -12
  2. pyinfra/__main__.py +4 -0
  3. pyinfra/api/__init__.py +19 -3
  4. pyinfra/api/arguments.py +413 -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 +73 -18
  12. pyinfra/api/facts.py +267 -200
  13. pyinfra/api/host.py +416 -50
  14. pyinfra/api/inventory.py +121 -160
  15. pyinfra/api/metadata.py +69 -0
  16. pyinfra/api/operation.py +432 -262
  17. pyinfra/api/operations.py +273 -260
  18. pyinfra/api/state.py +302 -248
  19. pyinfra/api/util.py +309 -369
  20. pyinfra/connectors/base.py +173 -0
  21. pyinfra/connectors/chroot.py +212 -0
  22. pyinfra/connectors/docker.py +405 -0
  23. pyinfra/connectors/dockerssh.py +297 -0
  24. pyinfra/connectors/local.py +238 -0
  25. pyinfra/connectors/scp/__init__.py +1 -0
  26. pyinfra/connectors/scp/client.py +204 -0
  27. pyinfra/connectors/ssh.py +727 -0
  28. pyinfra/connectors/ssh_util.py +114 -0
  29. pyinfra/connectors/sshuserclient/client.py +309 -0
  30. pyinfra/connectors/sshuserclient/config.py +102 -0
  31. pyinfra/connectors/terraform.py +135 -0
  32. pyinfra/connectors/util.py +417 -0
  33. pyinfra/connectors/vagrant.py +183 -0
  34. pyinfra/context.py +145 -0
  35. pyinfra/facts/__init__.py +7 -6
  36. pyinfra/facts/apk.py +22 -7
  37. pyinfra/facts/apt.py +117 -60
  38. pyinfra/facts/brew.py +100 -15
  39. pyinfra/facts/bsdinit.py +23 -0
  40. pyinfra/facts/cargo.py +37 -0
  41. pyinfra/facts/choco.py +47 -0
  42. pyinfra/facts/crontab.py +195 -0
  43. pyinfra/facts/deb.py +94 -0
  44. pyinfra/facts/dnf.py +48 -0
  45. pyinfra/facts/docker.py +96 -23
  46. pyinfra/facts/efibootmgr.py +113 -0
  47. pyinfra/facts/files.py +629 -58
  48. pyinfra/facts/flatpak.py +77 -0
  49. pyinfra/facts/freebsd.py +70 -0
  50. pyinfra/facts/gem.py +19 -6
  51. pyinfra/facts/git.py +59 -14
  52. pyinfra/facts/gpg.py +150 -0
  53. pyinfra/facts/hardware.py +313 -167
  54. pyinfra/facts/iptables.py +72 -62
  55. pyinfra/facts/launchd.py +44 -0
  56. pyinfra/facts/lxd.py +17 -4
  57. pyinfra/facts/mysql.py +122 -86
  58. pyinfra/facts/npm.py +17 -9
  59. pyinfra/facts/openrc.py +71 -0
  60. pyinfra/facts/opkg.py +246 -0
  61. pyinfra/facts/pacman.py +50 -7
  62. pyinfra/facts/pip.py +24 -7
  63. pyinfra/facts/pipx.py +82 -0
  64. pyinfra/facts/pkg.py +15 -6
  65. pyinfra/facts/pkgin.py +35 -0
  66. pyinfra/facts/podman.py +54 -0
  67. pyinfra/facts/postgres.py +178 -0
  68. pyinfra/facts/postgresql.py +6 -147
  69. pyinfra/facts/rpm.py +105 -0
  70. pyinfra/facts/runit.py +77 -0
  71. pyinfra/facts/selinux.py +161 -0
  72. pyinfra/facts/server.py +762 -285
  73. pyinfra/facts/snap.py +88 -0
  74. pyinfra/facts/systemd.py +139 -0
  75. pyinfra/facts/sysvinit.py +59 -0
  76. pyinfra/facts/upstart.py +35 -0
  77. pyinfra/facts/util/__init__.py +17 -0
  78. pyinfra/facts/util/databases.py +4 -6
  79. pyinfra/facts/util/packaging.py +37 -6
  80. pyinfra/facts/util/units.py +30 -0
  81. pyinfra/facts/util/win_files.py +99 -0
  82. pyinfra/facts/vzctl.py +20 -13
  83. pyinfra/facts/xbps.py +35 -0
  84. pyinfra/facts/yum.py +34 -40
  85. pyinfra/facts/zfs.py +77 -0
  86. pyinfra/facts/zypper.py +42 -0
  87. pyinfra/local.py +45 -83
  88. pyinfra/operations/__init__.py +12 -0
  89. pyinfra/operations/apk.py +99 -0
  90. pyinfra/operations/apt.py +496 -0
  91. pyinfra/operations/brew.py +232 -0
  92. pyinfra/operations/bsdinit.py +59 -0
  93. pyinfra/operations/cargo.py +45 -0
  94. pyinfra/operations/choco.py +61 -0
  95. pyinfra/operations/crontab.py +194 -0
  96. pyinfra/operations/dnf.py +213 -0
  97. pyinfra/operations/docker.py +492 -0
  98. pyinfra/operations/files.py +2014 -0
  99. pyinfra/operations/flatpak.py +95 -0
  100. pyinfra/operations/freebsd/__init__.py +12 -0
  101. pyinfra/operations/freebsd/freebsd_update.py +70 -0
  102. pyinfra/operations/freebsd/pkg.py +219 -0
  103. pyinfra/operations/freebsd/service.py +116 -0
  104. pyinfra/operations/freebsd/sysrc.py +92 -0
  105. pyinfra/operations/gem.py +48 -0
  106. pyinfra/operations/git.py +420 -0
  107. pyinfra/operations/iptables.py +312 -0
  108. pyinfra/operations/launchd.py +45 -0
  109. pyinfra/operations/lxd.py +69 -0
  110. pyinfra/operations/mysql.py +610 -0
  111. pyinfra/operations/npm.py +57 -0
  112. pyinfra/operations/openrc.py +63 -0
  113. pyinfra/operations/opkg.py +89 -0
  114. pyinfra/operations/pacman.py +82 -0
  115. pyinfra/operations/pip.py +206 -0
  116. pyinfra/operations/pipx.py +103 -0
  117. pyinfra/operations/pkg.py +71 -0
  118. pyinfra/operations/pkgin.py +92 -0
  119. pyinfra/operations/postgres.py +437 -0
  120. pyinfra/operations/postgresql.py +30 -0
  121. pyinfra/operations/puppet.py +41 -0
  122. pyinfra/operations/python.py +73 -0
  123. pyinfra/operations/runit.py +184 -0
  124. pyinfra/operations/selinux.py +190 -0
  125. pyinfra/operations/server.py +1100 -0
  126. pyinfra/operations/snap.py +118 -0
  127. pyinfra/operations/ssh.py +217 -0
  128. pyinfra/operations/systemd.py +150 -0
  129. pyinfra/operations/sysvinit.py +142 -0
  130. pyinfra/operations/upstart.py +68 -0
  131. pyinfra/operations/util/__init__.py +12 -0
  132. pyinfra/operations/util/docker.py +407 -0
  133. pyinfra/operations/util/files.py +247 -0
  134. pyinfra/operations/util/packaging.py +338 -0
  135. pyinfra/operations/util/service.py +46 -0
  136. pyinfra/operations/vzctl.py +137 -0
  137. pyinfra/operations/xbps.py +78 -0
  138. pyinfra/operations/yum.py +213 -0
  139. pyinfra/operations/zfs.py +176 -0
  140. pyinfra/operations/zypper.py +193 -0
  141. pyinfra/progress.py +44 -32
  142. pyinfra/py.typed +0 -0
  143. pyinfra/version.py +9 -1
  144. pyinfra-3.6.dist-info/METADATA +142 -0
  145. pyinfra-3.6.dist-info/RECORD +160 -0
  146. {pyinfra-0.11.dev3.dist-info → pyinfra-3.6.dist-info}/WHEEL +1 -2
  147. pyinfra-3.6.dist-info/entry_points.txt +12 -0
  148. {pyinfra-0.11.dev3.dist-info → pyinfra-3.6.dist-info/licenses}/LICENSE.md +1 -1
  149. pyinfra_cli/__init__.py +1 -0
  150. pyinfra_cli/cli.py +793 -0
  151. pyinfra_cli/commands.py +66 -0
  152. pyinfra_cli/exceptions.py +155 -65
  153. pyinfra_cli/inventory.py +233 -89
  154. pyinfra_cli/log.py +39 -43
  155. pyinfra_cli/main.py +26 -495
  156. pyinfra_cli/prints.py +215 -156
  157. pyinfra_cli/util.py +172 -105
  158. pyinfra_cli/virtualenv.py +25 -20
  159. pyinfra/api/connectors/__init__.py +0 -21
  160. pyinfra/api/connectors/ansible.py +0 -99
  161. pyinfra/api/connectors/docker.py +0 -178
  162. pyinfra/api/connectors/local.py +0 -169
  163. pyinfra/api/connectors/ssh.py +0 -402
  164. pyinfra/api/connectors/sshuserclient/client.py +0 -105
  165. pyinfra/api/connectors/sshuserclient/config.py +0 -90
  166. pyinfra/api/connectors/util.py +0 -63
  167. pyinfra/api/connectors/vagrant.py +0 -155
  168. pyinfra/facts/init.py +0 -176
  169. pyinfra/facts/util/files.py +0 -102
  170. pyinfra/hook.py +0 -41
  171. pyinfra/modules/__init__.py +0 -11
  172. pyinfra/modules/apk.py +0 -64
  173. pyinfra/modules/apt.py +0 -272
  174. pyinfra/modules/brew.py +0 -122
  175. pyinfra/modules/files.py +0 -711
  176. pyinfra/modules/gem.py +0 -30
  177. pyinfra/modules/git.py +0 -115
  178. pyinfra/modules/init.py +0 -344
  179. pyinfra/modules/iptables.py +0 -271
  180. pyinfra/modules/lxd.py +0 -45
  181. pyinfra/modules/mysql.py +0 -347
  182. pyinfra/modules/npm.py +0 -47
  183. pyinfra/modules/pacman.py +0 -60
  184. pyinfra/modules/pip.py +0 -99
  185. pyinfra/modules/pkg.py +0 -43
  186. pyinfra/modules/postgresql.py +0 -245
  187. pyinfra/modules/puppet.py +0 -20
  188. pyinfra/modules/python.py +0 -37
  189. pyinfra/modules/server.py +0 -524
  190. pyinfra/modules/ssh.py +0 -150
  191. pyinfra/modules/util/files.py +0 -52
  192. pyinfra/modules/util/packaging.py +0 -118
  193. pyinfra/modules/vzctl.py +0 -133
  194. pyinfra/modules/yum.py +0 -171
  195. pyinfra/pseudo_modules.py +0 -64
  196. pyinfra-0.11.dev3.dist-info/.DS_Store +0 -0
  197. pyinfra-0.11.dev3.dist-info/METADATA +0 -135
  198. pyinfra-0.11.dev3.dist-info/RECORD +0 -95
  199. pyinfra-0.11.dev3.dist-info/entry_points.txt +0 -3
  200. pyinfra-0.11.dev3.dist-info/top_level.txt +0 -2
  201. pyinfra_cli/__main__.py +0 -40
  202. pyinfra_cli/config.py +0 -92
  203. /pyinfra/{modules/util → connectors}/__init__.py +0 -0
  204. /pyinfra/{api/connectors → connectors}/sshuserclient/__init__.py +0 -0
@@ -1,155 +0,0 @@
1
- import json
2
-
3
- from os import path
4
- from queue import Queue
5
- from threading import Thread
6
-
7
- from pyinfra import local, logger
8
- from pyinfra.api.exceptions import InventoryError
9
- from pyinfra.api.util import memoize
10
- from pyinfra.progress import progress_spinner
11
-
12
-
13
- def _get_vagrant_ssh_config(queue, progress, target):
14
- logger.debug('Loading SSH config for {0}'.format(target))
15
-
16
- queue.put(local.shell(
17
- 'vagrant ssh-config {0}'.format(target),
18
- splitlines=True,
19
- ))
20
-
21
- progress(target)
22
-
23
-
24
- @memoize
25
- def get_vagrant_config(limit=None):
26
- logger.info('Getting Vagrant config...')
27
-
28
- if limit and not isinstance(limit, (list, tuple)):
29
- limit = [limit]
30
-
31
- with progress_spinner({'vagrant status'}) as progress:
32
- output = local.shell(
33
- 'vagrant status --machine-readable',
34
- splitlines=True,
35
- )
36
- progress('vagrant status')
37
-
38
- targets = []
39
-
40
- for line in output:
41
- _, target, type_, data = line.split(',', 3)
42
-
43
- # Skip anything not in the limit
44
- if limit is not None and target not in limit:
45
- continue
46
-
47
- # For each running container - fetch it's SSH config in a thread - this
48
- # is because Vagrant *really* slow to run each command.
49
- if type_ == 'state' and data == 'running':
50
- targets.append(target)
51
-
52
- threads = []
53
- config_queue = Queue()
54
-
55
- with progress_spinner(targets) as progress:
56
- for target in targets:
57
- thread = Thread(
58
- target=_get_vagrant_ssh_config,
59
- args=(config_queue, progress, target),
60
- )
61
- threads.append(thread)
62
- thread.start()
63
-
64
- for thread in threads:
65
- thread.join()
66
-
67
- queue_items = list(config_queue.queue)
68
-
69
- lines = []
70
- for output in queue_items:
71
- lines.extend(output)
72
-
73
- return lines
74
-
75
-
76
- @memoize
77
- def get_vagrant_options():
78
- if path.exists('@vagrant.json'):
79
- with open('@vagrant.json', 'r') as f:
80
- return json.loads(f.read())
81
- return {}
82
-
83
-
84
- def _make_name_data(host):
85
- vagrant_options = get_vagrant_options()
86
- vagrant_host = host['Host']
87
-
88
- data = {
89
- 'ssh_hostname': host['HostName'],
90
- }
91
-
92
- for config_key, data_key in (
93
- ('Port', 'ssh_port'),
94
- ('User', 'ssh_user'),
95
- ('IdentityFile', 'ssh_key'),
96
- ):
97
- if config_key in host:
98
- data[data_key] = host[config_key]
99
-
100
- # Update any configured JSON data
101
- if vagrant_host in vagrant_options.get('data', {}):
102
- data.update(vagrant_options['data'][vagrant_host])
103
-
104
- # Work out groups
105
- groups = vagrant_options.get('groups', {}).get(vagrant_host, [])
106
-
107
- if '@vagrant' not in groups:
108
- groups.append('@vagrant')
109
-
110
- return '@vagrant/{0}'.format(host['Host']), data, groups
111
-
112
-
113
- def make_names_data(limit=None):
114
- vagrant_ssh_info = get_vagrant_config(limit)
115
-
116
- logger.debug('Got Vagrant SSH info: \n{0}'.format(vagrant_ssh_info))
117
-
118
- hosts = []
119
- current_host = None
120
-
121
- for line in vagrant_ssh_info:
122
- # Vagrant outputs an empty line between each host
123
- if not line:
124
- if current_host:
125
- hosts.append(_make_name_data(current_host))
126
-
127
- current_host = None
128
- continue
129
-
130
- key, value = line.split(' ', 1)
131
-
132
- if key == 'Host':
133
- if current_host:
134
- hosts.append(_make_name_data(current_host))
135
-
136
- # Set the new host
137
- current_host = {
138
- key: value,
139
- }
140
-
141
- elif current_host:
142
- current_host[key] = value
143
-
144
- else:
145
- logger.debug('Extra Vagrant SSH key/value ({0}={1})'.format(
146
- key, value,
147
- ))
148
-
149
- if current_host:
150
- hosts.append(_make_name_data(current_host))
151
-
152
- if not hosts:
153
- raise InventoryError('No running Vagrant instances found!')
154
-
155
- return hosts
pyinfra/facts/init.py DELETED
@@ -1,176 +0,0 @@
1
- import re
2
-
3
- from pyinfra.api import FactBase
4
-
5
-
6
- class UpstartStatus(FactBase):
7
- '''
8
- Returns a dict of name -> status for upstart managed services.
9
- '''
10
-
11
- command = 'initctl list'
12
- regex = r'^([a-z\-]+) [a-z]+\/([a-z]+)'
13
- default = dict
14
-
15
- def process(self, output):
16
- services = {}
17
-
18
- for line in output:
19
- matches = re.match(self.regex, line)
20
- if matches:
21
- services[matches.group(1)] = matches.group(2) == 'running'
22
-
23
- return services
24
-
25
-
26
- class SystemdStatus(FactBase):
27
- '''
28
- Returns a dict of name -> status for systemd managed services.
29
- '''
30
-
31
- command = 'systemctl -alt service list-units'
32
- regex = r'^([a-z\-0-9]+)\.service\s+[a-z\-]+\s+[a-z]+\s+([a-z]+)'
33
- default = dict
34
-
35
- def process(self, output):
36
- services = {}
37
-
38
- for line in output:
39
- matches = re.match(self.regex, line)
40
- if matches:
41
- services[matches.group(1)] = matches.group(2) == 'running'
42
-
43
- return services
44
-
45
-
46
- class SystemdEnabled(FactBase):
47
- '''
48
- Returns a dict of name -> whether enabled for systemd managed services.
49
- '''
50
-
51
- command = '''
52
- systemctl --no-legend -alt service list-unit-files | while read -r SERVICE STATUS; do
53
- if [ "$STATUS" = generated ] &&
54
- systemctl is-enabled $SERVICE.service >/dev/null 2>&1; then
55
- STATUS=enabled
56
- fi
57
- echo $SERVICE $STATUS
58
- done
59
- '''
60
-
61
- regex = r'^([a-z\-]+)\.service\s+([a-z]+)'
62
- default = dict
63
-
64
- def process(self, output):
65
- services = {}
66
-
67
- for line in output:
68
- matches = re.match(self.regex, line)
69
- if matches:
70
- services[matches.group(1)] = (
71
- matches.group(2) in ('enabled', 'static')
72
- )
73
-
74
- return services
75
-
76
-
77
- class InitdStatus(FactBase):
78
- '''
79
- Low level check for every /etc/init.d/* script. Unfortunately many of these
80
- mishehave and return exit status 0 while also displaying the help info/not
81
- offering status support.
82
-
83
- Returns a dict of name -> status.
84
-
85
- Expected codes found at:
86
- http://refspecs.linuxbase.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
87
- '''
88
-
89
- command = '''
90
- for SERVICE in `ls /etc/init.d/`; do
91
- _=`cat /etc/init.d/$SERVICE | grep "### BEGIN INIT INFO"`
92
-
93
- if [ "$?" = "0" ]; then
94
- STATUS=`/etc/init.d/$SERVICE status`
95
- echo "$SERVICE=$?"
96
- fi
97
- done
98
- '''
99
-
100
- regex = r'([a-zA-Z0-9\-]+)=([0-9]+)'
101
- default = dict
102
-
103
- def process(self, output):
104
- services = {}
105
-
106
- for line in output:
107
- matches = re.match(self.regex, line)
108
- if matches:
109
- status = int(matches.group(2))
110
-
111
- # Exit code 0 = OK/running
112
- if status == 0:
113
- status = True
114
-
115
- # Exit codes 1-3 = DOWN/not running
116
- elif status < 4:
117
- status = False
118
-
119
- # Exit codes 4+ = unknown
120
- else:
121
- status = None
122
-
123
- services[matches.group(1)] = status
124
-
125
- return services
126
-
127
-
128
- class RcdStatus(InitdStatus):
129
- '''
130
- Same as ``initd_status`` but for BSD (/etc/rc.d) systems. Unlike Linux/init.d,
131
- BSD init scripts are well behaved and as such their output can be trusted.
132
- '''
133
-
134
- command = '''
135
- for SERVICE in `ls /etc/rc.d/`; do
136
- _=`cat /etc/rc.d/$SERVICE | grep "daemon="`
137
-
138
- if [ "$?" = "0" ]; then
139
- STATUS=`/etc/rc.d/$SERVICE check`
140
- echo "$SERVICE=$?"
141
- fi
142
- done
143
- '''
144
-
145
- default = dict
146
-
147
-
148
- class LaunchdStatus(FactBase):
149
- '''
150
- Returns a dict of name -> status for launchd managed services.
151
- '''
152
-
153
- command = 'launchctl list'
154
- default = dict
155
-
156
- def process(self, output):
157
- services = {}
158
-
159
- for line in output:
160
- bits = line.split()
161
-
162
- if not bits or bits[0] == 'PID':
163
- continue
164
-
165
- name = bits[2]
166
- status = False
167
-
168
- try:
169
- int(bits[0])
170
- status = True
171
- except ValueError:
172
- pass
173
-
174
- services[name] = status
175
-
176
- return services
@@ -1,102 +0,0 @@
1
- import re
2
- from datetime import datetime
3
-
4
-
5
- LS_REGEX = re.compile((
6
- # Type flag
7
- r'^[bcdlsp\-]'
8
- # Permissions/ACL
9
- r'([\-rwxsS]{9})[\.\+]?\s+'
10
- # Links (unused)
11
- r'[0-9]+\s+'
12
- # User & group
13
- r'([\w-]+)\s+([\w-]+)\s+'
14
- # Size
15
- r'([0-9]+)\s+'
16
- # Date start options
17
- r'((?:'
18
- # BSD format
19
- r'[a-zA-Z]{3}\s+[0-9]{1,2}\s+[0-9:]{8}\s+[0-9]{4}'
20
- # Or Linux format (ISO)
21
- r'|[0-9]{4}\-[0-9]{2}\-[0-9]{2}\s+[0-9:]{5}'
22
- # Date end
23
- r'))\s+'
24
- # Filename
25
- r'[\w\/\.@-]+'
26
- # Optional link target
27
- r'\s?-?>?\s?([\w\/\.@-]*)'
28
- ))
29
-
30
- FLAG_TO_TYPE = {
31
- 'b': 'block',
32
- 'c': 'character',
33
- 'd': 'directory',
34
- 'l': 'link',
35
- 's': 'socket',
36
- 'p': 'fifo',
37
- '-': 'file',
38
- }
39
-
40
- SYMBOL_TO_OCTAL_PERMISSIONS = {
41
- 'rwx': '7',
42
- 'rw-': '6',
43
- 'r-x': '5',
44
- 'r--': '4',
45
- '-wx': '3',
46
- '-w-': '2',
47
- '--x': '1',
48
- }
49
-
50
-
51
- def _parse_mode(mode):
52
- '''
53
- Converts ls mode output (rwxrwxrwx) -> integer (755).
54
- '''
55
-
56
- result = ''
57
- # owner, group, world
58
- for group in [mode[0:3], mode[3:6], mode[6:9]]:
59
- if group in SYMBOL_TO_OCTAL_PERMISSIONS:
60
- result = '{0}{1}'.format(result, SYMBOL_TO_OCTAL_PERMISSIONS[group])
61
- else:
62
- result = '{0}0'.format(result)
63
-
64
- # Return as an integer
65
- return int(result)
66
-
67
-
68
- def _parse_time(time):
69
- # Try matching with BSD format
70
- try:
71
- return datetime.strptime(time, '%b %d %H:%M:%S %Y')
72
- except ValueError:
73
- pass
74
-
75
- # Try matching ISO format
76
- try:
77
- return datetime.strptime(time, '%Y-%m-%d %H:%M')
78
- except ValueError:
79
- pass
80
-
81
-
82
- def parse_ls_output(output, wanted_type):
83
- if output:
84
- matches = re.match(LS_REGEX, output)
85
- if matches:
86
- type = FLAG_TO_TYPE[output[0]]
87
-
88
- if type != wanted_type:
89
- return False
90
-
91
- out = {
92
- 'mode': _parse_mode(matches.group(1)),
93
- 'user': matches.group(2),
94
- 'group': matches.group(3),
95
- 'size': matches.group(4),
96
- 'mtime': _parse_time(matches.group(5)),
97
- }
98
-
99
- if type == 'link':
100
- out['link_target'] = matches.group(6)
101
-
102
- return out
pyinfra/hook.py DELETED
@@ -1,41 +0,0 @@
1
- from functools import wraps
2
-
3
- from click import ClickException
4
-
5
- from pyinfra.api.exceptions import PyinfraError
6
-
7
- from . import pseudo_state
8
-
9
- HOOKS = {
10
- 'before_connect': [],
11
- 'before_facts': [],
12
- 'before_deploy': [],
13
- 'after_deploy': [],
14
- }
15
-
16
-
17
- class Error(PyinfraError, ClickException):
18
- '''
19
- Exception raised when encounting errors in deploy hooks.
20
- '''
21
-
22
-
23
- def _make_hook_wrapper(hook_name):
24
- def hook_func(func):
25
- # Only add hooks when the state is not initialised
26
- if pseudo_state.initialised:
27
- return
28
-
29
- HOOKS[hook_name].append(func)
30
-
31
- @wraps(func)
32
- def decorated(*args, **kwargs):
33
- return func(*args, **kwargs)
34
-
35
- return hook_func
36
-
37
-
38
- before_connect = _make_hook_wrapper('before_connect')
39
- before_facts = _make_hook_wrapper('before_facts')
40
- before_deploy = _make_hook_wrapper('before_deploy')
41
- after_deploy = _make_hook_wrapper('after_deploy')
@@ -1,11 +0,0 @@
1
- from glob import glob
2
- from os import path
3
-
4
-
5
- module_filenames = glob(path.join(path.dirname(__file__), '*.py'))
6
- module_names = [path.basename(name)[:-3] for name in module_filenames]
7
- __all__ = [name for name in module_names if name != '__init__']
8
-
9
-
10
- # Actually triggers __all__ imports to builds operations index
11
- from . import * # noqa
pyinfra/modules/apk.py DELETED
@@ -1,64 +0,0 @@
1
- '''
2
- Mange apk packages.
3
- '''
4
-
5
- from pyinfra.api import operation
6
-
7
- from .util.packaging import ensure_packages
8
-
9
-
10
- @operation
11
- def upgrade(state, host):
12
- '''
13
- Upgrades all apk packages.
14
- '''
15
-
16
- yield 'apk upgrade'
17
-
18
- _upgrade = upgrade # noqa: E305
19
-
20
-
21
- @operation
22
- def update(state, host):
23
- '''
24
- Updates apk repositories.
25
- '''
26
-
27
- yield 'apk update'
28
-
29
- _update = update # noqa: E305
30
-
31
-
32
- @operation
33
- def packages(
34
- state, host,
35
- packages=None, present=True, latest=False,
36
- update=False, upgrade=False,
37
- ):
38
- '''
39
- Add/remove/update apk packages.
40
-
41
- + packages: list of packages to ensure
42
- + present: whether the packages should be installed
43
- + latest: whether to upgrade packages without a specified version
44
- + update: run apk update before installing packages
45
- + upgrade: run apk upgrade before installing packages
46
-
47
- Versions:
48
- Package versions can be pinned like apk: ``<pkg>=<version>``.
49
- '''
50
-
51
- if update:
52
- yield _update(state, host)
53
-
54
- if upgrade:
55
- yield _upgrade(state, host)
56
-
57
- yield ensure_packages(
58
- packages, host.fact.apk_packages, present,
59
- install_command='apk add',
60
- uninstall_command='apk remove',
61
- upgrade_command='apk upgrade',
62
- version_join='=',
63
- latest=latest,
64
- )