| 1 | |
|---|
| 2 | __author__ = "Alexander Behrens (behrens@lfb.rwth-aachen.de), Linus Atorf" |
|---|
| 3 | __version__ = "$Revision: 0.2 $" |
|---|
| 4 | __date__ = "$Date: 2008/10/25$" |
|---|
| 5 | __copyright__ = "Copyright (c) 2008 Alexander Behrens, Linus Atorf" |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | import os |
|---|
| 9 | import sys |
|---|
| 10 | import glob |
|---|
| 11 | import shutil |
|---|
| 12 | |
|---|
| 13 | def publish_toolbox_mfiles(wg_publish_dir, input_dir, output_dir): |
|---|
| 14 | # start wg_publish_dir to create the html files from the toolbox mfiles |
|---|
| 15 | print |
|---|
| 16 | print "--------------------------------------------------------------" |
|---|
| 17 | print "Start MATLAB and publish_mfiles (wg_publish) to create html files..." |
|---|
| 18 | #message = []; |
|---|
| 19 | #message.append('matlab -nosplash -r') |
|---|
| 20 | #message.append(' "publish_mfiles(') |
|---|
| 21 | #message.append("'") |
|---|
| 22 | #message.append(wg_publish_dir) |
|---|
| 23 | #message.append("', '") |
|---|
| 24 | #message.append(input_dir) |
|---|
| 25 | #message.append("', '") |
|---|
| 26 | #message.append(output_dir) |
|---|
| 27 | #message.append("'") |
|---|
| 28 | #message.append('); exit;"') |
|---|
| 29 | #message = ''.join(message) |
|---|
| 30 | #print message |
|---|
| 31 | #os.system(message) |
|---|
| 32 | os.system(''.join(('matlab -automation -wait -r "cd(\'', os.getcwd(), '\'); publish_mfiles(); exit;"'))) |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | def remove_styles(output_dir, depth, files): |
|---|
| 36 | # usage: |
|---|
| 37 | # python remove_sytles.py [output_dir] [html files (*.html)] |
|---|
| 38 | # |
|---|
| 39 | print |
|---|
| 40 | print "--------------------------------------------------------------" |
|---|
| 41 | print "Remove styles sheets from the html files..." |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | # for each html-file do... |
|---|
| 45 | for i in files: |
|---|
| 46 | |
|---|
| 47 | # set output file name |
|---|
| 48 | (filepath, filename) = os.path.split(i) |
|---|
| 49 | output_name = os.path.join(output_dir, filename) |
|---|
| 50 | |
|---|
| 51 | file1 = file(i,"r") |
|---|
| 52 | file2 = file(output_name,"w") |
|---|
| 53 | |
|---|
| 54 | print "Processing file: %s ..." % filename |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | # read original file |
|---|
| 58 | org_lines = file1.read().split("\n") |
|---|
| 59 | new_lines = [] |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | # flags |
|---|
| 63 | key = True |
|---|
| 64 | style_start = False |
|---|
| 65 | style_end = False |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | for line in org_lines: |
|---|
| 69 | |
|---|
| 70 | s = line.find("<style>") |
|---|
| 71 | |
|---|
| 72 | if s != -1: |
|---|
| 73 | style_start = True |
|---|
| 74 | # add text before and after "<style>" |
|---|
| 75 | new_lines.append(line[0:s] + line[s+7:]) |
|---|
| 76 | # add style sheet link |
|---|
| 77 | if depth == 2: |
|---|
| 78 | new_lines.append('<link type="text/css" rel="stylesheet" href="../../style.css">') |
|---|
| 79 | elif depth == 1: |
|---|
| 80 | new_lines.append('<link type="text/css" rel="stylesheet" href="../style.css">') |
|---|
| 81 | continue |
|---|
| 82 | |
|---|
| 83 | s = line.find("</style>") |
|---|
| 84 | if s != -1: |
|---|
| 85 | style_end = True |
|---|
| 86 | # add text before and after "</style>" |
|---|
| 87 | new_lines.append(line[0:s] + line[s+8:]) |
|---|
| 88 | continue |
|---|
| 89 | |
|---|
| 90 | if style_start == True and style_end == False: |
|---|
| 91 | #skip |
|---|
| 92 | continue |
|---|
| 93 | |
|---|
| 94 | if style_start == False or style_end == True: |
|---|
| 95 | if line.find("<body>") != -1: |
|---|
| 96 | new_lines.append(line) |
|---|
| 97 | # add header banner |
|---|
| 98 | new_lines.append('<p class="header">RWTH - Mindstorms NXT Toolbox</p>') |
|---|
| 99 | |
|---|
| 100 | else: |
|---|
| 101 | new_lines.append(line) |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | # write new lines to output file |
|---|
| 105 | file2.write("\n".join(new_lines)) |
|---|
| 106 | |
|---|
| 107 | file1.close() |
|---|
| 108 | file2.close() |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | def remove_formats(output_dir, m_files): |
|---|
| 113 | # usage: |
|---|
| 114 | # python remove_formats.py output_dir *.m |
|---|
| 115 | # remove ; and || and %+ formats in the header description of each m-file |
|---|
| 116 | |
|---|
| 117 | print |
|---|
| 118 | print "--------------------------------------------------------------" |
|---|
| 119 | print "Remove formats from the m-files..." |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | # for each m-file do... |
|---|
| 123 | for i in m_files: |
|---|
| 124 | |
|---|
| 125 | # set output file name |
|---|
| 126 | (filepath, filename) = os.path.split(i) |
|---|
| 127 | output_name = os.path.join(output_dir, filename) |
|---|
| 128 | |
|---|
| 129 | file1 = file(i,"r") |
|---|
| 130 | file2 = file(output_name,"w") |
|---|
| 131 | |
|---|
| 132 | print "Processing file: %s ..." % filename |
|---|
| 133 | |
|---|
| 134 | # read original file |
|---|
| 135 | org_lines = file1.read().split("\n") |
|---|
| 136 | new_lines = [] |
|---|
| 137 | |
|---|
| 138 | # flags |
|---|
| 139 | key = True |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | # for each line do... |
|---|
| 143 | for line in org_lines: |
|---|
| 144 | |
|---|
| 145 | # check if line is empty |
|---|
| 146 | if line.strip() != "": |
|---|
| 147 | |
|---|
| 148 | # check is ";" is occured |
|---|
| 149 | if line.strip()[0] == ";": |
|---|
| 150 | key = False |
|---|
| 151 | # new_lines.append("") (not necessary since m2html is obsolete) |
|---|
| 152 | continue |
|---|
| 153 | |
|---|
| 154 | # remove | characters from %-lines |
|---|
| 155 | if line.strip()[0] == '%' and key == True: |
|---|
| 156 | line_cut = line.replace("|","") |
|---|
| 157 | |
|---|
| 158 | # replace %+ with % |
|---|
| 159 | if len(line.strip()) > 1: |
|---|
| 160 | if line_cut.strip()[1] == '+': |
|---|
| 161 | line_cut = '%' + line_cut.strip()[2:] |
|---|
| 162 | |
|---|
| 163 | new_lines.append(line_cut) |
|---|
| 164 | # new_lines.append(line.replace("|","")) |
|---|
| 165 | |
|---|
| 166 | else: |
|---|
| 167 | new_lines.append(line) |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | else: |
|---|
| 171 | new_lines.append(line) |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | # write new lines to output file |
|---|
| 175 | file2.write("\n".join(new_lines)) |
|---|
| 176 | |
|---|
| 177 | file1.close() |
|---|
| 178 | file2.close() |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | def createABCList(content_file, output_dir): |
|---|
| 182 | # create abc list of mfiles |
|---|
| 183 | print |
|---|
| 184 | print "--------------------------------------------------------------" |
|---|
| 185 | print "Create ABC list of m files..." |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | # set input and output files |
|---|
| 189 | file1 = file(content_file, "r") |
|---|
| 190 | file2 = file(os.path.join(output_dir, "abc.html"), "w") |
|---|
| 191 | |
|---|
| 192 | print "Create Alphabetical List of file: %s ..." % content_file |
|---|
| 193 | |
|---|
| 194 | # read original file |
|---|
| 195 | org_lines = file1.read().split("\n") |
|---|
| 196 | new_lines = [] |
|---|
| 197 | |
|---|
| 198 | # add html header |
|---|
| 199 | new_lines.append('<html>') |
|---|
| 200 | new_lines.append('<head>') |
|---|
| 201 | new_lines.append('<title>Functions - Alphabetical List</title>') |
|---|
| 202 | new_lines.append('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">') |
|---|
| 203 | new_lines.append('<link type="text/css" rel="stylesheet" href="../style.css">') |
|---|
| 204 | new_lines.append('</head>') |
|---|
| 205 | new_lines.append('') |
|---|
| 206 | new_lines.append('<body bgcolor="#FFFFFF" text="#000001">') |
|---|
| 207 | new_lines.append('<p class="header">RWTH - Mindstorms NXT Toolbox</p>') |
|---|
| 208 | new_lines.append('<p align="center">') |
|---|
| 209 | new_lines.append('<h1>Functions - Alphabetical List</h1>') |
|---|
| 210 | new_lines.append('</p>') |
|---|
| 211 | new_lines.append('') |
|---|
| 212 | new_lines.append('<table>') |
|---|
| 213 | |
|---|
| 214 | i = 0 |
|---|
| 215 | |
|---|
| 216 | for line in org_lines: |
|---|
| 217 | i = i + 1 |
|---|
| 218 | |
|---|
| 219 | if (i > 3) & (len(line) > 0): |
|---|
| 220 | |
|---|
| 221 | words = line.lstrip("%").strip().split("-",1) |
|---|
| 222 | |
|---|
| 223 | if len(words) >= 2: |
|---|
| 224 | command = words[0].strip() |
|---|
| 225 | description = words[1].strip() |
|---|
| 226 | words = [command, description] |
|---|
| 227 | |
|---|
| 228 | #print words |
|---|
| 229 | newline = '<tr><td><a href="./help/' + command + '.html">' + command + '</a></td><td>' + description + '</td></tr>' |
|---|
| 230 | new_lines.append(newline) |
|---|
| 231 | |
|---|
| 232 | |
|---|
| 233 | |
|---|
| 234 | # add html footer |
|---|
| 235 | new_lines.append('</table>') |
|---|
| 236 | new_lines.append('') |
|---|
| 237 | new_lines.append('</body>') |
|---|
| 238 | new_lines.append('</html>') |
|---|
| 239 | |
|---|
| 240 | # writ e new lines to output file |
|---|
| 241 | file2.write("\n".join(new_lines)) |
|---|
| 242 | |
|---|
| 243 | # close files |
|---|
| 244 | file1.close() |
|---|
| 245 | file2.close() |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | def createCategories(content_file, output_dir): |
|---|
| 249 | # create category list of mfiles |
|---|
| 250 | print |
|---|
| 251 | print "--------------------------------------------------------------" |
|---|
| 252 | print "Create category list of m files..." |
|---|
| 253 | |
|---|
| 254 | |
|---|
| 255 | # set input and output files |
|---|
| 256 | file1 = file(content_file, "r") |
|---|
| 257 | file2 = file(os.path.join(output_dir, "categories.html"), "w") |
|---|
| 258 | |
|---|
| 259 | print "Create Category List of file: %s ..." % content_file |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | # read original file |
|---|
| 263 | org_lines = file1.read().split("\n") |
|---|
| 264 | new_lines = [] |
|---|
| 265 | |
|---|
| 266 | # add html header |
|---|
| 267 | new_lines.append('<html>') |
|---|
| 268 | new_lines.append('<head>') |
|---|
| 269 | new_lines.append('<title>Functions by Category</title>') |
|---|
| 270 | new_lines.append('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">') |
|---|
| 271 | new_lines.append('<link type="text/css" rel="stylesheet" href="../style.css">') |
|---|
| 272 | new_lines.append('</head>') |
|---|
| 273 | new_lines.append('') |
|---|
| 274 | new_lines.append('<body bgcolor="#FFFFFF" text="#000001">') |
|---|
| 275 | new_lines.append('<p class="header">RWTH - Mindstorms NXT Toolbox</p>') |
|---|
| 276 | new_lines.append('<p align="center">') |
|---|
| 277 | new_lines.append('<h1>Functions by Category</h1>') |
|---|
| 278 | new_lines.append('</p>') |
|---|
| 279 | new_lines.append('') |
|---|
| 280 | new_lines.append('<table>') |
|---|
| 281 | |
|---|
| 282 | i = 0 |
|---|
| 283 | |
|---|
| 284 | COM_Functions = [] |
|---|
| 285 | NXT_Functions = [] |
|---|
| 286 | MAP_Functions = [] |
|---|
| 287 | General_Functions = [] |
|---|
| 288 | General = ["OptimizeToolboxPerformance"] |
|---|
| 289 | |
|---|
| 290 | Sensor_Functions = [] |
|---|
| 291 | Sensors = ["SENSOR_1", "SENSOR_2", "SENSOR_3", "SENSOR_4", "OpenLight", "OpenSound", "OpenSwitch", "OpenUltrasonic", "CloseSensor", "GetLight", "GetSound", "GetSwitch", "GetUltrasonic", "USGetSnapshotResults", "USMakeSnapshot", "OpenAccelerator", "GetAccelerator", "OpenInfrared", "GetInfrared", "OpenCompass", "GetCompass", "CalibrateCompass"] |
|---|
| 292 | Motor_Functions = [] |
|---|
| 293 | Motors = ["GetMotor", "GetMotorSettings", "SetAngleLimit", "SetMotor", "SetPower", "SetRampMode", "SetTurnRatio", "SyncToMotor", "SpeedRegulation", "SendMotorSettings", "WaitForMotor", "StopMotor", "ResetMotorAngle", "SwitchLamp", "MOTOR_A", "MOTOR_B", "MOTOR_C", "MotorRotateAbs", "GetMemoryCount", "SetMemoryCount"] |
|---|
| 294 | Debug_Functions = [] |
|---|
| 295 | Debug = ["DebugMode"] |
|---|
| 296 | |
|---|
| 297 | for line in org_lines: |
|---|
| 298 | i = i + 1 |
|---|
| 299 | |
|---|
| 300 | if (i > 3) & (len(line) > 0): |
|---|
| 301 | |
|---|
| 302 | words = line.lstrip("%").strip().split("-",1) |
|---|
| 303 | |
|---|
| 304 | if len(words) == 2: |
|---|
| 305 | command = words[0].strip() |
|---|
| 306 | description = words[1].strip() |
|---|
| 307 | words = [command, description] |
|---|
| 308 | |
|---|
| 309 | #print command[0].islower() |
|---|
| 310 | if command.find("COM") == 0: |
|---|
| 311 | COM_Functions.append(words) |
|---|
| 312 | |
|---|
| 313 | elif command.find("NXT") == 0: |
|---|
| 314 | NXT_Functions.append(words) |
|---|
| 315 | |
|---|
| 316 | elif command.find("MAP") == 0: |
|---|
| 317 | MAP_Functions.append(words) |
|---|
| 318 | |
|---|
| 319 | elif command[0].islower() or command in General: |
|---|
| 320 | General_Functions.append(words) |
|---|
| 321 | |
|---|
| 322 | elif command in Sensors: |
|---|
| 323 | Sensor_Functions.append(words) |
|---|
| 324 | |
|---|
| 325 | elif command in Motors: |
|---|
| 326 | Motor_Functions.append(words) |
|---|
| 327 | |
|---|
| 328 | elif command in Debug: |
|---|
| 329 | Debug_Functions.append(words) |
|---|
| 330 | |
|---|
| 331 | else: |
|---|
| 332 | print command |
|---|
| 333 | sys.stderr.write('Error, command can not be categorized\n') |
|---|
| 334 | sys.exit() |
|---|
| 335 | |
|---|
| 336 | categories = [[COM_Functions, 'NXT Communication'], [Sensor_Functions, 'NXT Sensors'], [Motor_Functions, 'NXT Motors'], [NXT_Functions, 'Direct NXT Functions'], [MAP_Functions, 'NXT Module Map Functions'], [General_Functions, 'General Functions'], [Debug_Functions, 'Debug Functions']] |
|---|
| 337 | |
|---|
| 338 | |
|---|
| 339 | for item in categories: |
|---|
| 340 | newline = '<tr><td colspan="2"><h2>' + item[1] + '</h2></td></tr>' |
|---|
| 341 | new_lines.append(newline) |
|---|
| 342 | for words in item[0]: |
|---|
| 343 | command = words[0] |
|---|
| 344 | description = words[1] |
|---|
| 345 | newline = '<tr><td><a href="./help/' + command + '.html">' + command + '</a></td><td>' + description + '</td></tr>' |
|---|
| 346 | new_lines.append(newline) |
|---|
| 347 | newline = '<tr><td><br><br></td></tr>' |
|---|
| 348 | new_lines.append(newline) |
|---|
| 349 | new_lines.append('') |
|---|
| 350 | new_lines.append('') |
|---|
| 351 | |
|---|
| 352 | |
|---|
| 353 | # add html footer |
|---|
| 354 | new_lines.append('</table>') |
|---|
| 355 | new_lines.append('') |
|---|
| 356 | new_lines.append('</body>') |
|---|
| 357 | new_lines.append('</html>') |
|---|
| 358 | |
|---|
| 359 | # write new lines to output file |
|---|
| 360 | file2.write("\n".join(new_lines)) |
|---|
| 361 | |
|---|
| 362 | # close files |
|---|
| 363 | file1.close() |
|---|
| 364 | file2.close() |
|---|
| 365 | |
|---|
| 366 | |
|---|
| 367 | |
|---|
| 368 | |
|---|
| 369 | def publish_m2html_files(output_dir, input_dir, m_files): |
|---|
| 370 | # create html from m-files in /doc/m2html/ --> doc/functions/ (e.g. Functions Overview etc.) |
|---|
| 371 | print |
|---|
| 372 | print "--------------------------------------------------------------" |
|---|
| 373 | print "Create html files from /doc/m2html/*.m files..." |
|---|
| 374 | #message = "" |
|---|
| 375 | #message.append('matlab -automation -wait -r "cd(') |
|---|
| 376 | #message.append("'") |
|---|
| 377 | #message.append(os.getcwd()) |
|---|
| 378 | #message.append("');") |
|---|
| 379 | #message.append(' publish_mfiles2html(') |
|---|
| 380 | #message.append("'") |
|---|
| 381 | #message.append(output_dir) |
|---|
| 382 | #message.append("', '") |
|---|
| 383 | #message.append(input_dir) |
|---|
| 384 | #message.append("'") |
|---|
| 385 | #for file in m_files: |
|---|
| 386 | # message.append(", '") |
|---|
| 387 | # message.append(file) |
|---|
| 388 | # message.append("'") |
|---|
| 389 | #message.append('); exit;"') |
|---|
| 390 | #message = ''.join(message) |
|---|
| 391 | message = 'matlab -automation -wait -r "cd(' + "'" + "%s'); publish_mfiles2html('%s', '%s', '" % (os.getcwd(), output_dir, input_dir) |
|---|
| 392 | message = message + "', '".join(m_files) + "'); " + 'exit;"' |
|---|
| 393 | |
|---|
| 394 | print message |
|---|
| 395 | os.system(message) |
|---|
| 396 | #('matlab -automation -wait -r "cd(\'', os.getcwd(), '\') |
|---|
| 397 | #os.sytem('matlab -nosplash -r "publish_mfile2html(%s, %s); exit;"' % test) |
|---|
| 398 | |
|---|
| 399 | |
|---|
| 400 | |
|---|
| 401 | # # ############################# |
|---|
| 402 | # remove style sheets from the html files and add header banner |
|---|
| 403 | #echo |
|---|
| 404 | #echo "--------------------------------------------------------------" |
|---|
| 405 | #echo "Remove styles sheets from the html files..." |
|---|
| 406 | #mkdir $output_dir/doc/programming |
|---|
| 407 | #python remove_styles2.py $output_dir/doc/programming $doc_dir/m2html/out/*.html# |
|---|
| 408 | # |
|---|
| 409 | #rm -Rf $doc_dir/m2html/out |
|---|
| 410 | |
|---|
| 411 | |
|---|
| 412 | # ############################## |
|---|
| 413 | |
|---|
| 414 | def createExamples(output_dir, m_files): |
|---|
| 415 | # create abc list of mfiles |
|---|
| 416 | print |
|---|
| 417 | print "--------------------------------------------------------------" |
|---|
| 418 | print "Create Examples list of demo files..." |
|---|
| 419 | |
|---|
| 420 | |
|---|
| 421 | |
|---|
| 422 | file2 = file(os.path.join(output_dir, "examples.html"), "w") |
|---|
| 423 | |
|---|
| 424 | new_lines = [] |
|---|
| 425 | |
|---|
| 426 | # add html header |
|---|
| 427 | new_lines.append('<html>') |
|---|
| 428 | new_lines.append('<head>') |
|---|
| 429 | new_lines.append('<title>Examples</title>') |
|---|
| 430 | new_lines.append('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">') |
|---|
| 431 | new_lines.append('<link type="text/css" rel="stylesheet" href="../style.css">') |
|---|
| 432 | new_lines.append('</head>') |
|---|
| 433 | new_lines.append('') |
|---|
| 434 | new_lines.append('<body bgcolor="#FFFFFF" text="#000001">') |
|---|
| 435 | new_lines.append('<p class="header">RWTH - Mindstorms NXT Toolbox</p>') |
|---|
| 436 | new_lines.append('<p align="center">') |
|---|
| 437 | new_lines.append('<h1>Examples</h1>') |
|---|
| 438 | new_lines.append('</p>') |
|---|
| 439 | new_lines.append('') |
|---|
| 440 | new_lines.append('<ul>') |
|---|
| 441 | |
|---|
| 442 | |
|---|
| 443 | for input_name in m_files: |
|---|
| 444 | name = os.path.basename(input_name) |
|---|
| 445 | |
|---|
| 446 | if name.count('GUI') < 1: |
|---|
| 447 | file1 = file(input_name, "r") |
|---|
| 448 | org_line = file1.readline() |
|---|
| 449 | org_line = file1.readline() |
|---|
| 450 | |
|---|
| 451 | new_lines.append('<li>' + '<a href="'+ name.rstrip('m').rstrip('.') + '.html' + '">' + name + ' : ' + org_line.lstrip('%') + '</a>' + '</li>') |
|---|
| 452 | new_lines.append('</br>') |
|---|
| 453 | |
|---|
| 454 | # close file |
|---|
| 455 | file1.close() |
|---|
| 456 | |
|---|
| 457 | new_lines.append('</ul>') |
|---|
| 458 | |
|---|
| 459 | new_lines.append('') |
|---|
| 460 | new_lines.append('</body>') |
|---|
| 461 | new_lines.append('</html>') |
|---|
| 462 | |
|---|
| 463 | # write new lines to output file |
|---|
| 464 | file2.write("\n".join(new_lines)) |
|---|
| 465 | |
|---|
| 466 | # close file |
|---|
| 467 | file2.close() |
|---|
| 468 | |
|---|
| 469 | |
|---|
| 470 | def createHelpIndex(output_dir, html_files): |
|---|
| 471 | # create help index of html files |
|---|
| 472 | print |
|---|
| 473 | print "--------------------------------------------------------------" |
|---|
| 474 | print "Create Help Index of html files..." |
|---|
| 475 | |
|---|
| 476 | |
|---|
| 477 | # output file |
|---|
| 478 | file2 = file(os.path.join(output_dir, "helpindex.xml"), "w") |
|---|
| 479 | |
|---|
| 480 | new_lines = [] |
|---|
| 481 | |
|---|
| 482 | # add xml header |
|---|
| 483 | new_lines.append("<?xml version='1.0' encoding='ISO-8859-1' ?>") |
|---|
| 484 | new_lines.append('') |
|---|
| 485 | new_lines.append('') |
|---|
| 486 | new_lines.append('<index version="1.0">') |
|---|
| 487 | |
|---|
| 488 | |
|---|
| 489 | for input_name in html_files: |
|---|
| 490 | name = os.path.basename(input_name) |
|---|
| 491 | |
|---|
| 492 | new_lines.append('<indexitem target="./functions/help/' + name + '">' + name.rstrip("html").rstrip(".") + '</indexitem>') |
|---|
| 493 | |
|---|
| 494 | |
|---|
| 495 | new_lines.append('</index>') |
|---|
| 496 | |
|---|
| 497 | # write new lines to output file |
|---|
| 498 | file2.write("\n".join(new_lines)) |
|---|
| 499 | |
|---|
| 500 | # close file |
|---|
| 501 | file2.close() |
|---|
| 502 | |
|---|
| 503 | def copyRecursive(input_dir, output_dir): |
|---|
| 504 | # |
|---|
| 505 | # get list |
|---|
| 506 | list = os.listdir(input_dir) |
|---|
| 507 | print list |
|---|
| 508 | for element in list: |
|---|
| 509 | # if element does not contain a '.' at the beginning |
|---|
| 510 | if element[0] != '.': |
|---|
| 511 | |
|---|
| 512 | if os.path.isdir(os.path.join(input_dir, element)): |
|---|
| 513 | try: |
|---|
| 514 | os.mkdir(os.path.join(output_dir, element)) |
|---|
| 515 | print "create directory: %s" % element |
|---|
| 516 | except OSError: |
|---|
| 517 | print "can't create directory: %s , exist already?" % element |
|---|
| 518 | copyRecursive(os.path.join(input_dir, element), os.path.join(output_dir, element)) |
|---|
| 519 | elif os.path.isfile(os.path.join(input_dir, element)): |
|---|
| 520 | shutil.copy(os.path.join(input_dir, element), output_dir) |
|---|
| 521 | # mache |
|---|
| 522 | |
|---|
| 523 | |
|---|
| 524 | # directory structure |
|---|
| 525 | |
|---|
| 526 | # /output |
|---|
| 527 | # /doc |
|---|
| 528 | # /functions |
|---|
| 529 | # /help |
|---|
| 530 | |
|---|
| 531 | if __name__ == "__main__": |
|---|
| 532 | |
|---|
| 533 | # set parameter / paths |
|---|
| 534 | |
|---|
| 535 | mfiles_dir = os.path.join(os.getcwd(), "..", "..", "mfiles") |
|---|
| 536 | doc_dir = os.path.join(os.getcwd(), "..", "..", "doc") |
|---|
| 537 | doc_html_dir = os.path.join(os.getcwd(), "..", "..", "doc", "html") |
|---|
| 538 | doc_m2html_dir = os.path.join(os.getcwd(), "..", "..", "doc", "m2html") |
|---|
| 539 | demos_dir = os.path.join(os.getcwd(), "..", "..", "demos") |
|---|
| 540 | tools_dir = os.path.join(os.getcwd(), "..", "..", "tools") |
|---|
| 541 | root_dir = os.path.join(os.getcwd(), "..", "..", "root") |
|---|
| 542 | |
|---|
| 543 | wg_publish_dir = os.path.join(os.getcwd(), "..", "tools", "3rdParties", "wg_publish") |
|---|
| 544 | |
|---|
| 545 | |
|---|
| 546 | output_dir = os.path.join(os.getcwd(), "..", "output") |
|---|
| 547 | |
|---|
| 548 | out_private_dir = os.path.join(output_dir, "private") |
|---|
| 549 | out_demos_dir = os.path.join(output_dir, "demos") |
|---|
| 550 | out_tools_dir = os.path.join(output_dir, "tools") |
|---|
| 551 | |
|---|
| 552 | out_doc_dir = os.path.join(output_dir, "doc") |
|---|
| 553 | out_doc_examples_dir = os.path.join(output_dir, "doc", "examples") |
|---|
| 554 | out_doc_programming_dir = os.path.join(output_dir, "doc", "programming") |
|---|
| 555 | out_doc_tools_dir = os.path.join(output_dir, "doc", "tools") |
|---|
| 556 | out_doc_functions_dir = os.path.join(output_dir, "doc", "functions") |
|---|
| 557 | out_doc_functions_help_dir = os.path.join(output_dir, "doc", "functions", "help") |
|---|
| 558 | |
|---|
| 559 | out_tmp = os.path.join(output_dir, "tmp") |
|---|
| 560 | out_tmp_mfileshtml = os.path.join(output_dir, "tmp", "mfileshtml") |
|---|
| 561 | out_tmp_m2html = os.path.join(output_dir, "tmp", "m2html") |
|---|
| 562 | out_tmp_examples = os.path.join(output_dir, "tmp", "examples") |
|---|
| 563 | out_tmp_tools = os.path.join(output_dir, "tmp", "tools") |
|---|
| 564 | |
|---|
| 565 | |
|---|
| 566 | dir_list = [out_private_dir, out_demos_dir, out_tools_dir, |
|---|
| 567 | out_doc_dir, out_doc_examples_dir, out_doc_programming_dir, out_doc_tools_dir, |
|---|
| 568 | out_doc_functions_dir, out_doc_functions_help_dir, |
|---|
| 569 | out_tmp, out_tmp_mfileshtml, out_tmp_m2html, out_tmp_examples, out_tmp_tools |
|---|
| 570 | ] |
|---|
| 571 | |
|---|
| 572 | |
|---|
| 573 | # create directories |
|---|
| 574 | for directory in dir_list: |
|---|
| 575 | try: |
|---|
| 576 | os.mkdir(directory) |
|---|
| 577 | print "create directory: %s" % directory |
|---|
| 578 | except OSError: |
|---|
| 579 | print "can't create directory: %s , exist already?" % directory |
|---|
| 580 | |
|---|
| 581 | |
|---|
| 582 | |
|---|
| 583 | |
|---|
| 584 | # copy doc/html dircetory (recursive) |
|---|
| 585 | copyRecursive(doc_html_dir, out_doc_dir) |
|---|
| 586 | |
|---|
| 587 | |
|---|
| 588 | |
|---|
| 589 | # copy doc directory |
|---|
| 590 | files = glob.glob(os.path.join(doc_dir, "*.*")) |
|---|
| 591 | for in_file in files: |
|---|
| 592 | shutil.copy(in_file, out_doc_dir) |
|---|
| 593 | |
|---|
| 594 | |
|---|
| 595 | |
|---|
| 596 | # copy root directory |
|---|
| 597 | files = glob.glob(os.path.join(root_dir, "*")) |
|---|
| 598 | for in_file in files: |
|---|
| 599 | shutil.copy(in_file, output_dir) |
|---|
| 600 | |
|---|
| 601 | |
|---|
| 602 | |
|---|
| 603 | # publish toolbox mfiles |
|---|
| 604 | # TODO: Funktionsuebergabe nach MATLAB funktioniert nicht wirklich |
|---|
| 605 | publish_toolbox_mfiles(wg_publish_dir, mfiles_dir, out_tmp_mfileshtml) |
|---|
| 606 | |
|---|
| 607 | |
|---|
| 608 | |
|---|
| 609 | # remove_styles of html files of m-files |
|---|
| 610 | files = glob.glob(os.path.join(out_tmp_mfileshtml, "*.html")) |
|---|
| 611 | remove_styles(out_doc_functions_help_dir, 2, files) |
|---|
| 612 | |
|---|
| 613 | |
|---|
| 614 | |
|---|
| 615 | # remove_formats of m-files (also copy) |
|---|
| 616 | files1 = glob.glob(os.path.join(mfiles_dir, "*.m*")) |
|---|
| 617 | files2 = glob.glob(os.path.join(mfiles_dir, "private", "*.m*")) |
|---|
| 618 | remove_formats(output_dir, files1) |
|---|
| 619 | remove_formats(out_private_dir, files2) |
|---|
| 620 | |
|---|
| 621 | |
|---|
| 622 | |
|---|
| 623 | # create ABC list & create Category List |
|---|
| 624 | in_file = os.path.join(mfiles_dir, "Contents.m") |
|---|
| 625 | createABCList(in_file, out_doc_functions_dir) |
|---|
| 626 | createCategories(in_file, out_doc_functions_dir) |
|---|
| 627 | |
|---|
| 628 | |
|---|
| 629 | |
|---|
| 630 | # create Help Index files |
|---|
| 631 | files = glob.glob(os.path.join(out_doc_functions_help_dir, "*.html")) |
|---|
| 632 | createHelpIndex(out_doc_dir, files) |
|---|
| 633 | |
|---|
| 634 | |
|---|
| 635 | |
|---|
| 636 | # publish m2html files |
|---|
| 637 | files = glob.glob(os.path.join(doc_m2html_dir, "*.m")) |
|---|
| 638 | filenames = [] |
|---|
| 639 | for in_file in files: |
|---|
| 640 | (filepath, filename) = os.path.split(in_file) |
|---|
| 641 | filenames.append(filename) |
|---|
| 642 | publish_m2html_files(out_tmp_m2html, doc_m2html_dir, filenames) |
|---|
| 643 | |
|---|
| 644 | # remove styles |
|---|
| 645 | files = glob.glob(os.path.join(out_tmp_m2html, "*.html")) |
|---|
| 646 | remove_styles(out_doc_programming_dir, 1, files) |
|---|
| 647 | |
|---|
| 648 | |
|---|
| 649 | |
|---|
| 650 | # publish demos |
|---|
| 651 | files = glob.glob(os.path.join(demos_dir, "*.m")) |
|---|
| 652 | filenames = [] |
|---|
| 653 | for in_file in files: |
|---|
| 654 | (filepath, filename) = os.path.split(in_file) |
|---|
| 655 | filenames.append(filename) |
|---|
| 656 | publish_m2html_files(out_tmp_examples, demos_dir, filenames) |
|---|
| 657 | |
|---|
| 658 | # remove styles |
|---|
| 659 | files = glob.glob(os.path.join(out_tmp_examples, "*.html")) |
|---|
| 660 | remove_styles(out_doc_examples_dir, 1, files) |
|---|
| 661 | |
|---|
| 662 | # create example index |
|---|
| 663 | files = glob.glob(os.path.join(demos_dir, "*.m")) |
|---|
| 664 | createExamples(out_doc_examples_dir, files) |
|---|
| 665 | |
|---|
| 666 | # copy demos directory |
|---|
| 667 | print |
|---|
| 668 | print "--------------------------------------------------------------" |
|---|
| 669 | print "Copy demo files..." |
|---|
| 670 | files = glob.glob(os.path.join(demos_dir, "*.m")) |
|---|
| 671 | for in_file in files: |
|---|
| 672 | shutil.copy(in_file, out_demos_dir) |
|---|
| 673 | |
|---|
| 674 | |
|---|
| 675 | |
|---|
| 676 | # publish tools |
|---|
| 677 | files = glob.glob(os.path.join(tools_dir, "*.m")) |
|---|
| 678 | filenames = [] |
|---|
| 679 | for in_file in files: |
|---|
| 680 | (filepath, filename) = os.path.split(in_file) |
|---|
| 681 | filenames.append(filename) |
|---|
| 682 | publish_m2html_files(out_tmp_tools, tools_dir, filenames) |
|---|
| 683 | |
|---|
| 684 | # remove styles |
|---|
| 685 | files = glob.glob(os.path.join(out_tmp_tools, "*.html")) |
|---|
| 686 | remove_styles(out_doc_tools_dir, 1, files) |
|---|
| 687 | |
|---|
| 688 | |
|---|
| 689 | # copy tools directory |
|---|
| 690 | print |
|---|
| 691 | print "--------------------------------------------------------------" |
|---|
| 692 | print "Copy tools files..." |
|---|
| 693 | files = [] |
|---|
| 694 | files.extend(glob.glob(os.path.join(tools_dir, "*.m"))) |
|---|
| 695 | files.extend(glob.glob(os.path.join(tools_dir, "*.fig"))) |
|---|
| 696 | for in_file in files: |
|---|
| 697 | shutil.copy(in_file, out_tools_dir) |
|---|
| 698 | |
|---|
| 699 | # overwrite generated files with html versions if existing... |
|---|
| 700 | files = [] |
|---|
| 701 | files.extend(glob.glob(os.path.join(tools_dir, "*.png"))) |
|---|
| 702 | files.extend(glob.glob(os.path.join(tools_dir, "*.html"))) |
|---|
| 703 | for in_file in files: |
|---|
| 704 | shutil.copy(in_file, out_doc_tools_dir) |
|---|
| 705 | |
|---|
| 706 | |
|---|
| 707 | # clean up: delete temp-dir!!! |
|---|
| 708 | print |
|---|
| 709 | print "--------------------------------------------------------------" |
|---|
| 710 | print "Clean up: Delete tmp-folder..." |
|---|
| 711 | shutil.rmtree(out_tmp, True) # True ignores errors! |
|---|