61276
|
1 |
/* Title: Pure/System/progress.scala
|
|
2 |
Author: Makarius
|
|
3 |
|
|
4 |
Progress context for system processes.
|
|
5 |
*/
|
|
6 |
|
|
7 |
package isabelle
|
|
8 |
|
|
9 |
|
64201
|
10 |
import java.io.{File => JFile}
|
|
11 |
|
|
12 |
|
61276
|
13 |
class Progress
|
|
14 |
{
|
|
15 |
def echo(msg: String) {}
|
64049
|
16 |
def echo_if(cond: Boolean, msg: String) { if (cond) echo(msg) }
|
61276
|
17 |
def theory(session: String, theory: String) {}
|
64909
|
18 |
|
65826
|
19 |
def echo_warning(msg: String) { echo(Output.warning_text(msg)) }
|
65828
|
20 |
def echo_error_message(msg: String) { echo(Output.error_message_text(msg)) }
|
65826
|
21 |
|
65921
|
22 |
def timeit[A](message: String = "", enabled: Boolean = true)(e: => A): A =
|
|
23 |
Timing.timeit(message, enabled, echo(_))(e)
|
|
24 |
|
61276
|
25 |
def stopped: Boolean = false
|
|
26 |
override def toString: String = if (stopped) "Progress(stopped)" else "Progress"
|
64201
|
27 |
|
|
28 |
def bash(script: String,
|
|
29 |
cwd: JFile = null,
|
|
30 |
env: Map[String, String] = Isabelle_System.settings(),
|
|
31 |
redirect: Boolean = false,
|
65930
|
32 |
echo: Boolean = false,
|
|
33 |
strict: Boolean = true): Process_Result =
|
64201
|
34 |
{
|
|
35 |
Isabelle_System.bash(script, cwd = cwd, env = env, redirect = redirect,
|
|
36 |
progress_stdout = echo_if(echo, _),
|
65930
|
37 |
progress_stderr = echo_if(echo, _),
|
|
38 |
strict = strict)
|
64201
|
39 |
}
|
61276
|
40 |
}
|
|
41 |
|
64909
|
42 |
object No_Progress extends Progress
|
61276
|
43 |
|
64117
|
44 |
class Console_Progress(verbose: Boolean = false, stderr: Boolean = false) extends Progress
|
61276
|
45 |
{
|
64117
|
46 |
override def echo(msg: String)
|
|
47 |
{
|
67178
|
48 |
Output.writeln(msg, stdout = !stderr)
|
64117
|
49 |
}
|
|
50 |
|
61276
|
51 |
override def theory(session: String, theory: String): Unit =
|
|
52 |
if (verbose) echo(session + ": theory " + theory)
|
|
53 |
|
|
54 |
@volatile private var is_stopped = false
|
|
55 |
def interrupt_handler[A](e: => A): A = POSIX_Interrupt.handler { is_stopped = true } { e }
|
|
56 |
override def stopped: Boolean =
|
|
57 |
{
|
|
58 |
if (Thread.interrupted) is_stopped = true
|
|
59 |
is_stopped
|
|
60 |
}
|
|
61 |
}
|
65888
|
62 |
|
|
63 |
class File_Progress(path: Path, verbose: Boolean = false) extends Progress
|
|
64 |
{
|
|
65 |
override def echo(msg: String): Unit =
|
|
66 |
File.append(path, msg + "\n")
|
|
67 |
|
|
68 |
override def theory(session: String, theory: String): Unit =
|
|
69 |
if (verbose) echo(session + ": theory " + theory)
|
|
70 |
|
|
71 |
override def toString: String = path.toString
|
|
72 |
}
|