Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML Units Checker #25236

Merged
merged 1 commit into from Nov 15, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
69 changes: 69 additions & 0 deletions DetectorDescription/DDCMS/test/python/UnitsCheck.py
@@ -0,0 +1,69 @@
import fileinput
import re

def index(line,substr):
result = line.index(substr)
return result

def errorPrint(line,indices):
print(line)
ll = len(line)
errstr="_"*ll
for i in indices:
errstr = errstr[:i] + '^' + errstr[i+1:]
print errstr

def findValuesWithUnits(line,ln):
numList = re.findall(r"\d*?[\s,.]?\d*\*\w*", line)
errindices = []
for match in re.finditer(r"\d*?[\s,.]?\d*\*\w*", line):
errindices.append(match.start())
l = len(numList)
if l > 0:
print 'Line #',ln,'Units defined: '
errorPrint(line,errindices)
return l

def findIndices(line,strList):
indices=[]
for x in strList:
idx = index(line,x)
indices.append(idx)
print(indices)
return indices

def findValuesWithoutUnits(line,ln):
numList = re.findall(r"\d+?[\s,.]?\d+[\s\"]", line)
errindices = []
for match in re.finditer(r"\d+?[\s,.]?\d+[\s\"]", line):
errindices.append(match.start())
l = len(numList)
if l > 0:
print 'Line #', ln, 'WARNING: Numerical values without units: '
errorPrint(line,errindices)
return l

def lineNumber(lookup):
with open(fileinput.filename()) as myfile:
for num, line in enumerate(myfile, 1):
if lookup in line:
return num

def process(line):
ln = lineNumber(line)
l = findValuesWithUnits(line,ln)
k = findValuesWithoutUnits(line,ln)
if l > 0 or k > 0:
print ' '

def check(line):
return 0;

for line in fileinput.input():
check(line)

with open(fileinput.filename()) as myfile:
for num, line in enumerate(myfile, 1):
process(line)