当前位置: 首页>>代码示例>>Scala>>正文


Scala ProcessLogger类代码示例

本文整理汇总了Scala中scala.sys.process.ProcessLogger的典型用法代码示例。如果您正苦于以下问题:Scala ProcessLogger类的具体用法?Scala ProcessLogger怎么用?Scala ProcessLogger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ProcessLogger类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: LoggingComponentTest

//设置package包名称以及导入依赖的类
package com.meetup.logging

import java.io.File

import org.scalatest.{FunSpec, Matchers}

import scala.sys.process.{Process, ProcessLogger}

class LoggingComponentTest extends FunSpec with Matchers {

  val baseDir = new File("src/component/sbt")
  var appJar = new File("target/scala-2.11/component-test.jar")

  it("should work when used in runtime") {
    val assemble = Process(Seq("sbt", "assembly", "run"), baseDir).!!.trim
    println(assemble)
    val proc = Process(Seq("java", "-jar", appJar.toString), baseDir)
    val (out, err) = (new StringBuffer(), new StringBuffer())
    val logger = ProcessLogger(
      out.append(_),
      err.append(_)
    )
    proc.!(logger)
    out.toString should include("TestApp info")
    err.toString should include("TestApp error")
  }

} 
开发者ID:meetup,项目名称:scala-logger,代码行数:29,代码来源:LoggingComponentTest.scala

示例2: SbtTestRunner

//设置package包名称以及导入依赖的类
package service.sbt

import java.nio.charset.StandardCharsets
import java.nio.file._
import java.nio.file.attribute.BasicFileAttributes

import scala.sys.process.{Process, ProcessLogger}
import scala.util.Try

object SbtTestRunner {

  def createProjectAndTest(solution: String, appAbsolutePath: String): String = {
    import scala.collection.JavaConversions._
    Try {
      val buildSbt = List(
        """lazy val root = (project in file("."))""",
        """  .settings(""",
        """    scalaVersion := "2.11.7",""",
        """    libraryDependencies += "org.scalatest" %% "scalatest" % "2.2.6" % "test"""",
        """  )"""
      )
      val d = Files.createTempDirectory("test")
      Files.write(d.resolve("build.sbt"), buildSbt, StandardCharsets.UTF_8)

      val project = d.resolve("project")
      Files.createDirectory(project)

      Files.write(project.resolve("build.properties"), List("sbt.version=0.13.9"), StandardCharsets.UTF_8)

      val solutionTargetPath = d.resolve("src").resolve("main").resolve("scala")
      Files.createDirectories(solutionTargetPath)
      Files.write(solutionTargetPath.resolve("UserSolution.scala"), List("package tests", s"object SleepInSolution {$solution}"), StandardCharsets.UTF_8)

      val testTargetPath = d.resolve("src").resolve("test").resolve("scala")
      Files.createDirectories(testTargetPath)
      val testSourcePath = Paths.get(appAbsolutePath, "test", "tests")

      Files.walkFileTree(testSourcePath, new SimpleFileVisitor[Path] {
        override def visitFile(file: Path, attrs: BasicFileAttributes): FileVisitResult = {
          Files.copy(file, testTargetPath.resolve(testSourcePath.relativize(file)))
          FileVisitResult.CONTINUE
        }
      })
      val sbtCommands = Seq("sbt", "-Dsbt.log.noformat=true", "test")
      val output = new StringBuilder
      Process(sbtCommands, d.toFile).!(ProcessLogger(line => output append line append "\n"))
      output.toString()
      //TODO: we need to clean all temp folders
    }.getOrElse("Test failed")
  }
} 
开发者ID:DmytroOrlov,项目名称:devgym,代码行数:52,代码来源:SbtTestRunner.scala

示例3: RsyncAction

//设置package包名称以及导入依赖的类
package com.criteo.dev.cluster.command

import com.criteo.dev.cluster._
import org.slf4j.LoggerFactory

import scala.sys.process.ProcessLogger


@Public
object RsyncAction {
  private val logger = LoggerFactory.getLogger(ScpAction.getClass)
  private val processLogger = ProcessLogger(
    (o: String) => logger.info(o),
    (e: String) => logger.error(e))

  def apply(srcPath: String, targetN: Node, targetPath: String, sudo: Boolean = false) : Unit = {
    var command = scala.collection.mutable.ListBuffer[String]()
    command += "rsync"
    command += "-rvvz"
    command += "-e"

    val sshStr = new StringBuilder("ssh -o StrictHostKeyChecking=no ")
    val targetKey = targetN.key
    val targetUser = targetN.user
    val targetIp = targetN.ip
    val targetPort = targetN.port

    if (targetKey.isDefined) {
      sshStr.append(s"-i ${targetKey.get}")
    }

    if (targetPort.isDefined) {
      sshStr.append(s"-P ${targetPort.get}")
    }
    command += sshStr.toString

    if (sudo) {
      command += "--rsync-path=sudo rsync"
    }

    command += srcPath

    val targetPathFull = new StringBuilder()
    if (targetUser.isDefined) {
      targetPathFull.append(s"${targetUser.get}@")
    }
    targetPathFull.append(s"$targetIp:")
    targetPathFull.append(targetPath)
    command += targetPathFull.toString

    val p = DevClusterProcess.processSeq(command)
    GeneralUtilities.checkStatus(p.!(processLogger))
  }
} 
开发者ID:criteo,项目名称:berilia,代码行数:55,代码来源:RsyncAction.scala

示例4: ShellAction

//设置package包名称以及导入依赖的类
package com.criteo.dev.cluster.command

import com.criteo.dev.cluster.{DevClusterProcess, GeneralUtilities, Public}
import org.slf4j.LoggerFactory

import scala.sys.process.ProcessLogger


@Public
object ShellAction {
  private val logger = LoggerFactory.getLogger(this.getClass)

  private val suppressingProcessLogger = ProcessLogger(_ => ())

  private val processLogger = ProcessLogger(
    (o: String) => logger.info(o),
    (e: String) => logger.error(e))

  def apply(script: String, returnResult: Boolean = false, ignoreFailure: Boolean = false): String = {
    val p = DevClusterProcess.processSeq(script.split("\\s+"))

    (returnResult, ignoreFailure) match {
      case (false, true) => {
        p.!(suppressingProcessLogger)
        return null
      }
      case (false, false) => {
        GeneralUtilities.checkStatus(p.!(processLogger))
        return null
      }
      case (true, true) => {
        try {
          p.!!(suppressingProcessLogger)
        } catch {
          case e: Exception => null
        }
      }
      case (true, false) => return p.!!(processLogger)
    }
  }
} 
开发者ID:criteo,项目名称:berilia,代码行数:42,代码来源:ShellAction.scala

示例5: DockerBuildAction

//设置package包名称以及导入依赖的类
package com.criteo.dev.cluster.docker

import com.criteo.dev.cluster.DevClusterProcess
import org.slf4j.LoggerFactory

import scala.collection.mutable.ListBuffer
import scala.sys.process.{Process, ProcessLogger}



class DockerBuildAction (dockerFile: String, dockerImage: String) {

  private val logger = LoggerFactory.getLogger(classOf[DockerBuildAction])

  private val processLogger = ProcessLogger(
    (e: String) => logger.info("err " + e))

  private val args = new ListBuffer[Pair[String, String]]
  private val ports = new ListBuffer[PortMeta]

  def addArg(key: String, value: String) = {
     args.+=(Pair(key, value))
  }

  def run() : Unit = {
    val sb = new StringBuilder("docker build")
    sb.append(s" -t $dockerImage")
    sb.append(s" -f ./${DockerConstants.dockerBaseDir}/$dockerFile")
    args.foreach(p =>  sb.append(s" --build-arg ${p._1}=${p._2}"))
    sb.append(s" ${DockerConstants.dockerBaseDir}")
    val out = DevClusterProcess.process(sb.toString).!
    if (out != 0) {
      throw new Exception("Failure running docker command.")
    }
  }
}

object DockerBuildAction {
  def apply(dockerFile: String, dockerImage: String) = {
    val dba = new DockerBuildAction(dockerFile, dockerImage)
    dba.run
  }
} 
开发者ID:criteo,项目名称:berilia,代码行数:44,代码来源:DockerBuildAction.scala

示例6: Numpy

//设置package包名称以及导入依赖的类
package testbed

import testbed._

import scala.reflect.io.{File, Path}
import scala.sys.process.{ProcessLogger, Process}

class Numpy[ResultType](val pathToPython: String, numpyImportAlias: String = "np") {

  def isInstalled = {
    val testPythonCmd = Process(s"$pathToPython --version")
    val testNumpyCmd = Process(Seq(pathToPython, "-c",  "'import numpy; print(numpy.version)'"))

    def pythonInstalled = {
      var result = ""
      testPythonCmd ! ProcessLogger(line => result += line)

      result contains "Python"
    }

    def numpyInstalled = {
      var result = ""
      testNumpyCmd ! ProcessLogger(line => result += line)

      !(result contains "Error")
    }

    pythonInstalled && numpyInstalled
  }

  val NOT_INSTALLED_MSG: String = s"No numpy installation found with $pathToPython."

  val PYTHON_SRC_FILE_NAME: String = "src_buffer.py"

  def getResult(numpyExpr: String, bufferName: String, resultReader: String => ResultType) = {
    assert(isInstalled, NOT_INSTALLED_MSG)
    val absolutePathToBuffer = Path(bufferName).toAbsolute.path
    val pythonSrcFile = File(PYTHON_SRC_FILE_NAME)
    val pythonFileWriteExpr =
      s"""import numpy as $numpyImportAlias
         |import csv
         |with open('$absolutePathToBuffer', 'w') as buffer_file:
         |        csv_writer = csv.writer(buffer_file, delimiter=',')
         |        for result_line in $numpyExpr:
         |            result_line = [result_line]
         |            csv_writer.writerow(result_line)
       """.stripMargin

    pythonSrcFile.writeAll(pythonFileWriteExpr)

    Process(Seq(pathToPython, pythonSrcFile.toAbsolute.path))!

    resultReader(bufferName)
  }
} 
开发者ID:bethge,项目名称:sketching-testbed,代码行数:56,代码来源:Numpy.scala


注:本文中的scala.sys.process.ProcessLogger类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。