composer: Fix open file warnings

This commit is contained in:
Brian C. Lane 2020-10-07 09:33:51 -07:00 committed by Brian C. Lane
parent abbd86a2f6
commit 46ab9e55f5
3 changed files with 12 additions and 6 deletions

View File

@ -328,7 +328,8 @@ def blueprints_save(socket_path, api_version, args, show_json=False):
for blueprint in argify(args):
api_route = client.api_url(api_version, "/blueprints/info/%s?format=toml" % blueprint)
blueprint_toml = client.get_url_raw(socket_path, api_route)
open(toml_filename(blueprint), "w").write(blueprint_toml)
with open(toml_filename(blueprint), "w") as f:
f.write(blueprint_toml)
return 0
@ -401,7 +402,8 @@ def blueprints_push(socket_path, api_version, args, show_json=False):
if not os.path.exists(blueprint):
log.error("Missing blueprint file: %s", blueprint)
continue
blueprint_toml = open(blueprint, "r").read()
with open(blueprint, "r") as f:
blueprint_toml = f.read()
result = client.post_url_toml(socket_path, api_route, blueprint_toml)
if handle_api_result(result, show_json)[0]:
@ -500,7 +502,8 @@ def blueprints_freeze_save(socket_path, api_version, args, show_json=False):
for blueprint in argify(args):
api_route = client.api_url(api_version, "/blueprints/freeze/%s?format=toml" % blueprint)
blueprint_toml = client.get_url_raw(socket_path, api_route)
open(frozen_toml_filename(blueprint), "w").write(blueprint_toml)
with open(frozen_toml_filename(blueprint), "w") as f:
f.write(blueprint_toml)
return 0
@ -569,7 +572,8 @@ def blueprints_workspace(socket_path, api_version, args, show_json=False):
if not os.path.exists(blueprint):
log.error("Missing blueprint file: %s", blueprint)
continue
blueprint_toml = open(blueprint, "r").read()
with open(blueprint, "r") as f:
blueprint_toml = f.read()
result = client.post_url_toml(socket_path, api_route, blueprint_toml)
if handle_api_result(result, show_json)[0]:

View File

@ -248,7 +248,8 @@ def providers_save(socket_path, api_version, args, show_json=False, testmode=0):
"profile": args[1],
"settings": results[args[0]]["profiles"][args[1]]
}
open(toml_filename(args[1]), "w").write(toml.dumps(profile))
with open(toml_filename(args[1]), "w") as f:
f.write(toml.dumps(profile))
return 0

View File

@ -125,7 +125,8 @@ def sources_add(socket_path, api_version, args, show_json=False):
if not os.path.exists(source):
log.error("Missing source file: %s", source)
continue
source_toml = open(source, "r").read()
with open(source, "r") as f:
source_toml = f.read()
result = client.post_url_toml(socket_path, api_route, source_toml)
if handle_api_result(result, show_json)[0]: