summaryrefslogtreecommitdiffhomepage
path: root/gui/scripts
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2021-07-06 13:28:58 +0200
committerAndrej Mihajlov <and@mullvad.net>2021-07-07 10:07:48 +0200
commit44bea4169595f6f676f4f8117d95892c70641ef0 (patch)
tree2742eb4c88b25bca550db40df3d338775a6976f9 /gui/scripts
parentd4c815a12e8622699ab4609ec7aafcaf3480b8e8 (diff)
downloadmullvadvpn-44bea4169595f6f676f4f8117d95892c70641ef0.tar.xz
mullvadvpn-44bea4169595f6f676f4f8117d95892c70641ef0.zip
Scripts: use "with" with resource allocating calls
Diffstat (limited to 'gui/scripts')
-rwxr-xr-xgui/scripts/extract-geo-data.py31
-rw-r--r--gui/scripts/integrate-into-app.py9
2 files changed, 20 insertions, 20 deletions
diff --git a/gui/scripts/extract-geo-data.py b/gui/scripts/extract-geo-data.py
index f9e9def1a7..0619ed375b 100755
--- a/gui/scripts/extract-geo-data.py
+++ b/gui/scripts/extract-geo-data.py
@@ -58,15 +58,15 @@ def extract_geometry():
"features": features
}
- p = Popen(
+ with Popen(
['geo2topo', '-q', '5e3', 'geometry=-', '-o', output_path],
stdin=PIPE, stdout=PIPE, stderr=PIPE
- )
- errors = p.communicate(input=json.dumps(my_layer).encode())[1]
- if p.returncode == 0:
- print(c.green("Extracted data to {}".format(output_path)))
- else:
- print(c.red("geo2topo exited with {}. {}".format(p.returncode, errors.decode().strip())))
+ ) as subproc:
+ errors = subproc.communicate(input=json.dumps(my_layer).encode())[1]
+ if subproc.returncode == 0:
+ print(c.green("Extracted data to {}".format(output_path)))
+ else:
+ print(c.red("geo2topo exited with {}. {}".format(subproc.returncode, errors.decode().strip())))
def extract_provinces_and_states_lines():
@@ -86,15 +86,15 @@ def extract_provinces_and_states_lines():
"features": features
}
- p = Popen(
+ with Popen(
['geo2topo', '-q', '5e3', 'geometry=-', '-o', output_path],
stdin=PIPE, stdout=PIPE, stderr=PIPE
- )
- errors = p.communicate(input=json.dumps(my_layer).encode())[1]
- if p.returncode == 0:
- print(c.green("Extracted data to {}".format(output_path)))
- else:
- print(c.red("geo2topo exited with {}. {}".format(p.returncode, errors.decode().strip())))
+ ) as subproc:
+ errors = subproc.communicate(input=json.dumps(my_layer).encode())[1]
+ if subproc.returncode == 0:
+ print(c.green("Extracted data to {}".format(output_path)))
+ else:
+ print(c.red("geo2topo exited with {}. {}".format(subproc.returncode, errors.decode().strip())))
def sort_pofile_entries(pofile):
@@ -460,7 +460,8 @@ def request_relays():
data = json.dumps({"jsonrpc": "2.0", "id": "0", "method": "relay_list_v3"}).encode()
request = urllib.request.Request("https://api.mullvad.net/rpc/", data=data)
request.add_header("Content-Type", "application/json")
- return json.load(urllib.request.urlopen(request))
+ with urllib.request.urlopen(request) as connection:
+ return json.load(connection)
# Program main()
diff --git a/gui/scripts/integrate-into-app.py b/gui/scripts/integrate-into-app.py
index dde4dfbac2..86eeff63fb 100644
--- a/gui/scripts/integrate-into-app.py
+++ b/gui/scripts/integrate-into-app.py
@@ -110,12 +110,11 @@ def merge_gettext_catalogues(existing_catalogue_file, generated_catalogue_file):
def run_program(*args):
- p = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
+ with Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE) as subproc:
+ print("Run: {}".format(' '.join(args)))
- print("Run: {}".format(' '.join(args)))
-
- errors = p.communicate()[1]
- return (p.returncode, errors)
+ errors = subproc.communicate()[1]
+ return (subproc.returncode, errors)
# Program main()