Skip to content

Commit d9f1497

Browse files
ekohlevgeni
authored andcommitted
Drop Python 2 compatibility
1 parent 4718e55 commit d9f1497

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

development/scripts/vagrant.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
1-
#!/usr/bin/env bash
2-
# this is a very crude hack and can be removed once we have no more python2 systems
3-
# that need to run this code
4-
"exec" "$(command -v python3 || command -v python)" "$0" "$@"
1+
#!/usr/bin/env python3
52
# Adapted from Mark Mandel's implementation
63
# https://github.com/ansible/ansible/blob/devel/plugins/inventory/vagrant.py
74
import argparse
85
import json
9-
import os
106
import subprocess
117
import sys
128
import yaml
139

14-
try:
15-
from StringIO import StringIO # pyright: reportMissingImports=false
16-
except ImportError:
17-
from io import StringIO # pyright: reportMissingImports=false
18-
1910
from collections import defaultdict
2011

2112

22-
try:
23-
DEVNULL = subprocess.DEVNULL
24-
except AttributeError:
25-
DEVNULL = open(os.devnull, 'w')
26-
27-
2813
def parse_args():
2914
parser = argparse.ArgumentParser(description="Vagrant inventory script")
3015
group = parser.add_mutually_exclusive_group(required=True)
@@ -36,7 +21,7 @@ def parse_args():
3621

3722
def get_running_hosts():
3823
try:
39-
subprocess.check_call(["which", "vagrant"], stdout=DEVNULL)
24+
subprocess.check_call(["which", "vagrant"], stdout=subprocess.DEVNULL)
4025
except subprocess.CalledProcessError:
4126
return
4227

@@ -70,7 +55,7 @@ def list_running_hosts():
7055
def get_ssh_configs(hosts):
7156
cmd = ['vagrant', 'ssh-config'] + hosts
7257
try:
73-
output = subprocess.check_output(cmd, universal_newlines=True, stderr=DEVNULL)
58+
output = subprocess.check_output(cmd, universal_newlines=True, stderr=subprocess.DEVNULL)
7459
except subprocess.CalledProcessError:
7560
return None
7661

0 commit comments

Comments
 (0)