#!/usr/bin/python2.4 # Copyright 2009, Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following disclaimer # in the documentation and/or other materials provided with the # distribution. # * Neither the name of Google Inc. nor the names of its # contributors may be used to endorse or promote products derived from # this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """Creates unordered list of classes and packages.""" import os.path import re import sys # Special regular expressions for search and replace list_item_string = ('' '([a-zA-Z0-9\.]*)') LIST_ITEM = re.compile(list_item_string) def HyphenateWord(original_word, max_length, join_str='-'): """Breaks a word at max_length with hyphens. If the word is still too long (i.e., length > 2*max_length), the word will be split again. The word will be split at word breaks defined by a switch from lowercase to uppercase. The function will attempt to break at the closest switch before the max_length number of letters. If there is no upper case letter before the max_length, the original word will be returned. If max_length is 0 the original word will be returned. Args: original_word: the word to break. max_length: maximum length in chars for any piece of the word. join_str: characters to join the hyphenated parts with, defaults to '-' Returns: the hyphenated word. """ word_list = [] while len(original_word) > max_length: for i in range(max_length, -1, -1): if original_word[i].isupper(): word_list += [original_word[:i]] original_word = original_word[i:] break if i == 0: # There was no uppercase letter found so we don't break and just # return the original word return original_word word_list += [original_word] return join_str.join(word_list) def CreateListItems(input_html_file, max_length, html_directory): """Creates html for a list of items based on the input html file. Args: input_html_file: file to extract list items from. max_length: maximum length for sidebar entry. html_directory: relative html path for linked files. Returns: item_list: a list representing the new html. """ infile = open(input_html_file, 'r') lines_list = infile.readlines() infile.close() item_list = ['