From 4497352a3af92224f5a03f71a5038861a16e861b Mon Sep 17 00:00:00 2001 From: James Allen Date: Tue, 12 Jan 2016 17:04:42 +0000 Subject: [PATCH] Allow optional image name to be passed --- app/coffee/CommandRunner.coffee | 2 +- app/coffee/CompileManager.coffee | 1 + app/coffee/LatexRunner.coffee | 4 ++-- app/coffee/RequestParser.coffee | 4 +++- test/unit/coffee/CompileManagerTests.coffee | 2 ++ test/unit/coffee/LatexRunnerTests.coffee | 7 +++++-- 6 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/coffee/CommandRunner.coffee b/app/coffee/CommandRunner.coffee index 55dec33..41cbfaa 100644 --- a/app/coffee/CommandRunner.coffee +++ b/app/coffee/CommandRunner.coffee @@ -2,7 +2,7 @@ spawn = require("child_process").spawn logger = require "logger-sharelatex" module.exports = CommandRunner = - run: (project_id, command, directory, timeout, callback = (error) ->) -> + run: (project_id, command, directory, image, timeout, callback = (error) ->) -> command = (arg.replace('$COMPILE_DIR', directory) for arg in command) logger.log project_id: project_id, command: command, directory: directory, "running command" logger.warn "timeouts and sandboxing are not enabled with CommandRunner" diff --git a/app/coffee/CompileManager.coffee b/app/coffee/CompileManager.coffee index 945da42..e7e8849 100644 --- a/app/coffee/CompileManager.coffee +++ b/app/coffee/CompileManager.coffee @@ -28,6 +28,7 @@ module.exports = CompileManager = mainFile: request.rootResourcePath compiler: request.compiler timeout: request.timeout + image: request.imageName }, (error) -> return callback(error) if error? logger.log project_id: request.project_id, time_taken: Date.now() - timer.start, "done compile" diff --git a/app/coffee/LatexRunner.coffee b/app/coffee/LatexRunner.coffee index cd6e356..169a216 100644 --- a/app/coffee/LatexRunner.coffee +++ b/app/coffee/LatexRunner.coffee @@ -6,7 +6,7 @@ CommandRunner = require(Settings.clsi?.commandRunner or "./CommandRunner") module.exports = LatexRunner = runLatex: (project_id, options, callback = (error) ->) -> - {directory, mainFile, compiler, timeout} = options + {directory, mainFile, compiler, timeout, image} = options compiler ||= "pdflatex" timeout ||= 60000 # milliseconds @@ -27,7 +27,7 @@ module.exports = LatexRunner = else return callback new Error("unknown compiler: #{compiler}") - CommandRunner.run project_id, command, directory, timeout, callback + CommandRunner.run project_id, command, directory, image, timeout, callback _latexmkBaseCommand: [ "latexmk", "-cd", "-f", "-jobname=output", "-auxdir=$COMPILE_DIR", "-outdir=$COMPILE_DIR"] diff --git a/app/coffee/RequestParser.coffee b/app/coffee/RequestParser.coffee index 5326810..1b4e06d 100644 --- a/app/coffee/RequestParser.coffee +++ b/app/coffee/RequestParser.coffee @@ -21,6 +21,9 @@ module.exports = RequestParser = compile.options.timeout default: RequestParser.MAX_TIMEOUT type: "number" + response.imageName = @_parseAttribute "imageName", + compile.options.imageName, + type: "string" if response.timeout > RequestParser.MAX_TIMEOUT response.timeout = RequestParser.MAX_TIMEOUT @@ -71,7 +74,6 @@ module.exports = RequestParser = throw "#{name} attribute should be a #{options.type}" else return options.default if options.default? - throw "Default not implemented" return attribute _sanitizePath: (path) -> diff --git a/test/unit/coffee/CompileManagerTests.coffee b/test/unit/coffee/CompileManagerTests.coffee index 87f424b..dff3052 100644 --- a/test/unit/coffee/CompileManagerTests.coffee +++ b/test/unit/coffee/CompileManagerTests.coffee @@ -44,6 +44,7 @@ describe "CompileManager", -> project_id: @project_id = "project-id-123" compiler: @compiler = "pdflatex" timeout: @timeout = 42000 + imageName: @image = "example.com/image" @Settings.compileDir = "compiles" @compileDir = "#{@Settings.path.compilesDir}/#{@project_id}" @ResourceWriter.syncResourcesToDisk = sinon.stub().callsArg(3) @@ -64,6 +65,7 @@ describe "CompileManager", -> mainFile: @rootResourcePath compiler: @compiler timeout: @timeout + image: @image }) .should.equal true diff --git a/test/unit/coffee/LatexRunnerTests.coffee b/test/unit/coffee/LatexRunnerTests.coffee index d3782a6..ace3d18 100644 --- a/test/unit/coffee/LatexRunnerTests.coffee +++ b/test/unit/coffee/LatexRunnerTests.coffee @@ -19,12 +19,13 @@ describe "LatexRunner", -> @directory = "/local/compile/directory" @mainFile = "main-file.tex" @compiler = "pdflatex" + @image = "example.com/image" @callback = sinon.stub() @project_id = "project-id-123" describe "runLatex", -> beforeEach -> - @CommandRunner.run = sinon.stub().callsArg(4) + @CommandRunner.run = sinon.stub().callsArg(5) describe "normally", -> beforeEach -> @@ -33,11 +34,12 @@ describe "LatexRunner", -> mainFile: @mainFile compiler: @compiler timeout: @timeout = 42000 + image: @image @callback it "should run the latex command", -> @CommandRunner.run - .calledWith(@project_id, sinon.match.any, @directory, @timeout) + .calledWith(@project_id, sinon.match.any, @directory, @image, @timeout) .should.equal true describe "with an .Rtex main file", -> @@ -46,6 +48,7 @@ describe "LatexRunner", -> directory: @directory mainFile: "main-file.Rtex" compiler: @compiler + image: @image timeout: @timeout = 42000 @callback