Show
Ignore:
Timestamp:
12/29/06 10:23:39 (2 years ago)
Author:
cneumann
Message:

- base templates to generate full set of access methods

for non-ptr mfields (including clear())
(full regeneration of base files in follow up commit)

- indented control statements in template files.
- do not screw up preformatted documentation from fcd files

in generated output.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Tools/fcd2code/FCDElement.py

    r425 r458  
    22import logging; 
    33import re; 
    4 import textwrap; 
    54 
    65class FCDElement(object): 
     
    9493        """Formats the description string. 
    9594        """ 
     95        indentStr   = " " * indent; 
    9696        paraList    = self._extractParagraphs(descText); 
    9797        paraListLen = len(paraList); 
    98         self.m_log.debug("paraList: %s", str(paraList)); 
    9998         
    100         # reformat the paragraphs 
    101         wrapper = textwrap.TextWrapper(); 
    102         wrapper.width             = 79 - indent; 
    103         wrapper.initial_indent    = " " * indent; 
    104         wrapper.subsequent_indent = " " * indent; 
    105         wrapper.break_long_words  = False; 
     99        for paraNum in range(paraListLen): 
     100            lineList    = paraList[paraNum].split("\n"); 
     101            lineListLen = len(lineList); 
     102             
     103            while lineListLen > 0 and lineList[0].strip() == "": 
     104                lineList     = lineList[1:]; 
     105                lineListLen -= 1; 
     106             
     107            while lineListLen > 0 and lineList[-1].strip() == "": 
     108                lineList     = lineList[0:-1]; 
     109                lineListLen -= 1; 
     110             
     111            for lineNum in range(lineListLen): 
     112                if paraNum > 0 or lineNum > 0: 
     113                    lineList[lineNum] = indentStr + lineList[lineNum]; 
     114             
     115            paraList[paraNum] = "\n".join(lineList); 
    106116         
    107         for paraNum, paraText in enumerate(paraList): 
    108             paraList[paraNum] = wrapper.fill(paraText); 
    109              
    110             if paraNum == 0: 
    111                 paraList[paraNum] = paraList[paraNum].lstrip(); 
    112          
    113         self.m_log.debug("paraList reformatted: %s", str(paraList)); 
    114117        return "\n\n".join(paraList); 
    115118     
     
    118121        """ 
    119122        indentStr   = " " * indent; 
    120         skipLines   = 0; 
    121123        lineList    = descText.split("\n"); 
    122124        lineListLen = len(lineList); 
    123         self.m_log.debug("lineList: %s", str(lineList)); 
     125         
     126        while lineListLen > 0 and lineList[0].strip() == "": 
     127            lineList     = lineList[1:]; 
     128            lineListLen -= 1; 
     129         
     130        while lineListLen > 0 and lineList[lineListLen-1].strip() == "": 
     131            lineList     = lineList[0:lineListLen-1]; 
     132            lineListLen -= 1; 
    124133         
    125134        for lineNum, lineText in enumerate(lineList): 
    126             if lineText.strip() == "": 
    127                 skipLines = skipLines + 1; 
    128                 continue; 
    129              
    130135            lineText = lineText.replace("\\",  "\\\\"); 
    131136            lineText = lineText.replace("\t",  "\\t"); 
     
    133138            lineText = lineText.replace("\"",  "\\\""); 
    134139             
    135             if lineNum - skipLines == 0: 
    136                 lineText = "\"" + lineText + "\\n\"\n"; 
     140            if lineNum == 0: 
     141                lineText =             "\"" + lineText + "\\n\""; 
    137142            else: 
    138                 lineText = indentStr + "\"" + lineText + "\\n\"\n"; 
     143                lineText = indentStr + "\"" + lineText + "\\n\""; 
    139144             
    140             lineList[lineNum - skipLines] = lineText; 
     145            if lineNum < lineListLen - 1: 
     146                lineText += "\n"; 
     147             
     148            lineList[lineNum] = lineText; 
    141149         
    142         lastLine = lineListLen - skipLines - 1; 
    143          
    144         if lineList[lastLine].endswith("\n"): 
    145             lineList[lastLine] = lineList[lastLine][:-1]; 
    146          
    147         self.m_log.debug("lineList reformatted: %s", str(lineList)); 
    148         return "".join(lineList[:(lineListLen - skipLines)]); 
     150        return "".join(lineList); 
    149151     
    150152    def _formatXML(self, lines, indent): 
    151153        """Formats the .fcd XML contents. 
    152154        """ 
    153         numLines  = len(lines); 
     155        linesLen  = len(lines); 
    154156        indentStr = " " * indent; 
    155157        output    = []; 
    156158         
    157         for i, line in enumerate(lines): 
     159        for lineNum, line in enumerate(lines): 
    158160            line = line.replace("\\",  "\\\\"); 
    159161            line = line.replace("\t",  "\\t"); 
     
    161163            line = line.replace("\"",  "\\\""); 
    162164             
    163             if i == 0: 
    164                 output.append("\"" + line + "\\n\""); 
     165            if lineNum == 0: 
     166                output.append(            "\"" + line + "\\n\""); 
    165167            else: 
    166168                output.append(indentStr + "\"" + line + "\\n\""); 
    167169             
    168             if i < numLines - 1: 
    169                 output[i] = output[i] + "\n"; 
     170            if lineNum < linesLen - 1: 
     171                output[lineNum] += "\n"; 
    170172         
    171173        return "".join(output); 
     
    174176        """Prints the contents of m_fcdDict and m_tmplDict to <log> 
    175177        """ 
    176         for key, value in self._getFCDDict().iteritems(): 
    177             log.info(key + " >" + str(value) + "<"); 
     178        sortFCDKeys = self._getFCDDict().keys(); 
     179        sortFCDKeys.sort(); 
     180        for key in sortFCDKeys: 
     181            log.info(key + " >" + str(self._getFCDDict()[key]) + "<"); 
    178182         
    179         for key, value in self._getTmplDict().iteritems(): 
    180             log.info("\t" + key + " >" + str(value) + "<"); 
     183        sortTmplKeys = self._getTmplDict().keys(); 
     184        sortTmplKeys.sort(); 
     185        for key in sortTmplKeys: 
     186            log.info("\t" + key + " >" + str(self._getTmplDict()[key]) + "<"); 
    181187