From 76a802428acba9ed7435602c26e2563e21ed789b Mon Sep 17 00:00:00 2001 From: Josht8601 Date: Tue, 17 Oct 2023 14:10:29 -0400 Subject: [PATCH] Added File IO --- .../scripts/preflight/SubChecklist.txt | 2 +- .../scripts/preflight/preflightFileIO.py | 62 +++++++++++++++++-- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/mil_common/utils/mil_tools/scripts/preflight/SubChecklist.txt b/mil_common/utils/mil_tools/scripts/preflight/SubChecklist.txt index 0527e6bd2..345e6aef7 100644 --- a/mil_common/utils/mil_tools/scripts/preflight/SubChecklist.txt +++ b/mil_common/utils/mil_tools/scripts/preflight/SubChecklist.txt @@ -1 +1 @@ -This is a test +Test diff --git a/mil_common/utils/mil_tools/scripts/preflight/preflightFileIO.py b/mil_common/utils/mil_tools/scripts/preflight/preflightFileIO.py index 85e357b07..272c56678 100755 --- a/mil_common/utils/mil_tools/scripts/preflight/preflightFileIO.py +++ b/mil_common/utils/mil_tools/scripts/preflight/preflightFileIO.py @@ -1,8 +1,62 @@ #!/usr/bin/env python3 -SubCheckList = open("SubChecklist.txt", "a+") -line = ["This is a test\n"] -SubCheckList.writelines(line) +# Systems[] +# Global variable that contains all the systems. Used to standardized file name. Ex Subjugator or Navigator +# writeTests(fileName, topicsToCheck[]) +# fileName should standardized, this input should be from a selected number of names +# topicsToCheck[] this array should only contain valid topics that we will make sure data is in. +# What ever program calls this function should only pass in valid topics. This will be a list of strings. +# This should not delete old topicsToCheck only add new ones. -SubCheckList.close() +# deleteTests(fileName, topicsToCheck[]) +# fileName should standardized, this input should be from a selected number of names +# topicsToCheck[] this array should only contain valid topics that we will make sure data is in. +# What ever program calls this function should only pass in valid topics. This will be a list of strings. +# delete tests from the file. + +# readTests(filename) +# reads and runs all the tests in the file. +# returns whether each test pass or fail + + +def writeTests(filename, topicsToCheck): + tests = open(filename, "a+") + lines = tests.readlines() + + # If the topic to add is not already in the list add it + for topic in topicsToCheck: + topic += "\n" + if topic not in lines: + tests.write(topic) + tests.close() + + +def deleteTests(filename, topicsToCheck): + tests = open(filename) + lines = tests.readlines() + tests.close() + + # If the topic to add is not already in the list add it + for topic in topicsToCheck: + topic += "\n" + if topic in lines: + lines.remove(topic) + + tests = open(filename, "w") + tests.writelines(lines) + + +def readTests(filename): + tests = open(filename) + lines = tests.readlines() + for i in range(len(lines)): + lines[i] = lines[i][:-1] + + print(lines) + # We need to call the ros topic and verify the data WIP + + +writeTests("SubChecklist.txt", ["Test", "testing"]) +deleteTests("SubChecklist.txt", ["testing"]) +readTests("SubChecklist.txt")