| author | paulson <lp15@cam.ac.uk> | 
| Thu, 19 Sep 2019 12:36:15 +0100 | |
| changeset 70724 | 65371451fde8 | 
| parent 68927 | 01f46a4b22b4 | 
| child 71631 | 3f02bc5a5a03 | 
| permissions | -rw-r--r-- | 
| 62400 | 1 | /* Title: Pure/System/process_result.scala | 
| 2 | Author: Makarius | |
| 3 | ||
| 4 | Result of system process. | |
| 5 | */ | |
| 6 | ||
| 7 | package isabelle | |
| 8 | ||
| 62401 | 9 | final case class Process_Result( | 
| 62402 | 10 | rc: Int, | 
| 11 | out_lines: List[String] = Nil, | |
| 12 | err_lines: List[String] = Nil, | |
| 62569 | 13 | timeout: Boolean = false, | 
| 14 | timing: Timing = Timing.zero) | |
| 62400 | 15 | {
 | 
| 16 | def out: String = cat_lines(out_lines) | |
| 17 | def err: String = cat_lines(err_lines) | |
| 68091 | 18 | def errors(errs: List[String]): Process_Result = copy(err_lines = err_lines ::: errs) | 
| 19 | def error(err: String): Process_Result = errors(List(err)) | |
| 62400 | 20 | |
| 62569 | 21 | def was_timeout: Process_Result = copy(rc = 1, timeout = true) | 
| 62401 | 22 | |
| 62400 | 23 | def ok: Boolean = rc == 0 | 
| 24 | def interrupted: Boolean = rc == Exn.Interrupt.return_code | |
| 25 | ||
| 68927 | 26 | def error_rc: Process_Result = if (interrupted) this else copy(rc = rc max 1) | 
| 27 | ||
| 64408 
50bcf976f276
clarified hg push return code: 1 means "nothing to push";
 wenzelm parents: 
64138diff
changeset | 28 | def check_rc(pred: Int => Boolean): Process_Result = | 
| 
50bcf976f276
clarified hg push return code: 1 means "nothing to push";
 wenzelm parents: 
64138diff
changeset | 29 | if (pred(rc)) this | 
| 62400 | 30 | else if (interrupted) throw Exn.Interrupt() | 
| 62492 | 31 | else Exn.error(err) | 
| 62400 | 32 | |
| 64408 
50bcf976f276
clarified hg push return code: 1 means "nothing to push";
 wenzelm parents: 
64138diff
changeset | 33 | def check: Process_Result = check_rc(_ == 0) | 
| 
50bcf976f276
clarified hg push return code: 1 means "nothing to push";
 wenzelm parents: 
64138diff
changeset | 34 | |
| 62400 | 35 | def print: Process_Result = | 
| 36 |   {
 | |
| 64138 
cf0c8c5782af
eliminated extra trim_line: Process_Result.out/err are based on cat_lines, without trailing newline;
 wenzelm parents: 
64024diff
changeset | 37 | Output.warning(err) | 
| 
cf0c8c5782af
eliminated extra trim_line: Process_Result.out/err are based on cat_lines, without trailing newline;
 wenzelm parents: 
64024diff
changeset | 38 | Output.writeln(out) | 
| 62404 
13a0f537e232
retain tail out_lines as printed, but not the whole log content;
 wenzelm parents: 
62402diff
changeset | 39 | copy(out_lines = Nil, err_lines = Nil) | 
| 62400 | 40 | } | 
| 62553 | 41 | |
| 42 | def print_stdout: Process_Result = | |
| 43 |   {
 | |
| 64138 
cf0c8c5782af
eliminated extra trim_line: Process_Result.out/err are based on cat_lines, without trailing newline;
 wenzelm parents: 
64024diff
changeset | 44 | Output.warning(err, stdout = true) | 
| 
cf0c8c5782af
eliminated extra trim_line: Process_Result.out/err are based on cat_lines, without trailing newline;
 wenzelm parents: 
64024diff
changeset | 45 | Output.writeln(out, stdout = true) | 
| 62553 | 46 | copy(out_lines = Nil, err_lines = Nil) | 
| 47 | } | |
| 64024 | 48 | |
| 49 | def print_if(b: Boolean): Process_Result = if (b) print else this | |
| 50 | def print_stdout_if(b: Boolean): Process_Result = if (b) print_stdout else this | |
| 62400 | 51 | } |