Ejemplo n.º 1
0
def runpylint(paths, verbosity=1):
    if verbosity > 0:
        print >> sys.stderr, '### pylint'

    if not paths:
        paths = ['.']

    # give helpful error if pylint is not installed
    ret = os.system('pylint --help > /dev/null 2>&1')
    if ret != 0:
        print >> sys.stderr, "\nWARNING: can't run pylint command -- try 'pip install pylint'\n"
        sys.exit(1)

    # use <site>/management/pylintrc.txt as rcfile if it exists
    if verbosity > 1:
        print >> sys.stderr, 'checking for pylint flags in %s' % CONFIG_FILE
    if os.path.exists(CONFIG_FILE):
        flags = '--rcfile %s' % CONFIG_FILE
    else:
        flags = DEFAULT_FLAGS

    cmd = 'pylint %s' % flags
    if verbosity > 2:
        xargsFlags = '--verbose'
    else:
        xargsFlags = ''

    exitCode = 0
    for path in paths:
        path = os.path.relpath(path)
        if os.path.isdir(path):
            findCmd = 'find %s -name "*.py"' % path
            rawPathsText = os.popen(findCmd).read()
            pathsText = lintignore(rawPathsText)
            if verbosity > 1:
                print >> sys.stderr, 'findCmd:', findCmd
                print >> sys.stderr, 'rawPathsText:\n' + rawPathsText
                print >> sys.stderr, '\npathsText:\n' + pathsText
            ret = pipeToCommand(
                'xargs %s --no-run-if-empty -n20 -d"\n" %s' %
                (xargsFlags, cmd), pathsText, verbosity)
            if ret != 0:
                exitCode = 1
        else:
            ret = dosys('%s %s' % (cmd, path), verbosity)
            if ret != 0:
                exitCode = 1

    return exitCode
Ejemplo n.º 2
0
def runpylint(paths, verbosity=1):
    if verbosity > 0:
        print >> sys.stderr, '### pylint'

    if not paths:
        paths = ['.']

    # give helpful error if pylint is not installed
    ret = os.system('pylint --help > /dev/null 2>&1')
    if ret != 0:
        print >> sys.stderr, "\nWARNING: can't run pylint command -- try 'pip install pylint'\n"
        sys.exit(1)

    # use <site>/management/pylintrc.txt as rcfile if it exists
    if verbosity > 1:
        print >> sys.stderr, 'checking for pylint flags in %s' % CONFIG_FILE
    if os.path.exists(CONFIG_FILE):
        flags = '--rcfile %s' % CONFIG_FILE
    else:
        flags = DEFAULT_FLAGS

    cmd = 'pylint %s' % flags
    if verbosity > 2:
        xargsFlags = '--verbose'
    else:
        xargsFlags = ''

    exitCode = 0
    for path in paths:
        path = os.path.relpath(path)
        if os.path.isdir(path):
            findCmd = 'find %s -name "*.py"' % path
            rawPathsText = os.popen(findCmd).read()
            pathsText = lintignore(rawPathsText)
            if verbosity > 1:
                print >> sys.stderr, 'findCmd:', findCmd
                print >> sys.stderr, 'rawPathsText:\n' + rawPathsText
                print >> sys.stderr, '\npathsText:\n' + pathsText
            ret = pipeToCommand('xargs %s --no-run-if-empty -n20 -d"\n" %s' % (xargsFlags, cmd),
                                pathsText, verbosity)
            if ret != 0:
                exitCode = 1
        else:
            ret = dosys('%s %s' % (cmd, path), verbosity)
            if ret != 0:
                exitCode = 1

    return exitCode
Ejemplo n.º 3
0
def runpep8(paths, verbosity=1):
    if verbosity > 0:
        print >> sys.stderr, '### pep8'

    if not paths:
        paths = ['.']

    # give helpful error message if pep8 is not installed
    ret = os.system('pep8 --help > /dev/null')
    if ret != 0:
        print >> sys.stderr, "\nWARNING: can't run pep8 command -- try 'pip install pep8'\n"
        sys.exit(1)

    # extract flags from <site>/management/pep8Flags.txt if it exists
    if verbosity > 1:
        print >> sys.stderr, 'checking for pep8 flags in %s' % CONFIG_FILE
    if os.path.exists(CONFIG_FILE):
        flags = readFlags(CONFIG_FILE)
    else:
        flags = DEFAULT_FLAGS

    exitCode = 0
    for d in paths:
        d = os.path.relpath(d)
        cmd = 'pep8 %s' % flags
        if verbosity > 2:
            xargsFlags = '--verbose'
        else:
            xargsFlags = ''
        if os.path.isdir(d):
            pathsText = lintignore(os.popen('find %s -name "*.py"' % d).read())
            ret = pipeToCommand(
                'xargs %s --no-run-if-empty -n50 -d"\n" %s' %
                (xargsFlags, cmd), pathsText, verbosity)
            if ret != 0:
                exitCode = 1
        else:
            ret = dosys('%s %s' % (cmd, d), verbosity)
            if ret != 0:
                exitCode = 1

    return exitCode
Ejemplo n.º 4
0
def runpep8(paths, verbosity=1):
    if verbosity > 0:
        print >> sys.stderr, '### pep8'

    if not paths:
        paths = ['.']

    # give helpful error message if pep8 is not installed
    ret = os.system('pep8 --help > /dev/null')
    if ret != 0:
        print >> sys.stderr, "\nWARNING: can't run pep8 command -- try 'pip install pep8'\n"
        sys.exit(1)

    # extract flags from <site>/management/pep8Flags.txt if it exists
    if verbosity > 1:
        print >> sys.stderr, 'checking for pep8 flags in %s' % CONFIG_FILE
    if os.path.exists(CONFIG_FILE):
        flags = readFlags(CONFIG_FILE)
    else:
        flags = DEFAULT_FLAGS

    exitCode = 0
    for d in paths:
        d = os.path.relpath(d)
        cmd = 'pep8 %s' % flags
        if verbosity > 2:
            xargsFlags = '--verbose'
        else:
            xargsFlags = ''
        if os.path.isdir(d):
            pathsText = lintignore(os.popen('find %s -name "*.py"' % d).read())
            ret = pipeToCommand('xargs %s --no-run-if-empty -n50 -d"\n" %s' % (xargsFlags, cmd),
                                pathsText, verbosity)
            if ret != 0:
                exitCode = 1
        else:
            ret = dosys('%s %s' % (cmd, d), verbosity)
            if ret != 0:
                exitCode = 1

    return exitCode
Ejemplo n.º 5
0
def rungjslint(paths, verbosity=1):
    if verbosity > 0:
        print >>sys.stderr, "### gjslint"

    if not paths:
        paths = ["."]

    # give helpful error message if gjslint is not installed
    ret = os.system("gjslint > /dev/null")
    if ret != 0:
        print >>sys.stderr, "\nWARNING: can't run gjslint command -- try 'pip install http://closure-linter.googlecode.com/files/closure_linter-latest.tar.gz'"
        sys.exit(1)

    # use rcfile if it exists
    if verbosity > 1:
        print >>sys.stderr, "checking for gjslint flags in %s" % CONFIG_FILE
    flags = DEFAULT_FLAGS
    if os.path.exists(CONFIG_FILE):
        flags += " --flagfile %s" % CONFIG_FILE

    exitCode = 0
    cmd = "gjslint %s" % flags
    for d in paths:
        if verbosity > 2:
            print >>sys.stderr, "directory:", d
        d = os.path.relpath(d)
        if os.path.isdir(d):
            pathsText = lintignore(os.popen('find %s -name "*.js"' % d).read())
            files = pathsText.splitlines()
        else:
            files = [d]
        if files:
            fileArgs = " ".join(files)
            ret = dosys("%s %s" % (cmd, fileArgs), verbosity)
            if ret != 0:
                exitCode = 1

    return exitCode
Ejemplo n.º 6
0
def rungjslint(paths, verbosity=1):
    if verbosity > 0:
        print >> sys.stderr, '### gjslint'

    if not paths:
        paths = ['.']

    # give helpful error message if gjslint is not installed
    ret = os.system('gjslint > /dev/null')
    if ret != 0:
        print >> sys.stderr, "\nWARNING: can't run gjslint command -- try 'pip install http://closure-linter.googlecode.com/files/closure_linter-latest.tar.gz'"
        sys.exit(1)

    # use rcfile if it exists
    if verbosity > 1:
        print >> sys.stderr, 'checking for gjslint flags in %s' % CONFIG_FILE
    flags = DEFAULT_FLAGS
    if os.path.exists(CONFIG_FILE):
        flags += ' --flagfile %s' % CONFIG_FILE

    exitCode = 0
    cmd = 'gjslint %s' % flags
    for d in paths:
        if verbosity > 2:
            print >> sys.stderr, 'directory:', d
        d = os.path.relpath(d)
        if os.path.isdir(d):
            pathsText = lintignore(os.popen('find %s -name "*.js"' % d).read())
            files = pathsText.splitlines()
        else:
            files = [d]
        if files:
            fileArgs = ' '.join(files)
            ret = dosys('%s %s' % (cmd, fileArgs), verbosity)
            if ret != 0:
                exitCode = 1

    return exitCode