<commit_before>"""List files in a given item.

usage:
    ia list [-v] [--glob=<pattern>|--location] [--columns <column1,column2> | --all] <identifier>
    ia metadata --help

options:
    -h, --help
    -v, --verbose               Print column headers. [default: False]
    -a, --all                   List all information available for files.
    -l, --location              Print full URL for each file.
    -c, --columns=<name,size>   List specified file information. [default: name]
    -g, --glob=<pattern>        Only return patterns match the given pattern.

"""
import sys
import csv
from itertools import chain
from fnmatch import fnmatch
import six

from docopt import docopt

from internetarchive import get_item


# main()
#_________________________________________________________________________________________
def main(argv):
    args = docopt(__doc__, argv=argv)
    item = get_item(args['<identifier>'])

    files = item.files
    if args.get('--all'):
        columns = list(set(chain.from_iterable(k for k in files)))
    else:
        columns = args['--columns'].split(',')
        if not isinstance(columns, list):
            columns = [columns]

    dict_writer = csv.DictWriter(sys.stdout, columns, delimiter='\t')

    if args.get('--glob'):
        patterns = args['--glob'].split('|')
        if not isinstance(patterns, list):
            patterns = [patterns]
        files = [f for f in files if any(fnmatch(f['name'], p) for p in patterns)]

    output = []
    for f in files:
        file_dict = {}
        for key, val in f.items():<commit_msg>Added support for returning files matching a given source using --source=<source><commit_after>"""List files in a given item.

usage:
    ia list [-v] [--glob=<pattern>] [--location] [--source=<source>] 
            [--columns <column1,column2> | --all] <identifier>
    ia metadata --help

options:
    -h, --help
    -v, --verbose               Print column headers. [default: False]
    -a, --all                   List all information available for files.
    -l, --location              Print full URL for each file.
    -c, --columns=<name,size>   List specified file information. [default: name]
    -g, --glob=<pattern>        Only return patterns match the given pattern.
    -s, --source=<source>       Return files matching source.

"""
import sys
import csv
from itertools import chain
from fnmatch import fnmatch
import six

from docopt import docopt

from internetarchive import get_item


# main()
#_________________________________________________________________________________________
def main(argv):
    args = docopt(__doc__, argv=argv)
    item = get_item(args['<identifier>'])

    files = item.files
    if args.get('--all'):
        columns = list(set(chain.from_iterable(k for k in files)))
    else:
        columns = args['--columns'].split(',')
        if not isinstance(columns, list):
            columns = [columns]

    dict_writer = csv.DictWriter(sys.stdout, columns, delimiter='\t')

    if args.get('--glob'):
        patterns = args['--glob'].split('|')
        if not isinstance(patterns, list):
            patterns = [patterns]
        files = [f for f in files if any(fnmatch(f['name'], p) for p in patterns)]
    elif args.get('--source'):
        files = [f.__dict__ for f in item.get_files(source=args['--source'])]

    output = []
    for f in files:
        file_dict = {}
        for key, val in f.items():
{'fraction_non_alphanumeric': 0.13125727590221187, 'fraction_numerical': 0.0011641443538998836, 'mean_word_length': 2.5951882845188283, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4916519', 'n_tokens_mistral': 976, 'n_tokens_neox': 962, 'n_words': 321}