Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions lib/libreconv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,40 @@ 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
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

private

def silent_stdout
@orig_stdout = $stdout.clone
$stdout.reopen File.new('/dev/null', 'w')
end

def original_stdout
$stdout.reopen @orig_stdout
end

def uuid
@uuid ||= SecureRandom.uuid
end

def determine_soffice_command
unless @soffice_command
@soffice_command ||= which("soffice")
Expand Down
2 changes: 1 addition & 1 deletion lib/libreconv/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Libreconv
VERSION = "0.9.1"
VERSION = "0.9.2"
end