#! /usr/bin/env python

##############################################################################
#
# Copyright (C) Zenoss, Inc. 2013, all rights reserved.
#
# This content is made available according to terms specified in the LICENSE
# file at the top-level directory of this package.
#
##############################################################################

import sys
import os
from itertools import chain
from subprocess import check_output

python_files = chain.from_iterable(
    [os.path.join(root, fname) for fname in fnames if fname.endswith('.py')]
    for root, dirs, fnames in os.walk('txwinrm')
)

command = ['cyclic_complexity/pygenie.py', 'complexity']
command.extend(python_files)
output = check_output(command)

exit_code = 0
for line in output.splitlines():
    line = line.strip()
    if not line:
        continue
    print line
    if line.startswith('File:') \
            or line == "This code looks all good!":
        continue
    exit_code = 1

sys.exit(exit_code)
