Skip to content

Commit 67118b8

Browse files
authored
Merge pull request #159 from tuttiq/master
Fix deprecated method File.exists? to File.exist?
2 parents ff3b443 + 6127e39 commit 67118b8

File tree

5 files changed

+23
-23
lines changed

5 files changed

+23
-23
lines changed

lib/docsplit/image_extractor.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def convert(pdf, size, format, previous=nil)
3333
directory = directory_for(size)
3434
pages = @pages || '1-' + Docsplit.extract_length(pdf).to_s
3535
escaped_pdf = ESCAPE[pdf]
36-
FileUtils.mkdir_p(directory) unless File.exists?(directory)
36+
FileUtils.mkdir_p(directory) unless File.exist?(directory)
3737
common = "#{MEMORY_ARGS} -density #{@density} #{resize_arg(size)} #{quality_arg(format)}"
3838
if previous
3939
FileUtils.cp(Dir[directory_for(previous) + '/*'], directory)
@@ -48,7 +48,7 @@ def convert(pdf, size, format, previous=nil)
4848
end
4949
end
5050
ensure
51-
FileUtils.remove_entry_secure tempdir if File.exists?(tempdir)
51+
FileUtils.remove_entry_secure tempdir if File.exist?(tempdir)
5252
end
5353

5454

lib/docsplit/page_extractor.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ def extract(pdfs, opts)
1010
[pdfs].flatten.each do |pdf|
1111
pdf_name = File.basename(pdf, File.extname(pdf))
1212
page_path = ESCAPE[File.join(@output, "#{pdf_name}")] + "_%d.pdf"
13-
FileUtils.mkdir_p @output unless File.exists?(@output)
14-
13+
FileUtils.mkdir_p @output unless File.exist?(@output)
14+
1515
cmd = if DEPENDENCIES[:pdftailor] # prefer pdftailor, but keep pdftk for backwards compatability
1616
"pdftailor unstitch --output #{page_path} #{ESCAPE[pdf]} 2>&1"
1717
else
1818
"pdftk #{ESCAPE[pdf]} burst output #{page_path} 2>&1"
1919
end
2020
result = `#{cmd}`.chomp
21-
FileUtils.rm('doc_data.txt') if File.exists?('doc_data.txt')
21+
FileUtils.rm('doc_data.txt') if File.exist?('doc_data.txt')
2222
raise ExtractionFailed, result if $? != 0
2323
result
2424
end

lib/docsplit/pdf_extractor.rb

+15-15
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def osx?
1616
def linux?
1717
!!HOST_OS.match(/linux/i)
1818
end
19-
19+
2020
# The first line of the help output holds the name and version number
2121
# of the office software to be used for extraction.
2222
def version_string
@@ -35,10 +35,10 @@ def libre_office?
3535
def open_office?
3636
!!version_string.match(/^OpenOffice.org/)
3737
end
38-
38+
3939
# A set of default locations to search for office software
4040
# These have been extracted from JODConverter. Each listed
41-
# path should contain a directory "program" which in turn
41+
# path should contain a directory "program" which in turn
4242
# contains the "soffice" executable.
4343
# see: https://github.com/mirkonasato/jodconverter/blob/master/jodconverter-core/src/main/java/org/artofsolving/jodconverter/office/OfficeUtils.java#L63-L91
4444
def office_search_paths
@@ -69,7 +69,7 @@ def office_search_paths
6969
end
7070
search_paths
7171
end
72-
72+
7373
# Identify the path to a working office executable.
7474
def office_executable
7575
paths = office_search_paths
@@ -78,10 +78,10 @@ def office_executable
7878
# raise an error if that path isn't valid, otherwise, add
7979
# it to the front of our search paths.
8080
if ENV['OFFICE_PATH']
81-
raise ArgumentError, "No such file or directory #{ENV['OFFICE_PATH']}" unless File.exists? ENV['OFFICE_PATH']
81+
raise ArgumentError, "No such file or directory #{ENV['OFFICE_PATH']}" unless File.exist? ENV['OFFICE_PATH']
8282
paths.unshift(ENV['OFFICE_PATH'])
8383
end
84-
84+
8585
# The location of the office executable is OS dependent
8686
path_pieces = ["soffice"]
8787
if windows?
@@ -91,32 +91,32 @@ def office_executable
9191
else
9292
path_pieces += [["program", "soffice"]]
9393
end
94-
94+
9595
# Search for the first suitable office executable
9696
# and short circuit an executable is found.
9797
paths.each do |path|
98-
if File.exists? path
98+
if File.exist? path
9999
@@executable ||= path unless File.directory? path
100100
path_pieces.each do |pieces|
101101
check_path = File.join(path, pieces)
102-
@@executable ||= check_path if File.exists? check_path
102+
@@executable ||= check_path if File.exist? check_path
103103
end
104104
end
105105
break if @@executable
106106
end
107107
raise OfficeNotFound, "No office software found" unless @@executable
108108
@@executable
109109
end
110-
110+
111111
# Used to specify the office location for JODConverter
112112
def office_path
113113
File.dirname(File.dirname(office_executable))
114114
end
115-
115+
116116
# Convert documents to PDF.
117117
def extract(docs, opts)
118118
out = opts[:output] || '.'
119-
FileUtils.mkdir_p out unless File.exists?(out)
119+
FileUtils.mkdir_p out unless File.exist?(out)
120120
[docs].flatten.each do |doc|
121121
ext = File.extname(doc)
122122
basename = File.basename(doc, ext)
@@ -128,7 +128,7 @@ def extract(docs, opts)
128128
if libre_office?
129129
# Set the LibreOffice user profile, so that parallel uses of cloudcrowd don't trip over each other.
130130
ENV['SYSUSERCONFIG']="file://#{File.expand_path(escaped_out)}"
131-
131+
132132
options = "--headless --invisible --norestore --nolockcheck --convert-to pdf --outdir #{escaped_out} #{escaped_doc}"
133133
cmd = "#{office_executable} #{options} 2>&1"
134134
result = `#{cmd}`.chomp
@@ -147,9 +147,9 @@ def extract(docs, opts)
147147
LOGGING = "-Djava.util.logging.config.file=#{ESCAPED_ROOT}/vendor/logging.properties"
148148

149149
HEADLESS = "-Djava.awt.headless=true"
150-
150+
151151
private
152-
152+
153153
# Runs a Java command, with quieted logging, and the classpath set properly.
154154
def run_jod(command, pdfs, opts, return_output=false)
155155

lib/docsplit/text_extractor.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def initialize
2828
# Extract text from a list of PDFs.
2929
def extract(pdfs, opts)
3030
extract_options opts
31-
FileUtils.mkdir_p @output unless File.exists?(@output)
31+
FileUtils.mkdir_p @output unless File.exist?(@output)
3232
[pdfs].flatten.each do |pdf|
3333
@pdf_name = File.basename(pdf, File.extname(pdf))
3434
pages = (@pages == 'all') ? 1..Docsplit.extract_length(pdf) : @pages
@@ -80,7 +80,7 @@ def extract_from_ocr(pdf, pages)
8080
clean_text(base_path + '.txt') if @clean_ocr
8181
end
8282
ensure
83-
FileUtils.remove_entry_secure tempdir if File.exists?(tempdir)
83+
FileUtils.remove_entry_secure tempdir if File.exist?(tempdir)
8484
end
8585

8686

test/test_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Minitest::Test
1010
OUTPUT = 'test/output'
1111

1212
def clear_output
13-
FileUtils.rm_r(OUTPUT) if File.exists?(OUTPUT)
13+
FileUtils.rm_r(OUTPUT) if File.exist?(OUTPUT)
1414
end
1515

1616
def teardown

0 commit comments

Comments
 (0)