Ejemplo n.º 1
0
def check_tidy(src_dir):
    count_lines = 0
    count_empty_lines = 0

    for (dirpath, dirnames, filenames) in os.walk(src_dir):
        if any(d in fs.relpath(dirpath, src_dir) for d in skip_dirs):
            continue

        files = [
            fs.join(dirpath, name) for name in filenames
            if is_interesting(name)
        ]

        if not files:
            continue

        for file in files:
            if is_checked_by_clang(file):
                formatted = ex.run_cmd_output(' '.join(
                    ['clang-format-3.8', '-style=file', file]),
                                              quiet=True)
                f = open(file + '.formatted', 'w')
                f.write(formatted)
                f.close()
                ex.check_run_cmd('diff', [file, file + '.formatted'],
                                 quiet=True)
                fs.remove(file + '.formatted')

        for line in fileinput.input(files):
            if '\t' in line:
                report_error('TAB character')
            if '\r' in line:
                report_error('CR character')
            if line.endswith(' \n') or line.endswith('\t\n'):
                report_error('trailing whitespace')
            if not line.endswith('\n'):
                report_error('line ends without NEW LINE character')

            if len(line) - 1 > column_limit:
                report_error('line exceeds %d characters' % column_limit)

            if fileinput.isfirstline():
                if not CheckLicenser.check(fileinput.filename()):
                    report_error_name_line(fileinput.filename(), None,
                                           'incorrect license')

            count_lines += 1
            if not line.strip():
                count_empty_lines += 1

    print "* total lines of code: %d" % count_lines
    print("* total non-blank lines of code: %d" %
          (count_lines - count_empty_lines))
    print "%s* total errors: %d%s" % (TERM_RED if count_err > 0 else
                                      TERM_GREEN, count_err, TERM_EMPTY)
    print

    return count_err == 0
Ejemplo n.º 2
0
def check_change(path):
    '''Check if current pull request depends on path,
    return `False` if not depends, else if depends.'''
    if os.getenv('TRAVIS_PULL_REQUEST') == 'false':
        return True
    travis_branch = os.getenv('TRAVIS_BRANCH')
    commit_diff = ex.run_cmd_output(
        'git', ['diff', '--name-only', 'HEAD..origin/' + travis_branch], True)
    return commit_diff.find(path) != -1
Ejemplo n.º 3
0
    def check(self, files):
        if not self._clang_format:
            return

        for file in filter(self.is_checked_by_clang, files):
            output = ex.run_cmd_output(self._clang_format,
                                       ['-style=file', file],
                                       quiet=True)

            with tempfile.NamedTemporaryFile() as temp:
                temp.write(output)
                temp.flush()  # just to be really safe
                self._diff(file, temp.name)
Ejemplo n.º 4
0
    def check(self, files):
        if not self._clang_format:
            return

        for file in filter(self.is_checked_by_clang, files):
            args = ['-style=file', file]
            if self._options and self._options.autoedit:
                args.append('-i')
            output = ex.run_cmd_output(self._clang_format, args, quiet=True)

            if output:
                with tempfile.NamedTemporaryFile() as temp:
                    temp.write(output)
                    temp.flush()  # just to be really safe
                    self._diff(file, temp.name)
Ejemplo n.º 5
0
    def check(self):
        self.error_count = 0

        if not self._node or not self._eslint:
            return
        args = ['src', '-f', 'codeframe']
        if self._options and self._options.autoedit:
            args.append('--fix')

        output = ex.run_cmd_output(self._eslint, args, quiet=True)
        match = re.search('(\d+) error', output)
        if match:
            self.error_count = int(match.group(1))

        # Delete unnecessary error messages.
        self.errors = output.split('\n')[:-4]
Ejemplo n.º 6
0
    def check(self):
        self.error_count = 0

        if not self._node or not self._eslint:
            return
        args = ['src', '-f', 'codeframe']
        if self._options and self._options.autoedit:
             args.append('--fix')

        output = ex.run_cmd_output(self._eslint, args, quiet=True)
        match = re.search('(\d+) error', output)
        if match:
            self.error_count = int(match.group(1))

        # Delete unnecessary error messages.
        self.errors = output.split('\n')[:-4]
Ejemplo n.º 7
0
    def check(self, files):
        if not self._clang_format:
            return

        for file in filter(self.is_checked_by_clang, files):
            args = ['-style=file', file]
            if self._options and self._options.autoedit:
                args.append('-i')
            output = ex.run_cmd_output(self._clang_format,
                                       args,
                                       quiet=True)

            if output:
                with tempfile.NamedTemporaryFile() as temp:
                    temp.write(output)
                    temp.flush() # just to be really safe
                    self._diff(file, temp.name)
Ejemplo n.º 8
0
    def __init__(self, options):
        self.iotjs = options.iotjs
        self.quiet = options.quiet
        self.timeout = options.timeout
        self.valgrind = options.valgrind
        self.skip_modules = []
        self.results = {}

        if options.skip_modules:
            self.skip_modules = options.skip_modules.split(",")

        # Process the iotjs build information.
        iotjs_output = ex.run_cmd_output(self.iotjs, [path.BUILD_INFO_PATH])
        build_info = json.loads(iotjs_output)

        self.builtins = build_info["builtins"]
        self.stability = build_info["stability"]

        # Define own alarm handler to handle timeout.
        signal.signal(signal.SIGALRM, alarm_handler)
Ejemplo n.º 9
0
    def __init__(self, options):
        self.iotjs = fs.abspath(options.iotjs)
        self.quiet = options.quiet
        self.timeout = options.timeout
        self.valgrind = options.valgrind
        self.coverage = options.coverage
        self.skip_modules = []
        self.results = {}

        if options.skip_modules:
            self.skip_modules = options.skip_modules.split(",")

        # Process the iotjs build information.
        iotjs_output = ex.run_cmd_output(self.iotjs, [path.BUILD_INFO_PATH])
        build_info = json.loads(iotjs_output)

        self.builtins = build_info["builtins"]
        self.stability = build_info["stability"]

        # Define own alarm handler to handle timeout.
        signal.signal(signal.SIGALRM, alarm_handler)
Ejemplo n.º 10
0
def git_check_master():
    return not ex.run_cmd_output('git diff master origin/master')
Ejemplo n.º 11
0
def git_current_branch():
    return ex.run_cmd_output('git rev-parse --abbrev-ref HEAD')
Ejemplo n.º 12
0
def git_cache_credential():
    return ex.run_cmd_output('git config --global credential.helper cache')
Ejemplo n.º 13
0
def git_check_master():
    return not ex.run_cmd_output('git diff master origin/master')
Ejemplo n.º 14
0
def git_current_branch():
    return ex.run_cmd_output('git rev-parse --abbrev-ref HEAD')
Ejemplo n.º 15
0
def git_cache_credential():
    return ex.run_cmd_output('git config --global credential.helper cache')