3 import fileinput, string, sys
12 ''' Reads the layout.ini file into a global data structure - lay_tree
14 lay_p indicates the path to the layout file.
15 Returns False for error, True for success
19 f = open( lay_p,
"r" )
28 for lay_line
in layout.split(
"\n"):
30 lay_lcont = lay_line.strip()
31 if ( len( lay_lcont ) == 0 ):
34 if ( lay_lcont.startswith(
"#" ) ):
38 for char_itr
in lay_line:
39 if ( char_itr !=
" " ):
40 if ( char_itr !=
"\t" ):
44 if ( it_level >= crt_lev + 1 ):
46 it_level = crt_lev + 1
49 lay_tree.append([it_level,lay_lcont])
57 ''' get the text to be used as a link to the page
59 if ( page_name ==
"main" ):
60 ret_txt =
"\\ref index"
61 if ( len(link_text) != 0 ):
62 ret_txt +=
" \"" + link_text +
"\""
64 ret_txt +=
" \"Index\""
66 ret_txt =
"\\ref " + page_name
67 if ( len(link_text) != 0 ):
68 ret_txt +=
" \"" + link_text +
"\""
72 ''' updats dynamic data between the markers
74 The function reads the file and modified the content between the
77 print(
" Processing " + dox_file_p +
"..." )
80 f = open( dox_file_p,
"r" )
90 my_level = lay_tree[fileindex][0]
92 itr_max = len(lay_tree)
94 crt_level = lay_tree[i][0]
96 if (crt_level <= my_level):
98 if (crt_level == my_level+1):
99 new_cont +=
"- \\subpage " + lay_tree[i][1] +
"\n"
101 new_cont +=
"\t"*(crt_level-my_level-1)
102 new_cont +=
"- " +
pageLink(lay_tree[i][1],
"") +
"\n"
106 new_cont +=
"\n<TABLE width=\"100%\" border=\"0\"><TR>\n<TD>"
107 if ( fileindex != 0 ):
108 new_cont +=
pageLink(lay_tree[fileindex-1][1],
"Previous")
109 new_cont +=
"</TD>\n<TD width=\"100%\"></TD>\n<TD>"
110 if ( fileindex != itr_max-1 ):
111 new_cont +=
pageLink(lay_tree[fileindex+1][1],
"Next")
112 new_cont +=
"</TD>\n</TR></TABLE>\n"
117 idx_st = dox_cont.find(
"\\if MARKER_TREE_START" )
118 if ( idx_st == -1 ):
break
119 idx_st = dox_cont.find(
"\\endif", idx_st)
120 if ( idx_st == -1 ):
break
121 idx_st += len(
"\\endif" )
122 idx_end = dox_cont.find(
"\\if MARKER_TREE_END", idx_st )
123 if ( idx_end == -1 ):
break
126 if ( dox_cont[idx_st:idx_end] == new_cont ):
127 print(
" ... skipped" )
130 dox_cont = dox_cont[:idx_st] + new_cont + dox_cont[idx_end:]
133 f = open( dox_file_p,
"w" )
145 ''' Main function that is called when the module is loaded by itself
147 The function assumes that the documentation is in the same directory.
155 lay_tree.insert(0,[0,
"main"])
157 for itr_lay
in lay_tree:
163 if __name__ ==
"__main__":