From d3326656488313b7ca421755c7af7f7476b526db Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Tue, 8 Sep 2015 10:19:46 -0300 Subject: [PATCH] move texcount to docker --- .../clsi/app/coffee/CompileManager.coffee | 19 +++++++------- .../unit/coffee/CompileManagerTests.coffee | 25 +++++++++++++------ 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/services/clsi/app/coffee/CompileManager.coffee b/services/clsi/app/coffee/CompileManager.coffee index f689ae8833..0392ccef2c 100644 --- a/services/clsi/app/coffee/CompileManager.coffee +++ b/services/clsi/app/coffee/CompileManager.coffee @@ -7,6 +7,8 @@ Path = require "path" logger = require "logger-sharelatex" Metrics = require "./Metrics" child_process = require "child_process" +CommandRunner = require(Settings.clsi?.commandRunner or "./CommandRunner") +fs = require("fs") module.exports = CompileManager = doCompile: (request, callback = (error, outputFiles) ->) -> @@ -142,15 +144,12 @@ module.exports = CompileManager = return results wordcount: (project_id, file_name, callback = (error, pdfPositions) ->) -> - base_dir = Settings.path.synctexBaseDir(project_id) - file_path = base_dir + "/" + file_name - CompileManager._runWordcount [file_path], (error, stdout) -> - return callback(error) if error? - logger.log project_id: project_id, file_name: file_name, stdout: stdout, "wordcount output" - callback null, CompileManager._parseWordcountFromOutput(stdout) + file_path = "$COMPILE_DIR/" + file_name + command = [ "texcount", file_path, "-out=" + file_path + ".wc"] + directory = Path.join(Settings.path.compilesDir, project_id) + timeout = 10 * 1000 - _runWordcount: (args, callback = (error, stdout) ->) -> - seconds = 1000 - child_process.execFile "texcount", args, timeout: 10 * seconds, (error, stdout, stderr) -> + CommandRunner.run project_id, command, directory, timeout, (error) -> return callback(error) if error? - callback(null, stdout) \ No newline at end of file + stdout = fs.readFileSync(directory + "/" + file_name + ".wc", "utf-8") + callback null, CompileManager._parseWordcountFromOutput(stdout) diff --git a/services/clsi/test/unit/coffee/CompileManagerTests.coffee b/services/clsi/test/unit/coffee/CompileManagerTests.coffee index eae49627c1..10ab2eac43 100644 --- a/services/clsi/test/unit/coffee/CompileManagerTests.coffee +++ b/services/clsi/test/unit/coffee/CompileManagerTests.coffee @@ -16,6 +16,8 @@ describe "CompileManager", -> "settings-sharelatex": @Settings = { path: compilesDir: "/compiles/dir" } "logger-sharelatex": @logger = { log: sinon.stub() } "child_process": @child_process = {} + "./CommandRunner": @CommandRunner = {} + "fs": @fs = {} @callback = sinon.stub() describe "doCompile", -> @@ -175,16 +177,24 @@ describe "CompileManager", -> describe "wordcount", -> beforeEach -> + @CommandRunner.run = sinon.stub().callsArg(4) + @fs.readFileSync = sinon.stub().returns @stdout = "Encoding: ascii\nWords in text: 2" + @callback = sinon.stub() + + @project_id = "project-id-123" + @timeout = 10 * 1000 @file_name = "main.tex" - @child_process.execFile = sinon.stub() - @child_process.execFile.callsArgWith(3, null, @stdout = "Encoding: ascii\nWords in text: 2", "") - @Settings.path.synctexBaseDir = (project_id) => "#{@Settings.path.compilesDir}/#{@project_id}" + @Settings.path.compilesDir = "/local/compile/directory" + @CompileManager.wordcount @project_id, @file_name, @callback - it "should execute the texcount binary", -> - file_path = "#{@Settings.path.compilesDir}/#{@project_id}/#{@file_name}" - @child_process.execFile - .calledWith("texcount", [file_path], timeout: 10000) + it "should run the texcount command", -> + @directory = "#{@Settings.path.compilesDir}/#{@project_id}" + @file_path = "$COMPILE_DIR/#{@file_name}" + @command =[ "texcount", @file_path, "-out=" + @file_path + ".wc"] + + @CommandRunner.run + .calledWith(@project_id, @command, @directory, @timeout) .should.equal true it "should call the callback with the parsed output", -> @@ -200,4 +210,3 @@ describe "CompileManager", -> mathDisplay: 0 }) .should.equal true -