From e5dd2396c1b83fb652a4e13d6e0ed23421e31f1e Mon Sep 17 00:00:00 2001 From: barrerajl Date: Thu, 11 Oct 2018 13:05:37 +0200 Subject: [PATCH 1/3] Add soffice options as stated here: http://document-foundation-mail-archive.969070.n3.nabble.com/How-to-run-multiple-instances-of-Writer-simultaneously-td4225101.html to run multi instances of soffice --- lib/libreconv.rb | 28 ++++++++++++++++++++++++---- lib/libreconv/version.rb | 2 +- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/lib/libreconv.rb b/lib/libreconv.rb index ed1e1de..1b81d03 100644 --- a/lib/libreconv.rb +++ b/lib/libreconv.rb @@ -27,12 +27,19 @@ def initialize(source, target, soffice_command = nil, convert_to = nil) end def convert - orig_stdout = $stdout.clone - $stdout.reopen File.new('/dev/null', 'w') + silent_stdout Dir.mktmpdir { |target_path| - pid = Spoon.spawnp(@soffice_command, "--headless", "--convert-to", @convert_to, @source, "--outdir", target_path) + pid = Spoon.spawnp(@soffice_command, + "'--accept=\"pipe,name=soffice-pipe-#{uuid};url;StarOffice.ServiceManager\"", + "-env:UserInstallation=file:///tmp/soffice-dir-#{uuid}", + "--headless", + "--convert-to", + @convert_to, + @source, + "--outdir", + target_path) Process.waitpid(pid) - $stdout.reopen orig_stdout + loud_stoud target_tmp_file = "#{target_path}/#{File.basename(@source, ".*")}.#{File.basename(@convert_to, ":*")}" FileUtils.cp target_tmp_file, @target } @@ -40,6 +47,19 @@ def convert private + def silent_stdout + @orig_stdout = $stdout.clone + $stdout.reopen File.new('/dev/null', 'w') + end + + def loud_stoud + $stdout.reopen @orig_stdout + end + + def uuid + SecureRandom.uuid + end + def determine_soffice_command unless @soffice_command @soffice_command ||= which("soffice") diff --git a/lib/libreconv/version.rb b/lib/libreconv/version.rb index dadacbb..555baaf 100644 --- a/lib/libreconv/version.rb +++ b/lib/libreconv/version.rb @@ -1,3 +1,3 @@ module Libreconv - VERSION = "0.9.1" + VERSION = "0.9.2" end From 1567d8e248f1455026b0a03cfd84385e8ae94af4 Mon Sep 17 00:00:00 2001 From: barrerajl Date: Thu, 11 Oct 2018 13:09:10 +0200 Subject: [PATCH 2/3] Rename method for better understanding --- lib/libreconv.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/libreconv.rb b/lib/libreconv.rb index 1b81d03..ec38ff3 100644 --- a/lib/libreconv.rb +++ b/lib/libreconv.rb @@ -39,7 +39,7 @@ def convert "--outdir", target_path) Process.waitpid(pid) - loud_stoud + original_stdout target_tmp_file = "#{target_path}/#{File.basename(@source, ".*")}.#{File.basename(@convert_to, ":*")}" FileUtils.cp target_tmp_file, @target } @@ -52,7 +52,7 @@ def silent_stdout $stdout.reopen File.new('/dev/null', 'w') end - def loud_stoud + def original_stdout $stdout.reopen @orig_stdout end From ecc6f2a4c26e10a512689751bd3298e34b59cedc Mon Sep 17 00:00:00 2001 From: barrerajl Date: Thu, 11 Oct 2018 13:40:01 +0200 Subject: [PATCH 3/3] Remove soffice home dir after execution --- lib/libreconv.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/libreconv.rb b/lib/libreconv.rb index ec38ff3..41a38e3 100644 --- a/lib/libreconv.rb +++ b/lib/libreconv.rb @@ -42,6 +42,7 @@ def convert original_stdout target_tmp_file = "#{target_path}/#{File.basename(@source, ".*")}.#{File.basename(@convert_to, ":*")}" FileUtils.cp target_tmp_file, @target + FileUtils.rm_rf("/tmp/soffice-dir-#{uuid}") } end @@ -57,7 +58,7 @@ def original_stdout end def uuid - SecureRandom.uuid + @uuid ||= SecureRandom.uuid end def determine_soffice_command