Skip to content

Commit

Permalink
validate.py: show error if "xmllint" is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
cpina committed Jan 1, 2021
1 parent d9b2f90 commit 1de2ccc
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions tools/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@ def print_buffered_reader(buffered_reader):


def validate_file(dtd_path, file_path, *, verbose):
with subprocess.Popen(['xmllint', '--noout', '--dtdvalid', dtd_path, file_path],
stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc:
if verbose:
print_buffered_reader(proc.stdout)
print_buffered_reader(proc.stderr)
xmllint_bin = 'xmllint'
try:
proc = subprocess.Popen([xmllint_bin, '--noout', '--dtdvalid', dtd_path, file_path],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except FileNotFoundError:
print(
f'{xmllint_bin} needs to be available in the path. In Debian based systems is available in the package "libxml2-utils"', sys.stderr)
sys.exit(2)
if verbose:
print_buffered_reader(proc.stdout)
print_buffered_reader(proc.stderr)

proc.communicate()
proc.communicate()

return proc.returncode == 0
return proc.returncode == 0


def validate_directory(dtd_path, directory_path):
Expand All @@ -48,6 +54,7 @@ def validate_directory(dtd_path, directory_path):
print('Total files:', total_files)
print('Invalid files:', invalid_files)


def validate(dtd_path, path):
if not os.path.isfile(dtd_path):
print(f'Make sure that {dtd_path} is a DTD file')
Expand Down

0 comments on commit 1de2ccc

Please sign in to comment.