mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-23 01:23:59 +00:00
move texcount to docker
This commit is contained in:
parent
09032565e2
commit
d332665648
2 changed files with 26 additions and 18 deletions
|
@ -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)
|
||||
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" }
|
||||
"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
|
||||
|
||||
|
|
Loading…
Reference in a new issue