List all items in the database in a predefined format.

def ls():
    """List all items in the database in a predefined format."""
    if not os.path.exists(ARGS.database):
        exit('Error: The database does not exist; you must create it first.')
    with sqlite3.connect(ARGS.database) as connection:
        connection.text_factory = str
        cursor = connection.cursor()
        if ARGS.pattern:
            if not ARGS.strict:
                ARGS.pattern = '%{0}%'.format(ARGS.pattern)
            cursor.execute('SELECT * FROM Movies WHERE Name LIKE (?)',
                           [ARGS.pattern])
        else:
            cursor.execute('SELECT * FROM Movies')
        movies = sorted([row for row in cursor])
    if ARGS.name:
        print '\n'.join([movie[0] for movie in movies])
    elif ARGS.location:
        print '\n'.join([movie[1] for movie in movies])
    elif ARGS.size:
        print '\n'.join([prefix_size(int(movie[2])) for movie in movies])
    elif ARGS.files:
        for movie in movies:
            print ', '.join(movie[3].split('##'))
    else:
        for i, movie in enumerate(movies):
            print 'Name:\t\t{0}'.format(movie[0])
            print 'Location:\t{0}'.format(movie[1])
            print 'Size:\t\t{0}'.format(prefix_size(int(movie[2])))
            print 'Files:\t\t{0}'.format(', '.join(movie[3].split('##')))
            if not i == len(movies) - 1:
                print