Skip to content

Commit

Permalink
composer: Fix open file warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
bcl committed Oct 7, 2020
1 parent abbd86a commit 46ab9e5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/composer/cli/blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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]:
Expand Down
3 changes: 2 additions & 1 deletion src/composer/cli/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion src/composer/cli/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down

0 comments on commit 46ab9e5

Please sign in to comment.