Skip to content

Commit

Permalink
Fixing project.py -S printing problem
Browse files Browse the repository at this point in the history
Printing too large of a string can fail in Windows, as detailed here:
https://bugs.python.org/issue11395. This works around the problem by
adding a print_large_string function that breaks up the string into
smaller pieces before printing it.
  • Loading branch information
bridadan committed Oct 31, 2016
1 parent 8a9a246 commit 67c2ea7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tools/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from tools.utils import argparse_filestring_type, argparse_many, args_error
from tools.utils import argparse_force_lowercase_type
from tools.utils import argparse_force_uppercase_type
from tools.utils import print_large_string
from tools.project_api import export_project, get_exporter_toolchain
from tools.options import extract_profile

Expand Down Expand Up @@ -189,7 +190,7 @@ def main():

# Only prints matrix of supported IDEs
if options.supported_ides:
print mcu_ide_matrix()
print_large_string(mcu_ide_matrix())
exit(0)

# Only prints matrix of supported IDEs
Expand Down
21 changes: 21 additions & 0 deletions tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from os.path import isdir, join, exists, split, relpath, splitext, abspath
from os.path import commonprefix, normpath, dirname
from subprocess import Popen, PIPE, STDOUT, call
from math import ceil
import json
from collections import OrderedDict
import logging
Expand Down Expand Up @@ -486,3 +487,23 @@ def parse_type(not_parent):
else:
return not_parent
return parse_type

def print_large_string(large_string):
""" Breaks a string up into smaller pieces before print them
This is a limitation within Windows, as detailed here:
https://bugs.python.org/issue11395
Positional arguments:
large_string - the large string to print
"""
string_limit = 1000
large_string_len = len(large_string)
num_parts = int(ceil(float(large_string_len) / float(string_limit)))
for string_part in range(num_parts):
start_index = string_part * string_limit
if string_part == num_parts - 1:
print large_string[start_index:]
else:
end_index = ((string_part + 1) * string_limit) - 1
print large_string[start_index:end_index],

0 comments on commit 67c2ea7

Please sign in to comment.