in cbmc_viewer/sourcet.py [0:0]
def sloc(files, root):
"""Run sloc on a list of files under root."""
loc = {}
sources = files
while sources:
files = sources[:100]
sources = sources[100:]
logging.info('Running sloc on %s files starting with %s...',
len(files),
files[0])
command = ['sloc', '-f', 'json'] + files
logging.debug('sloc: %s', ' '.join(command))
try:
result = runt.run(command, root)
except FileNotFoundError as error:
# handle sloc command not found
logging.info('sloc not found: %s', error.strerror)
return None
except OSError as error:
# handle sloc argument list too long
if error.errno != 7: # errno==7 is 'Argument list too long'
raise
logging.info('sloc argument list too long: %s', error.strerror)
return None
except subprocess.CalledProcessError as error:
# handle sloc error generated by running sloc
logging.info('Unable to run sloc: %s', error.stderr)
return None
# sloc produces useful data in addition to the summary
data = json.loads(result)['summary']
for key, val in data.items():
loc[key] = int(val) + loc.get(key, 0)
return loc