Changeset 458 for trunk/Tools/fcd2code/FCDElement.py
- Timestamp:
- 12/29/06 10:23:39 (2 years ago)
- Files:
-
- trunk/Tools/fcd2code/FCDElement.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Tools/fcd2code/FCDElement.py
r425 r458 2 2 import logging; 3 3 import re; 4 import textwrap;5 4 6 5 class FCDElement(object): … … 94 93 """Formats the description string. 95 94 """ 95 indentStr = " " * indent; 96 96 paraList = self._extractParagraphs(descText); 97 97 paraListLen = len(paraList); 98 self.m_log.debug("paraList: %s", str(paraList));99 98 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); 106 116 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));114 117 return "\n\n".join(paraList); 115 118 … … 118 121 """ 119 122 indentStr = " " * indent; 120 skipLines = 0;121 123 lineList = descText.split("\n"); 122 124 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; 124 133 125 134 for lineNum, lineText in enumerate(lineList): 126 if lineText.strip() == "":127 skipLines = skipLines + 1;128 continue;129 130 135 lineText = lineText.replace("\\", "\\\\"); 131 136 lineText = lineText.replace("\t", "\\t"); … … 133 138 lineText = lineText.replace("\"", "\\\""); 134 139 135 if lineNum - skipLines== 0:136 lineText = "\"" + lineText + "\\n\"\n";140 if lineNum == 0: 141 lineText = "\"" + lineText + "\\n\""; 137 142 else: 138 lineText = indentStr + "\"" + lineText + "\\n\" \n";143 lineText = indentStr + "\"" + lineText + "\\n\""; 139 144 140 lineList[lineNum - skipLines] = lineText; 145 if lineNum < lineListLen - 1: 146 lineText += "\n"; 147 148 lineList[lineNum] = lineText; 141 149 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); 149 151 150 152 def _formatXML(self, lines, indent): 151 153 """Formats the .fcd XML contents. 152 154 """ 153 numLines= len(lines);155 linesLen = len(lines); 154 156 indentStr = " " * indent; 155 157 output = []; 156 158 157 for i, line in enumerate(lines):159 for lineNum, line in enumerate(lines): 158 160 line = line.replace("\\", "\\\\"); 159 161 line = line.replace("\t", "\\t"); … … 161 163 line = line.replace("\"", "\\\""); 162 164 163 if i== 0:164 output.append( "\"" + line + "\\n\"");165 if lineNum == 0: 166 output.append( "\"" + line + "\\n\""); 165 167 else: 166 168 output.append(indentStr + "\"" + line + "\\n\""); 167 169 168 if i < numLines- 1:169 output[ i] = output[i] +"\n";170 if lineNum < linesLen - 1: 171 output[lineNum] += "\n"; 170 172 171 173 return "".join(output); … … 174 176 """Prints the contents of m_fcdDict and m_tmplDict to <log> 175 177 """ 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]) + "<"); 178 182 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]) + "<"); 181 187
