def get_tracking_remote(): branch = [GitExe(), "branch", "-vv", "-a"] # The output of git branch -vv will be in format # * <branch> <hash> [<remote>: ahead <n>, behind <m>] <subject> # <branch> <hash> <subject> output = GetCommandOutput(branch) branches = output.split("\n") for branch in branches: # we only need active branch first. if not branch.startswith("*"): continue detail = branch[1:].strip().split(" ", 1)[1].strip().split(" ", 1)[1].strip() if detail.startswith("["): remote = detail[1:].split("]", 1)[0] remote = remote.split(":", 1)[0].strip() # verify that remotes/branch or branch is a real branch # There is still chance that developer named his commit # as [origin/branch], in this case exists = [ r_branch for r_branch in branches if r_branch.strip().startswith("remotes/" + remote) or r_branch.strip().startswith(remote) ] if len(exists) == 0: remote = "" else: remote = "" break if remote == "": if repo_is_dirty(): remote = "HEAD" else: remote = "HEAD~" print "Base is not specified, " "will use %s as comparasion base for linting" % remote return remote
def get_change_file_list(base): diff = [GitExe(), 'diff', '--name-only', base] output = GetCommandOutput(diff) changes = [line.strip() for line in output.strip().split('\n')] pyfiles = [] others = [] # pylint: disable=W0612 for change in changes: root, ext = os.path.splitext(change) if ext.lower() in PYTHON_EXTS: pyfiles.append(change) else: others.append(change) return pyfiles, others
def do_js_lint(changeset): print '\n_____ do JavaScript lint' if sys.platform.startswith('win'): jslint_cmd = ['gjslint.exe'] else: jslint_cmd = ['gjslint'] error_count = 0 for jsfile in changeset: if os.path.exists(jsfile) != True: print "Skipping file %s: File doesn't exist." % jsfile continue args = [ '--strict', '--nojsdoc', '--max_line_length', '100', '--unix_mode' ] js_dir, js_name = os.path.split(os.path.abspath(jsfile)) previous_cwd = os.getcwd() os.chdir(js_dir) print 'jslint %s' % jsfile args.append(js_name) try: output = GetCommandOutput(jslint_cmd + args).strip() if len(output) > 0: print output else: error_count += 1 except Exception, e: print e error_count += 1 os.chdir(previous_cwd)
def do_py_lint(changeset): print '_____ do python lint' if sys.platform.startswith('win'): pylint_cmd = ['pylint.bat'] else: pylint_cmd = ['pylint'] _has_import_error = False error_count = 0 for pyfile in changeset: if os.path.exists(pyfile) != True: print "Skipping file %s: File doesn't exist." % pyfile continue py_dir, py_name = os.path.split(os.path.abspath(pyfile)) previous_cwd = os.getcwd() os.chdir(py_dir) print 'pylint %s' % pyfile try: output = GetCommandOutput(pylint_cmd + [py_name]).strip() if len(output) > 0: print output else: error_count += 1 except Exception, e: if not _has_import_error and \ 'F0401:' in [error[:6] for error in str(e).splitlines()]: _has_import_error = True print e error_count += 1 os.chdir(previous_cwd)
def get_change_file_list(base): diff = [GitExe(), 'diff', '--name-only', base] output = GetCommandOutput(diff) changes = [line.strip() for line in output.strip().split('\n')] pyfiles = [] jsfiles = [] others = [] common_regex = re.compile('common') # pylint: disable=W0612 for change in changes: root, ext = os.path.splitext(change) if common_regex.match(os.path.dirname(change)): print 'Skip common dir' continue if ext.lower() in PYTHON_EXTS: pyfiles.append(change) elif ext.lower() in JS_EXTS: jsfiles.append(change) else: others.append(change) return pyfiles, jsfiles, others
def get_tracking_remote(): branch = [GitExe(), 'branch', '-vv', '-a'] # The output of git branch -vv will be in format # * <branch> <hash> [<remote>: ahead <n>, behind <m>] <subject> # <branch> <hash> <subject> output = GetCommandOutput(branch) branches = output.split('\n') for branch in branches: # we only need active branch first. if not branch.startswith('*'): continue detail = \ branch[1:].strip().split(' ', 1)[1].strip().split(' ', 1)[1].strip() if detail.startswith('['): remote = detail[1:].split(']', 1)[0] remote = remote.split(':', 1)[0].strip() # verify that remotes/branch or branch is a real branch # There is still chance that developer named his commit # as [origin/branch], in this case exists = [ r_branch for r_branch in branches if r_branch.strip().startswith('remotes/' + remote) or r_branch.strip().startswith(remote) ] if len(exists) == 0: remote = '' else: remote = '' break if remote == '': if repo_is_dirty(): remote = 'HEAD' else: remote = 'HEAD~' print 'Base is not specified, '\ 'will use %s as comparasion base for linting' % remote return remote
def get_change_file_list(base, ignore_array): diff = [GitExe(), "diff", "--name-only", base] output = GetCommandOutput(diff) changes = [line.strip() for line in output.strip().split("\n")] pyfiles = [] jsfiles = [] others = [] common_regex = re.compile("common") # pylint: disable=W0612 for change in changes: if change in ignore_array: print "Linting for %s ignored!" % change continue root, ext = os.path.splitext(change) if common_regex.match(os.path.dirname(change)): print "Skip common dir" continue if ext.lower() in PYTHON_EXTS: pyfiles.append(change) elif ext.lower() in JS_EXTS: jsfiles.append(change) else: others.append(change) return pyfiles, jsfiles, others
def get_tracking_remote(): branch = [GitExe(), 'branch', '-vv', '-a'] # The output of git branch -vv will be in format # * <branch> <hash> [<remote>: ahead <n>, behind <m>] <subject> # <branch> <hash> <subject> output = GetCommandOutput(branch) branches = output.split('\n') for branch in branches: # we only need active branch first. if not branch.startswith('*'): continue detail = \ branch[1:].strip().split(' ', 1)[1].strip().split(' ', 1)[1].strip() if detail.startswith('['): remote = detail[1:].split(']', 1)[0] remote = remote.split(':', 1)[0].strip() # verify that remotes/branch or branch is a real branch # There is still chance that developer named his commit # as [origin/branch], in this case exists = [\ r_branch for r_branch in branches \ if r_branch.strip().startswith('remotes/'+remote) or \ r_branch.strip().startswith(remote)] if len(exists) == 0: remote = '' else: remote = '' break if remote == '': if repo_is_dirty(): remote = 'HEAD' else: remote = 'HEAD~' print 'Base is not specified, '\ 'will use %s as comparasion base for linting' % remote return remote
def do_py_lint(changeset): print '_____ do python lint' pylint_cmd = ['pylint'] _has_import_error = False for pyfile in changeset: py_dir, py_name = os.path.split(os.path.abspath(pyfile)) previous_cwd = os.getcwd() os.chdir(py_dir) print 'pylint %s' % pyfile try: output = GetCommandOutput(pylint_cmd + [py_name]).strip() if len(output) > 0: print output except Exception, e: if not _has_import_error and \ 'F0401:' in [error[:6] for error in str(e).splitlines()]: _has_import_error = True print e os.chdir(previous_cwd)
def repo_is_dirty(): return GetCommandOutput([GitExe(), 'diff', 'HEAD']).strip() != ''