moved file check into statcollect function only if results are true

This commit is contained in:
Marc Mance
2024-06-06 14:50:24 -04:00
parent 9c24ca5a56
commit 0bdc036f01
4 changed files with 32 additions and 32 deletions

View File

@@ -38,14 +38,6 @@ headerRow = [
filename = "topStat.csv"
# Check if the file exists
if not os.path.exists(filename):
# Create the file in write mode ('w') if it doesn't exist
with open(filename, "w", newline="") as csvfile:
csv_writer = csv.writer(csvfile)
# Write the header row (optional)
csv_writer.writerow(headerRow)
def convert_to_megabytes(data_size):
"""
@@ -89,6 +81,14 @@ def runtopstat():
# Check the return code (0 for success)
if result.returncode == 0:
# Check if the file exists
if not os.path.exists(filename):
# Create the file in write mode ('w') if it doesn't exist
with open(filename, "w", newline="") as csvfile:
csv_writer = csv.writer(csvfile)
# Write the header row (optional)
csv_writer.writerow(headerRow)
# Access the captured output as a string
output = result.stdout