Skip to content

Commit f752b71

Browse files
authored
Merge pull request #42 from svenkreiss/javanotfound
improve check for Java
2 parents b0d9259 + 437786b commit f752b71

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

html5validator/validator.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
class JavaNotFoundException(Exception):
2020
def __str__(self):
21-
return 'Missing Java Runtime Environment on this system. ' +\
22-
'The command "java" must be available.'
21+
return ('Missing Java Runtime Environment on this system. ' +
22+
'The command "java" must be available.')
2323

2424

2525
class Validator(object):
@@ -113,22 +113,21 @@ def all_files(self, skip_invisible=True):
113113
def validate(self, files=None):
114114
if not files:
115115
files = self.all_files()
116-
117116
if sys.platform == 'cygwin':
118117
files = [self._cygwin_path_convert(f) for f in files]
119118

120-
with open(os.devnull, 'w') as f_null:
121-
if subprocess.call(['java', '-version'],
122-
stdout=f_null, stderr=f_null) != 0:
123-
raise JavaNotFoundException()
124-
125119
try:
126120
cmd = (['java'] + self._java_options +
127121
['-jar', self.vnu_jar_location] + self._vnu_options + files)
128122
o = subprocess.check_output(
129123
cmd,
130124
stderr=subprocess.STDOUT,
131125
).decode('utf-8')
126+
except OSError as e:
127+
if e.errno == os.errno.ENOENT:
128+
raise JavaNotFoundException()
129+
else:
130+
raise
132131
except subprocess.CalledProcessError as e:
133132
o = e.output.decode('utf-8')
134133

0 commit comments

Comments
 (0)