xref: /illumos-gate/usr/src/tools/scripts/wscheck.py (revision 3f770aab)
1*3f770aabSAndy Fiddaman#!@TOOLS_PYTHON@ -Es
24ff15898SGordon Ross#
34ff15898SGordon Ross# CDDL HEADER START
44ff15898SGordon Ross#
54ff15898SGordon Ross# The contents of this file are subject to the terms of the
64ff15898SGordon Ross# Common Development and Distribution License (the "License").
74ff15898SGordon Ross# You may not use this file except in compliance with the License.
84ff15898SGordon Ross#
94ff15898SGordon Ross# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
104ff15898SGordon Ross# or http://www.opensolaris.org/os/licensing.
114ff15898SGordon Ross# See the License for the specific language governing permissions
124ff15898SGordon Ross# and limitations under the License.
134ff15898SGordon Ross#
144ff15898SGordon Ross# When distributing Covered Code, include this CDDL HEADER in each
154ff15898SGordon Ross# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
164ff15898SGordon Ross# If applicable, add the following below this CDDL HEADER, with the
174ff15898SGordon Ross# fields enclosed by brackets "[]" replaced with your own identifying
184ff15898SGordon Ross# information: Portions Copyright [yyyy] [name of copyright owner]
194ff15898SGordon Ross#
204ff15898SGordon Ross# CDDL HEADER END
214ff15898SGordon Ross#
224ff15898SGordon Ross
234ff15898SGordon Ross#
244ff15898SGordon Ross# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
25ca13eaa5SAndy Fiddaman# Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
264ff15898SGordon Ross#
274ff15898SGordon Ross
284ff15898SGordon Ross#
294ff15898SGordon Ross# Check file for whitespace issues
304ff15898SGordon Ross# (space tab, trailing space)
314ff15898SGordon Ross#
324ff15898SGordon Ross
33ca13eaa5SAndy Fiddamanimport sys, os, io
344ff15898SGordon Ross
354ff15898SGordon Rosssys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "lib",
364ff15898SGordon Ross                                "python%d.%d" % sys.version_info[:2]))
374ff15898SGordon Ross
384ff15898SGordon Ross# Allow running from the source tree, using the modules in the source tree
394ff15898SGordon Rosssys.path.insert(2, os.path.join(os.path.dirname(__file__), '..'))
404ff15898SGordon Ross
414ff15898SGordon Rossfrom onbld.Checks.WsCheck import wscheck
424ff15898SGordon Ross
434ff15898SGordon Rossret = 0
444ff15898SGordon Rossfor filename in sys.argv[1:]:
454ff15898SGordon Ross	try:
46ca13eaa5SAndy Fiddaman		with io.open(filename, encoding='utf-8',
47ca13eaa5SAndy Fiddaman		    errors='replace') as fh:
48ca13eaa5SAndy Fiddaman			ret |= wscheck(fh, output=sys.stderr)
49ca13eaa5SAndy Fiddaman	except IOError as e:
504ff15898SGordon Ross		sys.stderr.write("failed to open '%s': %s\n" %
514ff15898SGordon Ross				 (e.filename, e.strerror))
52ca13eaa5SAndy Fiddaman		continue
534ff15898SGordon Ross
544ff15898SGordon Rosssys.exit(ret)
55