<commit_before># -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
import logging
import docopt
import pprint

import psd_tools.reader
import psd_tools.decoder

from psd_tools.decoder.layers import layer_to_PIL, image_to_PIL

logger = logging.getLogger('psd_tools')
logger.addHandler(logging.StreamHandler())

def main():
    """
    psd-tools.py

    Usage:
        psd-tools.py <filename> [--encoding <encoding>] [--verbose]
        psd-tools.py -h | --help
        psd-tools.py --version

    Options:
        -v --verbose                Be more verbose.
        --encoding <encoding>       Text encoding [default: ascii].

    """
    args = docopt.docopt(main.__doc__)

    if args['--verbose']:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)

    with open(args['<filename>'], 'rb') as f:
        res = psd_tools.reader.parse(f, args['--encoding'])
        decoded = psd_tools.decoder.decode(res)
        for it in decoded:
            pprint.pprint(it)

#        im = layer_to_PIL(decoded, 1)<commit_msg>simple 'convert' cli command<commit_after># -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
import logging
import docopt
import pprint

import psd_tools.reader
import psd_tools.decoder

from psd_tools.decoder.layers import layer_to_PIL, image_to_PIL

logger = logging.getLogger('psd_tools')
logger.addHandler(logging.StreamHandler())

def main():
    """
    psd-tools.py

    Usage:
        psd-tools.py <filename> [--encoding <encoding>] [--verbose]
        psd-tools.py convert <psd_filename> <out_filename> [--verbose]
        psd-tools.py -h | --help
        psd-tools.py --version

    Options:
        -v --verbose                Be more verbose.
        --encoding <encoding>       Text encoding [default: ascii].

    """
    args = docopt.docopt(main.__doc__)

    if args['--verbose']:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)

    if args['convert']:
        with open(args['<psd_filename>'], 'rb') as f:
            res = psd_tools.reader.parse(f)
            decoded = psd_tools.decoder.decode(res)
            im = image_to_PIL(decoded)
            im.save(args['<out_filename>'])

    else:
        with open(args['<filename>'], 'rb') as f:
            res = psd_tools.reader.parse(f, args['--encoding'])
            decoded = psd_tools.decoder.decode(res)
            for it in decoded:
                pprint.pprint(it)

#        im = layer_to_PIL(decoded, 1)
{'fraction_non_alphanumeric': 0.12943962115232832, 'fraction_numerical': 0.0015785319652722968, 'mean_word_length': 2.4396200814111264, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '6110158', 'n_tokens_mistral': 845, 'n_tokens_neox': 810, 'n_words': 176}