forked from theforeman/foreman-packaging
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove_host
executable file
·43 lines (31 loc) · 1.06 KB
/
remove_host
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
import argparse
from pathlib import Path
from ruamel.yaml import YAML
def main():
parser = argparse.ArgumentParser()
parser.add_argument('package', nargs='+', help='Name of the package(s) to add')
parser.add_argument('--filename', help='Path to the manifest', default='package_manifest.yaml')
args = parser.parse_args()
manifest_path = Path(args.filename)
yaml = YAML(typ='rt')
yaml.default_flow_style = False
yaml.explicit_start = True
yaml.preserve_quotes = True
yaml.indent(sequence=4, offset=2)
try:
manifest = yaml.load(manifest_path.read_text())
except FileNotFoundError:
parser.error(f'Manifest {manifest_path} was not found')
for section in manifest.values():
try:
hosts = section['hosts']
except KeyError:
pass
else:
for package in args.package:
hosts.pop(package, None)
with manifest_path.open('w') as manifest_fp:
yaml.dump(manifest, manifest_fp)
if __name__ == '__main__':
main()