summaryrefslogtreecommitdiffstats
path: root/src/engine/SCons/Optik/option_parser.py
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2003-06-25 16:32:43 (GMT)
committerSteven Knight <knight@baldmt.com>2003-06-25 16:32:43 (GMT)
commit35828d429f289360d9baaac22bd779633d1ef538 (patch)
treef75465c08a6eac0c08895be282d9a63f4a1d2f9a /src/engine/SCons/Optik/option_parser.py
parent89cbcdab1aa03c28d7f9e55bc5c67ac4fece1693 (diff)
downloadSCons-35828d429f289360d9baaac22bd779633d1ef538.zip
SCons-35828d429f289360d9baaac22bd779633d1ef538.tar.gz
SCons-35828d429f289360d9baaac22bd779633d1ef538.tar.bz2
Eliminate the need to import distutils.fancy_getopt.
Diffstat (limited to 'src/engine/SCons/Optik/option_parser.py')
-rw-r--r--src/engine/SCons/Optik/option_parser.py71
1 files changed, 70 insertions, 1 deletions
diff --git a/src/engine/SCons/Optik/option_parser.py b/src/engine/SCons/Optik/option_parser.py
index ebe8336..94375d0 100644
--- a/src/engine/SCons/Optik/option_parser.py
+++ b/src/engine/SCons/Optik/option_parser.py
@@ -556,7 +556,10 @@ class OptionParser:
Print an extended help message, listing all options and any
help text provided with them, to 'file' (default stdout).
"""
- from distutils.fancy_getopt import wrap_text
+ # SCons: don't import wrap_text from distutils, use the
+ # copy we've included below, so we can avoid being dependent
+ # on having the right version of distutils installed.
+ #from distutils.fancy_getopt import wrap_text
if file is None:
file = sys.stdout
@@ -659,3 +662,69 @@ def _match_abbrev (s, wordmap):
# More than one possible completion: ambiguous prefix.
raise BadOptionError("ambiguous option: %s (%s?)"
% (s, string.join(possibilities,", ")))
+
+# SCons: Include a snarfed copy of wrap_text(), so we're not dependent
+# on the right version of distutils being installed.
+import re
+
+WS_TRANS = string.maketrans(string.whitespace, ' ' * len(string.whitespace))
+
+def wrap_text (text, width):
+ """wrap_text(text : string, width : int) -> [string]
+
+ Split 'text' into multiple lines of no more than 'width' characters
+ each, and return the list of strings that results.
+ """
+
+ if text is None:
+ return []
+ if len(text) <= width:
+ return [text]
+
+ text = string.expandtabs(text)
+ text = string.translate(text, WS_TRANS)
+ chunks = re.split(r'( +|-+)', text)
+ chunks = filter(None, chunks) # ' - ' results in empty strings
+ lines = []
+
+ while chunks:
+
+ cur_line = [] # list of chunks (to-be-joined)
+ cur_len = 0 # length of current line
+
+ while chunks:
+ l = len(chunks[0])
+ if cur_len + l <= width: # can squeeze (at least) this chunk in
+ cur_line.append(chunks[0])
+ del chunks[0]
+ cur_len = cur_len + l
+ else: # this line is full
+ # drop last chunk if all space
+ if cur_line and cur_line[-1][0] == ' ':
+ del cur_line[-1]
+ break
+
+ if chunks: # any chunks left to process?
+
+ # if the current line is still empty, then we had a single
+ # chunk that's too big too fit on a line -- so we break
+ # down and break it up at the line width
+ if cur_len == 0:
+ cur_line.append(chunks[0][0:width])
+ chunks[0] = chunks[0][width:]
+
+ # all-whitespace chunks at the end of a line can be discarded
+ # (and we know from the re.split above that if a chunk has
+ # *any* whitespace, it is *all* whitespace)
+ if chunks[0][0] == ' ':
+ del chunks[0]
+
+ # and store this line in the list-of-all-lines -- as a single
+ # string, of course!
+ lines.append(string.join(cur_line, ''))
+
+ # while chunks
+
+ return lines
+
+# wrap_text ()