(args)
return 0
Run the stats tool.

    Args:
      args: The argparser parsed args object.

    Returns:
      0 on success, 1 on failure.
Run the stats tool.
Run the stats tool .
def stats(args):
    """Run the stats tool.

    Args:
      args: The argparser parsed args object.

    Returns:
      0 on success, 1 on failure.
    """
    csv_writer = None
    if args.csv:
        csv_writer = csv.writer(sys.stdout)
        csv_writer.writerow([
            'Filename',
            'Title',
            'Byline',
            'Code Version',
            'Char Count',
            'Token Count',
            'Line Count',
            'Compressed Code Size'
        ])

    for fname, g in _games_for_filenames(args.filename):
        if g is None:
            util.error('{}: could not load cart\n'.format(fname))
            if len(args.filename) == 1:
                return 1
            continue

        if args.csv:
            csv_writer.writerow([
                os.path.basename(fname),
                _as_friendly_string(g.lua.get_title()),
                _as_friendly_string(g.lua.get_byline()),
                g.lua.version,
                g.lua.get_char_count(),
                g.lua.get_token_count(),
                g.lua.get_line_count(),
                g.get_compressed_size()
            ])
        else:
            title = _as_friendly_string(g.lua.get_title())
            byline = _as_friendly_string(g.lua.get_byline())

            if title is not None:
                util.write('{} ({})\n'.format(
                    title, os.path.basename(g.filename)))
            else:
                util.write(os.path.basename(g.filename) + '\n')
            if byline is not None:
                util.write(byline + '\n')
            util.write('- version: {}\n- lines: {}\n- chars: {}\n'
                       '- tokens: {}\n- compressed chars: {}\n'.format(
                           g.lua.version, g.lua.get_line_count(),
                           g.lua.get_char_count(), g.lua.get_token_count(),
                           g.get_compressed_size()))
            util.write('\n')

    return 0
def stats ( args ) : csv_writer = None if args . csv : csv_writer = csv . writer ( sys . stdout ) csv_writer . writerow ( [ 'Filename' , 'Title' , 'Byline' , 'Code Version' , 'Char Count' , 'Token Count' , 'Line Count' , 'Compressed Code Size' ] ) for fname , g in _games_for_filenames ( args . filename ) : if g is None : util . error ( '{}: could not load cart\n' . format ( fname ) ) if len ( args . filename ) == 1 : return 1 continue if args . csv : csv_writer . writerow ( [ os . path . basename ( fname ) , _as_friendly_string ( g . lua . get_title ( ) ) , _as_friendly_string ( g . lua . get_byline ( ) ) , g . lua . version , g . lua . get_char_count ( ) , g . lua . get_token_count ( ) , g . lua . get_line_count ( ) , g . get_compressed_size ( ) ] ) else : title = _as_friendly_string ( g . lua . get_title ( ) ) byline = _as_friendly_string ( g . lua . get_byline ( ) ) if title is not None : util . write ( '{} ({})\n' . format ( title , os . path . basename ( g . filename ) ) ) else : util . write ( os . path . basename ( g . filename ) + '\n' ) if byline is not None : util . write ( byline + '\n' ) util . write ( '- version: {}\n- lines: {}\n- chars: {}\n' '- tokens: {}\n- compressed chars: {}\n' . format ( g . lua . version , g . lua . get_line_count ( ) , g . lua . get_char_count ( ) , g . lua . get_token_count ( ) , g . get_compressed_size ( ) ) ) util . write ( '\n' ) return 0