[Python-checkins] CVS: python/dist/src/Doc/tools buildindex.py,1.11,1.11.26.1

Fred L. Drake fdrake@users.sourceforge.net
2001年12月27日 20:36:16 -0800


Update of /cvsroot/python/python/dist/src/Doc/tools
In directory usw-pr-cvs1:/tmp/cvs-serv5343/tools
Modified Files:
 Tag: release22-maint
	buildindex.py 
Log Message:
Make this do the right thing with entries which start with the percent sign,
in response to Skip's comments in SF bug #487165.
Make use of string methods instead of string module functions in most places.
Add (and make the default) a way to collapse symbol entries into a single
"Symbols" section in the generated index. This is similar to what makeindex
does, but does not include entries beginning with an underscore.
Index: buildindex.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/tools/buildindex.py,v
retrieving revision 1.11
retrieving revision 1.11.26.1
diff -C2 -d -r1.11 -r1.11.26.1
*** buildindex.py	2000年04月03日 04:19:14	1.11
--- buildindex.py	2001年12月28日 04:36:14	1.11.26.1
***************
*** 9,12 ****
--- 9,16 ----
 
 
+ bang_join = "!".join
+ null_join = "".join
+ 
+ 
 class Node:
 __rmjunk = re.compile("<#\d+#>")
***************
*** 39,51 ****
 
 def __repr__(self):
! return "<Node for %s (%s)>" % (string.join(self.text, '!'), self.seqno)
 
 def __str__(self):
! return string.join(self.key, '!')
 
 def dump(self):
 return "%s1円%s###%s\n" \
 % (string.join(self.links, "1円"),
! string.join(self.text, '!'),
 self.seqno)
 
--- 43,55 ----
 
 def __repr__(self):
! return "<Node for %s (%s)>" % (bang_join(self.text), self.seqno)
 
 def __str__(self):
! return bang_join(self.key)
 
 def dump(self):
 return "%s1円%s###%s\n" \
 % (string.join(self.links, "1円"),
! bang_join(self.text),
 self.seqno)
 
***************
*** 55,60 ****
 if result == 0:
 return 0
! l1 = string.lower(s1)
! l2 = string.lower(s2)
 minlen = min(len(s1), len(s2))
 if len(s1) < len(s2) and l1 == l2[:len(s1)]:
--- 59,64 ----
 if result == 0:
 return 0
! l1 = s1.lower()
! l2 = s2.lower()
 minlen = min(len(s1), len(s2))
 if len(s1) < len(s2) and l1 == l2[:len(s1)]:
***************
*** 69,74 ****
 def split_entry(str, which):
 stuff = []
! parts = string.split(str, '!')
! parts = map(string.split, parts, ['@'] * len(parts))
 for entry in parts:
 if len(entry) != 1:
--- 73,78 ----
 def split_entry(str, which):
 stuff = []
! parts = str.split('!')
! parts = [part.split('@') for part in parts]
 for entry in parts:
 if len(entry) != 1:
***************
*** 89,95 ****
 m = _rmtt.match(parts[i])
 if m:
! parts[i] = string.join(m.group(1, 2, 3), '')
 else:
! parts[i] = string.lower(parts[i])
 # remove '()' from the key:
 parts[i] = _rmparens.sub('', parts[i])
--- 93,99 ----
 m = _rmtt.match(parts[i])
 if m:
! parts[i] = null_join(m.group(1, 2, 3))
 else:
! parts[i] = parts[i].lower()
 # remove '()' from the key:
 parts[i] = _rmparens.sub('', parts[i])
***************
*** 101,105 ****
 m = _rmtt.match(str)
 if m:
! str = string.join(m.group(1, 2, 3), '')
 return split_entry(str, 1)
 
--- 105,109 ----
 m = _rmtt.match(str)
 if m:
! str = null_join(m.group(1, 2, 3))
 return split_entry(str, 1)
 
***************
*** 122,133 ****
 # ignore $ to keep environment variables with the
 # leading letter from the name
! s = string.lower(s)
! if s[0] == "$":
! return s[1:]
 else:
! return s
 
 def get_first_letter(s):
! return string.lower(trim_ignored_letters(s)[0])
 
 
--- 126,139 ----
 # ignore $ to keep environment variables with the
 # leading letter from the name
! if s.startswith("$"):
! return s[1:].lower()
 else:
! return s.lower()
 
 def get_first_letter(s):
! if s.startswith("<tex2html_percent_mark>"):
! return "%"
! else:
! return trim_ignored_letters(s)[0]
 
 
***************
*** 150,153 ****
--- 156,169 ----
 
 
+ def group_symbols(groups):
+ entries = []
+ ident_letters = string.ascii_letters + "_"
+ while groups[0][0] not in ident_letters:
+ entries += groups[0][1]
+ del groups[0]
+ if entries:
+ groups.insert(0, ("Symbols", entries))
+ 
+ 
 # need a function to separate the nodes into columns...
 def split_columns(nodes, columns=1):
***************
*** 156,161 ****
 # This is a rough height; we may have to increase to avoid breaks before
 # a subitem.
! colheight = len(nodes) / columns
! numlong = len(nodes) % columns
 if numlong:
 colheight = colheight + 1
--- 172,177 ----
 # This is a rough height; we may have to increase to avoid breaks before
 # a subitem.
! colheight = int(len(nodes) / columns)
! numlong = int(len(nodes) % columns)
 if numlong:
 colheight = colheight + 1
***************
*** 170,174 ****
 colheight = colheight - 1
 try:
! numshort = len(nodes) / colheight
 except ZeroDivisionError:
 cols = cols + (columns - len(cols)) * [[]]
--- 186,190 ----
 colheight = colheight - 1
 try:
! numshort = int(len(nodes) / colheight)
 except ZeroDivisionError:
 cols = cols + (columns - len(cols)) * [[]]
***************
*** 236,240 ****
 append("\n")
 append("</dl>" * (level + 1))
! return string.join(strings, '')
 
 
--- 252,256 ----
 append("\n")
 append("</dl>" * (level + 1))
! return null_join(strings)
 
 
***************
*** 244,251 ****
 if columns > 1:
 colnos = range(columns)
! colheight = len(nodes) / columns
 if len(nodes) % columns:
 colheight = colheight + 1
! colwidth = 100 / columns
 append('<table width="100%"><tr valign="top">')
 for col in split_columns(nodes, columns):
--- 260,267 ----
 if columns > 1:
 colnos = range(columns)
! colheight = int(len(nodes) / columns)
 if len(nodes) % columns:
 colheight = colheight + 1
! colwidth = int(100 / columns)
 append('<table width="100%"><tr valign="top">')
 for col in split_columns(nodes, columns):
***************
*** 257,261 ****
 append(format_column(nodes))
 append("\n<p>\n")
! return string.join(strings, '')
 
 
--- 273,277 ----
 append(format_column(nodes))
 append("\n<p>\n")
! return null_join(strings)
 
 
***************
*** 266,276 ****
 lettername = "_ (underscore)"
 else:
! lettername = string.upper(letter)
 return "\n<hr>\n<h2><a name=\"letter-%s\">%s</a></h2>\n\n" \
 % (letter, lettername)
 
 
! def format_html_letters(nodes, columns=1):
 letter_groups = split_letters(nodes)
 items = []
 for letter, nodes in letter_groups:
--- 282,294 ----
 lettername = "_ (underscore)"
 else:
! lettername = letter.capitalize()
 return "\n<hr>\n<h2><a name=\"letter-%s\">%s</a></h2>\n\n" \
 % (letter, lettername)
 
 
! def format_html_letters(nodes, columns, group_symbol_nodes):
 letter_groups = split_letters(nodes)
+ if group_symbol_nodes:
+ group_symbols(letter_groups)
 items = []
 for letter, nodes in letter_groups:
***************
*** 281,285 ****
 s.append(format_letter(letter))
 s.append(format_nodes(nodes, columns))
! return string.join(s, '')
 
 def format_html(nodes, columns):
--- 299,303 ----
 s.append(format_letter(letter))
 s.append(format_nodes(nodes, columns))
! return null_join(s)
 
 def format_html(nodes, columns):
***************
*** 309,317 ****
 
 
! def process_nodes(nodes, columns, letters):
 nodes.sort()
 collapse(nodes)
 if letters:
! return format_html_letters(nodes, columns)
 else:
 return format_html(nodes, columns)
--- 327,335 ----
 
 
! def process_nodes(nodes, columns, letters=0, group_symbol_nodes=0):
 nodes.sort()
 collapse(nodes)
 if letters:
! return format_html_letters(nodes, columns, group_symbol_nodes)
 else:
 return format_html(nodes, columns)
***************
*** 324,336 ****
 columns = 1
 letters = 0
 opts, args = getopt.getopt(sys.argv[1:], "c:lo:",
! ["columns=", "letters", "output="])
 for opt, val in opts:
 if opt in ("-o", "--output"):
 ofn = val
 elif opt in ("-c", "--columns"):
! columns = string.atoi(val)
 elif opt in ("-l", "--letters"):
 letters = 1
 if not args:
 args = [ifn]
--- 342,360 ----
 columns = 1
 letters = 0
+ group_symbol_nodes = 1
 opts, args = getopt.getopt(sys.argv[1:], "c:lo:",
! ["columns=", "dont-group-symbols",
! "group-symbols", "letters", "output="])
 for opt, val in opts:
 if opt in ("-o", "--output"):
 ofn = val
 elif opt in ("-c", "--columns"):
! columns = int(val, 10)
 elif opt in ("-l", "--letters"):
 letters = 1
+ elif opt == "--group-symbols":
+ group_symbol_nodes = 1
+ elif opt == "--dont-group-symbols":
+ group_symbol_nodes = 0
 if not args:
 args = [ifn]
***************
*** 339,343 ****
 nodes = nodes + load(open(fn))
 num_nodes = len(nodes)
! html = process_nodes(nodes, columns, letters)
 program = os.path.basename(sys.argv[0])
 if ofn == "-":
--- 363,367 ----
 nodes = nodes + load(open(fn))
 num_nodes = len(nodes)
! html = process_nodes(nodes, columns, letters, group_symbol_nodes)
 program = os.path.basename(sys.argv[0])
 if ofn == "-":

AltStyle によって変換されたページ (->オリジナル) /