Skip to content

Config Output Auto-update Script #948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions check_tools/config-update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import sys, os
import re
import subprocess

def split_into_pairs(l):
for i in range(0, len(l), 2):
yield l[i:i + 2]

def main(file):
file_h = open(file, 'r+')
file = file_h.read()
snippet_indices = [m.start() for m in re.finditer('```', file)]

blocks = {}
for i in range(0, int(len(snippet_indices) / 2)):
# Need to rerun on every loop as the indices change each iteration
snippet_indices = [m.start() for m in re.finditer('```', file)]
ranges = list(split_into_pairs(snippet_indices))
start = ranges[i][0]
end = ranges[i][1]

try:
blocks[i] = file[start : end + 3]
if ('Name: ' in blocks[i]):
lib = blocks[i].split('Name: ')[1].split('.')[0]
print("================= %s =================" % lib)
out = str(subprocess.check_output(["mbed", "compile", "--config", "-v", "--prefix", lib]))
file = file[:start+4] + out[:out.index("Macros") - 1] + file[end:]

# Originally added for debugging purposes, catch and display exceptions before
# continuing without exiting to provide a complete list of errors found
except Exception as e:
print("Error")
print(e)
print("____________________")
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print(exc_type, fname, exc_tb.tb_lineno)
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked offline why this has exception handling here as it looks like it doesn't do anything. I was wrong, this one passes (is there another way to do this?). You may want a comment to explain this for idiots like me :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updooted, I'm also OK with removing this section as its more of a vestigial hold out from development (although can still be helpful, let me catch minor exceptions that didn't cause issues without exiting and provided a full list of all files that caused issues).


file_h.truncate(0)
file_h.seek(0)
file_h.write(file)
file_h.close()

if __name__ == '__main__':
if (len(sys.argv) < 2):
path = '../docs/reference/configuration'
else:
path = sys.argv[1]

if (path == '-h' or path == '--help'):
print("By default the script runs out of the docs tools directory and iterates through reference/configuration.\n"
"You may pass in a directory path that will run on all files contained within, or a single file path optionally.")
exit(0)

if (os.path.isfile(path)):
main(path)
elif (os.path.isdir(path)):
for doc in os.listdir(path):
if (doc != 'configuration.md'):
print('_____ %s _____' % os.path.join(path, doc))
main(os.path.join(path, doc))
else:
print("Please provide a valid file or directory path")
Loading