elif "(First " in slug: num_of_lines = int(slug.split()[3]) adjusted = lines[:num_of_lines + 1] +\ [" ..."] return "\n".join(adjusted) else: return text @CmdLine("f") def reformat_runoutput_files(): "Produce formatted .p1 files from the .out files produced by gradlew run" out_files = list(Path(".").rglob("*.out")) if len(out_files) < 10: print("Error: found less than 10 .out files") sys.exit(1) for outfile in out_files: out_text = adjust_lines(outfile.read_text()) phase_1 = outfile.with_suffix(".p1") with phase_1.open('w') as phs1: phs1.write(fill_to_width(out_text) + "\n") errfile = outfile.with_suffix(".err") if errfile.exists(): phs1.write("___[ Error Output ]___\n") phs1.write(fill_to_width(errfile.read_text()) + "\n") phs1.write("*/\n") if __name__ == '__main__': CmdLine.run()
@CmdLine("c") def clean(): "Remove ExtractedExamples directory" print("Cleaning ...") try: if config.example_dir.exists(): shutil.rmtree(str(config.example_dir)) except: print("Old path removal failed") raise RuntimeError() # go_bat = """\ # gradlew --parallel --daemon run > output.txt 2> errors.txt # START /min "C:\Program Files\Windows Media Player\wmplayer.exe" %windir%\media\Alarm07.wav # rem find . -size 0 -type f # """ @CmdLine('e') def extractAndCopyBuildFiles(): "Clean, then extract examples from Markdown, copy gradle files from OnJava-Examples" clean() extractExamples() copyGradleFiles() # os.chdir(str(config.example_dir)) # with open("go.bat", 'w') as run: # run.write(go_bat) if __name__ == '__main__': CmdLine.run()
def test_main(): CmdLine.run()
def test_main(): sys.argv.append("-t") CmdLine.run()
else: self.output.append("```") self.output.append("") self.output.append(self.input[self.index]) return @CmdLine('e') def fix_code_ends(): """ Put in "```" lines """ fixed = FixCode(config.markdown.read_text(encoding="utf8").splitlines()) config.markdown.with_name("AtomicScala-2.md").write_text("\n".join(fixed.output), encoding="utf8") @CmdLine('f') def fix_code(): """ Fix code listings in AtomicScala.md """ mdown = config.markdown.read_text(encoding="utf8") starts = [line for line in mdown.splitlines() if line.startswith("1 ") ] pprint(starts) print(len(starts)) if __name__ == '__main__': CmdLine.run()