SHA256
1
0
forked from pool/rpmlint
rpmlint/BashismsCheck.py
OBS User autobuild f7d2015dce Accepting request 44204 from Base:System
Copy from Base:System/rpmlint based on submit request 44204 from user dirkmueller

OBS-URL: https://build.opensuse.org/request/show/44204
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/rpmlint?expand=0&rev=67
2010-08-01 15:30:35 +00:00

45 lines
1.5 KiB
Python

#############################################################################
# File : BashismsCheck.py
# Package : rpmlint
# Author : Guido Berhoerster
# Purpose : check /bin/sh shell scripts for bashisms
#############################################################################
import re
import AbstractCheck
import Config
import Pkg
from Filter import *
class BashismsCheck(AbstractCheck.AbstractFilesCheck):
RE_BIN_SH = re.compile('#!\s*(/usr)?/bin/sh(\s+|$)')
def __init__(self):
AbstractCheck.AbstractFilesCheck.__init__(self, "BashismsCheck", ".*")
def check_file(self, pkg, filename):
try:
f = open(filename)
except:
return
try:
first_line = f.read(256).split("\n")[0]
if self.RE_BIN_SH.match(first_line):
status, output = Pkg.getstatusoutput(["dash", "-n", filename])
if status == 2:
printWarning(pkg, "bin-sh-syntax-error", filename)
status, output = Pkg.getstatusoutput(["checkbashisms", filename])
if status == 1:
printInfo(pkg, "potential-bashisms", filename)
finally:
f.close()
check = BashismsCheck()
if Config.info:
addDetails('bin-sh-syntax-error',
'''A /bin/sh shell script contains a syntax error.''',
'potential-bashisms',
'''checkbashisms reported potential bashisms in a /bin/sh shell
script, you might want to manually check this script for bashisms.''')