Exemplo n.º 1
0
def server():
    '''Server side to call PyLint'''
    # Initialize wrapper
    data = []
    # Storage path
    exchange = os.getenv(nconst.AUDIT_EXCHANGE_ENTRY)
    # Get errors
    try:
        # Unload data
        package, output, target, config = ntools.exchange(exchange)
        # Get a wrapper
        wrapper = AuditWrapper(package, output, os.path.join(target, package))
        # Get the arguments
        argv = ['--include-ids=yes', # Set id
                '--files-output=yes', # Set file output
                '--reports=yes',
                '--comment=yes', ] # Do not generate report
        # Check if configuration
        if config is not None: argv.append('--rcfile=%s' % config)
        # Add the package
        argv.append(package)
        # Store errors
        data = wrapper.data
        # Start PyLint
        pylint.lint.Run(argv, wrapper)
    # Get exit code
    except SystemExit, e:
        # Check if allowed (32 is parsing error in PyLint)
        if e.code != 32: ntools.exchange(exchange, data=(data, None))
        # Not allowed
        else: ntools.exchange(exchange, data=(data, traceback.format_exc()))
Exemplo n.º 2
0
def server():
    '''Server side to call PyLint'''
    # Initialize wrapper
    data = []
    # Storage path
    exchange = os.getenv(nconst.AUDIT_EXCHANGE_ENTRY)
    # Get errors
    try:
        # Unload data
        package, output, target, config = ntools.exchange(exchange)
        # Get a wrapper
        wrapper = AuditWrapper(package, output, os.path.join(target, package))
        # Get the arguments
        argv = [
            '--include-ids=yes',  # Set id
            '--files-output=yes',  # Set file output
            '--reports=yes',
            '--comment=yes',
        ]  # Do not generate report
        # Check if configuration
        if config is not None: argv.append('--rcfile=%s' % config)
        # Add the package
        argv.append(package)
        # Store errors
        data = wrapper.data
        # Start PyLint
        pylint.lint.Run(argv, wrapper)
    # Get exit code
    except SystemExit, e:
        # Check if allowed (32 is parsing error in PyLint)
        if e.code != 32:
            ntools.exchange(exchange, data=(data, None))
            # Not allowed
        else:
            ntools.exchange(exchange, data=(data, traceback.format_exc()))
Exemplo n.º 3
0
def client(source, packages, output, target, config=None):
    '''Client side to call PyLint'''
    # Get the exchange path
    exchange = os.path.join(target, nconst.AUDIT_EXCHANGE_FILE)
    # Get the context
    context = ntools.expand(os.environ.copy())
    # Add exchange configuration
    context[nconst.AUDIT_EXCHANGE_ENTRY] = exchange
    # Store the test entries
    listing = {}
    # Go threw the packages
    for package in packages:
        # Get the data
        entries = (package, output, target, config)
        # Save data
        ntools.exchange(exchange, entries)
        # Get line
        line = [
            sys.executable, '-c',
            'import %s ; %s.server()' % (__name__, __name__)
        ]
        # Call subprocess
        p = subprocess.Popen(line,
                             cwd=source,
                             env=context,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT)
        # Get the output
        display = p.stdout.read()
        # Wait till the end
        p.wait()
        # Check return code
        if p.returncode != 0:
            # Log the output
            logger.error(display)
            # Raise
            raise nexcepts.AuditError(
                'failed to call PyLint in a distinct process: %s returned' %
                p.returncode)
        # Get the wrapper
        data, error = ntools.exchange(exchange)
        # Check if errors
        if error is not None:
            # Log the error
            logger.error(error)
            # Step out
            raise nexcepts.AuditError('failed to audit %s' % package)
        # Add to errors
        listing[package] = data
    # Return results
    return listing
Exemplo n.º 4
0
def client(source, packages, output, target, config=None):
    '''Client side to call PyLint'''
    # Get the exchange path
    exchange = os.path.join(target, nconst.AUDIT_EXCHANGE_FILE)
    # Get the context
    context = ntools.expand(os.environ.copy())
    # Add exchange configuration
    context[nconst.AUDIT_EXCHANGE_ENTRY] = exchange
    # Store the test entries
    listing = {}
    # Go threw the packages
    for package in packages:
        # Get the data
        entries = (package, output, target, config)
        # Save data
        ntools.exchange(exchange, entries)
        # Get line
        line = [sys.executable, '-c', 'import %s ; %s.server()' % (__name__, __name__) ]
        # Call subprocess
        p = subprocess.Popen(line, cwd=source, env=context, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        # Get the output
        display = p.stdout.read()
        # Wait till the end
        p.wait()
        # Check return code
        if p.returncode != 0:
            # Log the output
            logger.error(display)
            # Raise
            raise nexcepts.AuditError('failed to call PyLint in a distinct process: %s returned' % p.returncode)
        # Get the wrapper
        data, error = ntools.exchange(exchange)
        # Check if errors
        if error is not None:
            # Log the error
            logger.error(error)
            # Step out
            raise nexcepts.AuditError('failed to audit %s' % package)
        # Add to errors
        listing[package] = data
    # Return results
    return listing
Exemplo n.º 5
0
        # Check if configuration
        if config is not None: argv.append('--rcfile=%s' % config)
        # Add the package
        argv.append(package)
        # Store errors
        data = wrapper.data
        # Start PyLint
        pylint.lint.Run(argv, wrapper)
    # Get exit code
    except SystemExit, e:
        # Check if allowed (32 is parsing error in PyLint)
        if e.code != 32: ntools.exchange(exchange, data=(data, None))
        # Not allowed
        else: ntools.exchange(exchange, data=(data, traceback.format_exc()))
    # Get error
    except: ntools.exchange(exchange, data=(data, traceback.format_exc()))
    # No error
    else: ntools.exchange(exchange, data=(data, None))

def report(target, sources):
    '''Create report'''
    # Extract the Java Script and the CSS
    ntools.extract_pic_js_css(target)
    # Get the date
    date = datetime.datetime.now()
    # Process the index
    ntools.kiding(__name__, 'index.html', target)
    # Process the listing
    ntools.kiding(__name__, 'listing.html', target, sources=sources, date=date)
    # Process the abstract
    ntools.kiding(__name__, 'abstract.html', target, sources=sources, date=date)
Exemplo n.º 6
0
        argv.append(package)
        # Store errors
        data = wrapper.data
        # Start PyLint
        pylint.lint.Run(argv, wrapper)
    # Get exit code
    except SystemExit, e:
        # Check if allowed (32 is parsing error in PyLint)
        if e.code != 32:
            ntools.exchange(exchange, data=(data, None))
            # Not allowed
        else:
            ntools.exchange(exchange, data=(data, traceback.format_exc()))
    # Get error
    except:
        ntools.exchange(exchange, data=(data, traceback.format_exc()))
        # No error
    else:
        ntools.exchange(exchange, data=(data, None))


def report(target, sources):
    '''Create report'''
    # Extract the Java Script and the CSS
    ntools.extract_pic_js_css(target)
    # Get the date
    date = datetime.datetime.now()
    # Process the index
    ntools.kiding(__name__, 'index.html', target)
    # Process the listing
    ntools.kiding(__name__, 'listing.html', target, sources=sources, date=date)