summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/support/tlcockpit/src/main/scala/TeXLive/TlmgrProcess.scala
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/source/support/tlcockpit/src/main/scala/TeXLive/TlmgrProcess.scala')
-rw-r--r--Master/texmf-dist/source/support/tlcockpit/src/main/scala/TeXLive/TlmgrProcess.scala137
1 files changed, 30 insertions, 107 deletions
diff --git a/Master/texmf-dist/source/support/tlcockpit/src/main/scala/TeXLive/TlmgrProcess.scala b/Master/texmf-dist/source/support/tlcockpit/src/main/scala/TeXLive/TlmgrProcess.scala
index 169f44154fb..7d84e6dd008 100644
--- a/Master/texmf-dist/source/support/tlcockpit/src/main/scala/TeXLive/TlmgrProcess.scala
+++ b/Master/texmf-dist/source/support/tlcockpit/src/main/scala/TeXLive/TlmgrProcess.scala
@@ -2,103 +2,50 @@ package TeXLive
import java.io._
-import OsTools._
+import TeXLive.OsTools._
import scala.collection.mutable.ArrayBuffer
import scala.concurrent.SyncVar
-// import scala.sys.process.{Process, ProcessBuilder, ProcessIO}
import scala.sys.process._
-class TlmgrProcess(updout: Array[String] => Unit, upderr: String => Unit, updline: String => Unit) {
+class TlmgrProcess(updout: String => Unit, upderr: String => Unit) {
val inputString = new SyncVar[String] // used for the tlmgr process input
- val outputString = new SyncVar[String] // used for the tlmgr process output
- val errorBuffer: StringBuffer = new StringBuffer() // buffer used for both tmgr process error console AND logging
+ // val outputString = new SyncVar[String] // used for the tlmgr process output
+ // val errorBuffer: StringBuffer = new StringBuffer() // buffer used for both tmgr process error console AND logging
val tlroot = "kpsewhich -var-value SELFAUTOPARENT".!!.trim
// println("tlroot ==" + tlroot + "==")
// set in only one place, in the main thread
var process: Process = _
- var lastInput: String = ""
- var lastOk: Boolean = false
- var isBusy = false
-
- def send_command(input: String): Array[String] = {
-
- lastInput = input
-
- val maxWaitTime = 5000
- var waited = 0
- var sendNL = 0
- while (isBusy) {
- // do busy waiting here in case some other tlmgr command is running
- // println("Debug: waiting for tlmgr being ready, want to send " + input)
- Thread.sleep(300)
- waited += 300
-
- if (waited > maxWaitTime && sendNL < 3) {
- outputString.put("protocol")
- sendNL += 1
- }
- if (waited > maxWaitTime && sendNL >= 3) {
- throw new Exception("tlmgr busy, waited too long, aborting calling: " + input)
- }
- }
+ def send_command(input: String): Unit = {
try {
- // pass the input and wait for the output
assert(!inputString.isSet)
- assert(!outputString.isSet)
- // errorBuffer.setLength(0)
- synchronized(isBusy = true)
inputString.put(input)
- val ret = if (input != "quit") {
- get_output_till_prompt()
- } else {
- new Array[String](0)
- }
- // updout(ret.mkString("\n"))
- updout(ret)
- upderr(errorBuffer.toString)
- synchronized( isBusy = false )
- ret
} catch {
case exc: Throwable =>
- errorBuffer.append(" Main thread: " +
+ upderr("Main thread: " +
(if (exc.isInstanceOf[NoSuchElementException]) "Timeout" else "Exception: " + exc))
- null
}
}
- def start_process(): Unit = {
+ def isAlive(): Boolean = {
+ if (process != null)
+ process.isAlive()
+ else
+ // return true on not-started process
+ true
+ }
+
+ def start_process(): Boolean = {
// process creation
if (process == null) {
- val procIO = new ProcessIO(inputFn(_), outputFn(_), errorFn(_))
- val processBuilder: ProcessBuilder = Seq({if (isWindows) "tlmgr.bat" else "tlmgr"}, "--machine-readable", "shell")
+ val procIO = new ProcessIO(inputFn(_), outputFn(_, updout), outputFn(_, upderr))
+ val processBuilder: ProcessBuilder = Seq({if (isWindows) "tlmgr.bat" else "tlmgr"}, "-v", "--machine-readable", "shell")
process = processBuilder.run(procIO)
}
- }
-
- def get_output_till_prompt(): Array[String] = {
- var ret = ArrayBuffer[String]()
- var result = ""
- var found = false
- synchronized(isBusy = true)
- while (!found) {
- result = outputString.take()
- if (result == "tlmgr> ") {
- found = true
- } else if (result == "OK") {
- lastOk = true
- // do nothing, we found a good ok
- } else if (result == "ERROR") {
- lastOk = false
- } else {
- ret += result
- }
- }
- synchronized(isBusy = false)
- ret.toArray
+ process.isAlive()
}
def cleanup(): Unit = {
@@ -129,53 +76,29 @@ class TlmgrProcess(updout: Array[String] => Unit, upderr: String => Unit, updlin
case exc: Throwable =>
stdin.close()
// println("Exception in inputFn thread: " + exc + "\n")
- errorBuffer.append(" Input thread: Exception: " + exc + "\n")
+ upderr("Input thread: Exception: " + exc + "\n")
}
}
- private[this] def outputFn(stdOut: InputStream): Unit = {
- val reader = new BufferedReader(new InputStreamReader(stdOut))
+ private[this] def outputFn(outStr: InputStream, updfun: String => Unit): Unit = {
+ val reader = new BufferedReader(new InputStreamReader(outStr))
try {
var line: String = ""
while (true) {
line = reader.readLine
- if (line == null) {
- // println("Did read NULL from stdin giving up")
- // error = true
- } else {
- // println("DDD did read " + line + " from process")
- outputString.put(line)
- try {
- updline(line)
- } catch {
- case exc: Throwable =>
- println("Update line function failed, continuing anyway (probably old tlmgr)!")
- }
+ // println("DDD did read " + line + " from process")
+ try {
+ updfun(line)
+ } catch {
+ case exc: Throwable =>
+ upderr("Update output line function failed, continuing anyway. Exception: " + exc)
}
}
- stdOut.close()
- } catch {
- case exc: Throwable =>
- stdOut.close()
- // println("Exception in outputFn thread: " + exc + "\n")
- errorBuffer.append(" Output thread: Exception: " + exc + "\n")
- }
- }
-
- private[this] def errorFn(stdErr: InputStream): Unit = {
- val reader = new BufferedReader(new InputStreamReader(stdErr))
- try {
- var line = reader.readLine
- while (line != null) {
- errorBuffer.append(line + "\n")
- line = reader.readLine
- }
- stdErr.close()
+ outStr.close()
} catch {
case exc: Throwable =>
- stdErr.close()
- // println("Exception in errorFn thread: " + exc + "\n")
- errorBuffer.append(" Error thread: Exception: " + exc + "\n")
+ outStr.close()
+ upderr("Output thread: Exception: " + exc + "\n")
}
}
}