| 453 | self.warnCount = self.warnCount + 1 |
| 454 | |
| 455 | def reflowFile(filename, args): |
| 456 | logDiag('reflow: filename', filename) |
| 457 | |
| 458 | # Output file handle and reflow object for this file. There are no race |
| 459 | # conditions on overwriting the input, but it is not recommended unless |
| 460 | # you have backing store such as git. |
| 461 | |
| 462 | lines, newline_string = loadFile(filename) |
| 463 | if lines is None: |
| 464 | return |
| 465 | |
| 466 | if args.overwrite: |
| 467 | outFilename = filename |
| 468 | else: |
| 469 | outDir = Path(args.outDir).resolve() |
| 470 | outDir.mkdir(parents=True, exist_ok=True) |
| 471 | |
| 472 | outFilename = str(outDir / (os.path.basename(filename) + args.suffix)) |
| 473 | |
| 474 | if args.nowrite: |
| 475 | fp = None |
| 476 | else: |
| 477 | try: |
| 478 | fp = open(outFilename, 'w', encoding='utf8', newline=newline_string) |
| 479 | except: |
| 480 | logWarn('Cannot open output file', outFilename, ':', sys.exc_info()[0]) |
| 481 | return |
| 482 | |
| 483 | callback = ReflowCallbacks(filename, |
| 484 | args.vuidDict, |
| 485 | margin = args.margin, |
| 486 | reflow = not args.noflow, |
| 487 | nextvu = args.nextvu, |
| 488 | maxvu = args.maxvu, |
| 489 | check = args.check) |
| 490 | |
| 491 | transformer = doctransformer.DocTransformer(filename, |
| 492 | outfile = fp, |
| 493 | callback = callback) |
| 494 | |
| 495 | transformer.transformFile(lines) |
| 496 | |
| 497 | if fp is not None: |
| 498 | fp.close() |
| 499 | |
| 500 | # Update the 'nextvu' value |
| 501 | if args.nextvu != callback.nextvu: |
| 502 | logWarn('Updated nextvu to', callback.nextvu, 'after file', filename) |
| 503 | args.nextvu = callback.nextvu |
| 504 | |
| 505 | args.warnCount += callback.warnCount |
| 506 | |
| 507 | def reflowAllAdocFiles(folder_to_reflow, args): |
| 508 | for root, subdirs, files in os.walk(folder_to_reflow): |