1*7078Smjnelson# 2*7078Smjnelson# CDDL HEADER START 3*7078Smjnelson# 4*7078Smjnelson# The contents of this file are subject to the terms of the 5*7078Smjnelson# Common Development and Distribution License (the "License"). 6*7078Smjnelson# You may not use this file except in compliance with the License. 7*7078Smjnelson# 8*7078Smjnelson# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*7078Smjnelson# or http://www.opensolaris.org/os/licensing. 10*7078Smjnelson# See the License for the specific language governing permissions 11*7078Smjnelson# and limitations under the License. 12*7078Smjnelson# 13*7078Smjnelson# When distributing Covered Code, include this CDDL HEADER in each 14*7078Smjnelson# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*7078Smjnelson# If applicable, add the following below this CDDL HEADER, with the 16*7078Smjnelson# fields enclosed by brackets "[]" replaced with your own identifying 17*7078Smjnelson# information: Portions Copyright [yyyy] [name of copyright owner] 18*7078Smjnelson# 19*7078Smjnelson# CDDL HEADER END 20*7078Smjnelson# 21*7078Smjnelson 22*7078Smjnelson# 23*7078Smjnelson# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24*7078Smjnelson# Use is subject to license terms. 25*7078Smjnelson# 26*7078Smjnelson# ident "%Z%%M% %I% %E% SMI" 27*7078Smjnelson# 28*7078Smjnelson 29*7078Smjnelson# 30*7078Smjnelson# JStyle, wrap the jstyle tool in a pythonic API 31*7078Smjnelson# 32*7078Smjnelson 33*7078Smjnelsonimport sys 34*7078Smjnelsonfrom onbld.Checks.ProcessCheck import processcheck 35*7078Smjnelson 36*7078Smjnelson 37*7078Smjnelsondef jstyle(fh, filename=None, output=sys.stderr, **opts): 38*7078Smjnelson opttrans = {'check_continuation': '-c', 39*7078Smjnelson 'heuristic': '-h', 40*7078Smjnelson 'picky': '-p', 41*7078Smjnelson 'ignore_hdr_comment': '-C', 42*7078Smjnelson 'verbose': '-v', 43*7078Smjnelson 'tabs': '-t'} 44*7078Smjnelson 45*7078Smjnelson for x in filter(lambda x: x not in opttrans, opts): 46*7078Smjnelson raise TypeError('jstyle() got an unexpected keyword ' 47*7078Smjnelson 'argument %s' % x) 48*7078Smjnelson 49*7078Smjnelson options = [opttrans[x] for x in opts if opts[x]] 50*7078Smjnelson 51*7078Smjnelson if not filename: 52*7078Smjnelson filename = fh.name 53*7078Smjnelson 54*7078Smjnelson ret, tmpfile = processcheck('jstyle', options, fh, output) 55*7078Smjnelson 56*7078Smjnelson if tmpfile: 57*7078Smjnelson for line in tmpfile: 58*7078Smjnelson line = line.replace('<stdin>', filename) 59*7078Smjnelson output.write(line) 60*7078Smjnelson 61*7078Smjnelson tmpfile.close() 62*7078Smjnelson 63*7078Smjnelson return ret 64