[discinfo] Use context manager for file access
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
2113b6475c
commit
8ef9478879
@ -45,19 +45,18 @@ def write_discinfo(file_path, description, arch, disc_numbers=None, timestamp=No
|
|||||||
raise TypeError("Invalid type: disc_numbers type is %s; expected: <list>" % type(disc_numbers))
|
raise TypeError("Invalid type: disc_numbers type is %s; expected: <list>" % type(disc_numbers))
|
||||||
if not timestamp:
|
if not timestamp:
|
||||||
timestamp = "%f" % time.time()
|
timestamp = "%f" % time.time()
|
||||||
f = open(file_path, "w")
|
with open(file_path, "w") as f:
|
||||||
f.write("%s\n" % timestamp)
|
f.write("%s\n" % timestamp)
|
||||||
f.write("%s\n" % description)
|
f.write("%s\n" % description)
|
||||||
f.write("%s\n" % arch)
|
f.write("%s\n" % arch)
|
||||||
if disc_numbers:
|
if disc_numbers:
|
||||||
f.write("%s\n" % ",".join([str(i) for i in disc_numbers]))
|
f.write("%s\n" % ",".join([str(i) for i in disc_numbers]))
|
||||||
f.close()
|
|
||||||
return timestamp
|
return timestamp
|
||||||
|
|
||||||
|
|
||||||
def read_discinfo(file_path):
|
def read_discinfo(file_path):
|
||||||
result = {}
|
result = {}
|
||||||
f = open(file_path, "r")
|
with open(file_path, "r") as f:
|
||||||
result["timestamp"] = f.readline().strip()
|
result["timestamp"] = f.readline().strip()
|
||||||
result["description"] = f.readline().strip()
|
result["description"] = f.readline().strip()
|
||||||
result["arch"] = f.readline().strip()
|
result["arch"] = f.readline().strip()
|
||||||
|
Loading…
Reference in New Issue
Block a user