move texcount to docker
This commit is contained in:
@@ -7,6 +7,8 @@ Path = require "path"
|
|||||||
logger = require "logger-sharelatex"
|
logger = require "logger-sharelatex"
|
||||||
Metrics = require "./Metrics"
|
Metrics = require "./Metrics"
|
||||||
child_process = require "child_process"
|
child_process = require "child_process"
|
||||||
|
CommandRunner = require(Settings.clsi?.commandRunner or "./CommandRunner")
|
||||||
|
fs = require("fs")
|
||||||
|
|
||||||
module.exports = CompileManager =
|
module.exports = CompileManager =
|
||||||
doCompile: (request, callback = (error, outputFiles) ->) ->
|
doCompile: (request, callback = (error, outputFiles) ->) ->
|
||||||
@@ -142,15 +144,12 @@ module.exports = CompileManager =
|
|||||||
return results
|
return results
|
||||||
|
|
||||||
wordcount: (project_id, file_name, callback = (error, pdfPositions) ->) ->
|
wordcount: (project_id, file_name, callback = (error, pdfPositions) ->) ->
|
||||||
base_dir = Settings.path.synctexBaseDir(project_id)
|
file_path = "$COMPILE_DIR/" + file_name
|
||||||
file_path = base_dir + "/" + file_name
|
command = [ "texcount", file_path, "-out=" + file_path + ".wc"]
|
||||||
CompileManager._runWordcount [file_path], (error, stdout) ->
|
directory = Path.join(Settings.path.compilesDir, project_id)
|
||||||
return callback(error) if error?
|
timeout = 10 * 1000
|
||||||
logger.log project_id: project_id, file_name: file_name, stdout: stdout, "wordcount output"
|
|
||||||
callback null, CompileManager._parseWordcountFromOutput(stdout)
|
|
||||||
|
|
||||||
_runWordcount: (args, callback = (error, stdout) ->) ->
|
CommandRunner.run project_id, command, directory, timeout, (error) ->
|
||||||
seconds = 1000
|
|
||||||
child_process.execFile "texcount", args, timeout: 10 * seconds, (error, stdout, stderr) ->
|
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
callback(null, stdout)
|
stdout = fs.readFileSync(directory + "/" + file_name + ".wc", "utf-8")
|
||||||
|
callback null, CompileManager._parseWordcountFromOutput(stdout)
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ describe "CompileManager", ->
|
|||||||
"settings-sharelatex": @Settings = { path: compilesDir: "/compiles/dir" }
|
"settings-sharelatex": @Settings = { path: compilesDir: "/compiles/dir" }
|
||||||
"logger-sharelatex": @logger = { log: sinon.stub() }
|
"logger-sharelatex": @logger = { log: sinon.stub() }
|
||||||
"child_process": @child_process = {}
|
"child_process": @child_process = {}
|
||||||
|
"./CommandRunner": @CommandRunner = {}
|
||||||
|
"fs": @fs = {}
|
||||||
@callback = sinon.stub()
|
@callback = sinon.stub()
|
||||||
|
|
||||||
describe "doCompile", ->
|
describe "doCompile", ->
|
||||||
@@ -175,16 +177,24 @@ describe "CompileManager", ->
|
|||||||
|
|
||||||
describe "wordcount", ->
|
describe "wordcount", ->
|
||||||
beforeEach ->
|
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"
|
@file_name = "main.tex"
|
||||||
@child_process.execFile = sinon.stub()
|
@Settings.path.compilesDir = "/local/compile/directory"
|
||||||
@child_process.execFile.callsArgWith(3, null, @stdout = "Encoding: ascii\nWords in text: 2", "")
|
|
||||||
@Settings.path.synctexBaseDir = (project_id) => "#{@Settings.path.compilesDir}/#{@project_id}"
|
|
||||||
@CompileManager.wordcount @project_id, @file_name, @callback
|
@CompileManager.wordcount @project_id, @file_name, @callback
|
||||||
|
|
||||||
it "should execute the texcount binary", ->
|
it "should run the texcount command", ->
|
||||||
file_path = "#{@Settings.path.compilesDir}/#{@project_id}/#{@file_name}"
|
@directory = "#{@Settings.path.compilesDir}/#{@project_id}"
|
||||||
@child_process.execFile
|
@file_path = "$COMPILE_DIR/#{@file_name}"
|
||||||
.calledWith("texcount", [file_path], timeout: 10000)
|
@command =[ "texcount", @file_path, "-out=" + @file_path + ".wc"]
|
||||||
|
|
||||||
|
@CommandRunner.run
|
||||||
|
.calledWith(@project_id, @command, @directory, @timeout)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should call the callback with the parsed output", ->
|
it "should call the callback with the parsed output", ->
|
||||||
@@ -200,4 +210,3 @@ describe "CompileManager", ->
|
|||||||
mathDisplay: 0
|
mathDisplay: 0
|
||||||
})
|
})
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user