import logging import os import subprocess # Create Cppcheck project file def create_gui_project_file(project_file, root_path=None, import_project=None, paths=None, exclude_paths=None, suppressions=None, addon=None): cppcheck_xml = ('\n' '\n') if root_path: cppcheck_xml += ' \n' if import_project: cppcheck_xml += ' ' + import_project + '\n' if paths: cppcheck_xml += ' \n' for path in paths: cppcheck_xml += ' \n' cppcheck_xml += ' \n' if exclude_paths: cppcheck_xml += ' \n' for path in exclude_paths: cppcheck_xml += ' \n' cppcheck_xml += ' \n' if suppressions: cppcheck_xml += ' \n' for suppression in suppressions: cppcheck_xml += ' \n' cppcheck_xml += ' \n' if addon: cppcheck_xml += ' \n' cppcheck_xml += ' %s\n' % (addon) cppcheck_xml += ' \n' cppcheck_xml += '\n' f = open(project_file, 'wt') f.write(cppcheck_xml) f.close() # Run Cppcheck with args def cppcheck(args): exe = None if os.path.isfile('../../bin/debug/cppcheck.exe'): exe = '../../bin/debug/cppcheck.exe' elif os.path.isfile('../../../bin/debug/cppcheck.exe'): exe = '../../../bin/debug/cppcheck.exe' elif os.path.isfile('../../cppcheck'): exe = '../../cppcheck' else: exe = '../../../cppcheck' logging.info(exe + ' ' + ' '.join(args)) p = subprocess.Popen([exe] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) comm = p.communicate() stdout = comm[0].decode(encoding='utf-8', errors='ignore').replace('\r\n', '\n') stderr = comm[1].decode(encoding='utf-8', errors='ignore').replace('\r\n', '\n') return p.returncode, stdout, stderr