-
Notifications
You must be signed in to change notification settings - Fork 178
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
AnotherButler
merged 21 commits into
ARMmbed:development
from
kegilbert:config-doc-update-script
Feb 27, 2019
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
6b234ce
First pass at config doc update script.
kegilbert 3c5bb53
Add Python interpretation
kegilbert 1d8d2b4
Squash connectivity config option list to single pane
kegilbert 446d8a0
Add small check for snippet blocks not containing a name keyword
kegilbert 4caba20
Run config list with prefix
kegilbert aa633bb
Swap config blocks in file
kegilbert 44d1dfa
Minor loop formatting cleanup
kegilbert 2f22bf0
Make Python3 compliant
kegilbert 8b46dbc
Move script to tools folder
kegilbert d9cae1a
Add default file path
kegilbert 6dc9927
Remove proto shell script effort
kegilbert 39a4f21
Clean up script usage
kegilbert 19d95eb
Do not run on configuration.md
kegilbert 6a487ff
Post script config markdown files
kegilbert 2b94675
Cleanup LoRaWAN config file
kegilbert e7b48f3
Add minor help script and comments
kegilbert 5e2f758
Clear file before writing to prevent trailing junk.
kegilbert e6cfa05
Rerun script with proper truncation
kegilbert 3ac0648
Add exception handling comment
kegilbert 9589fd2
Add isdir check on paths
kegilbert f19914d
Fix str/byte formatting between Python2/3
kegilbert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
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") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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).